소스 검색

Added background job

Mohidul Islam 5 년 전
부모
커밋
905e30db57
4개의 변경된 파일43개의 추가작업 그리고 10개의 파일을 삭제
  1. 7 0
      dashboard/static/main.css
  2. 4 4
      dashboard/templates/_reportsidebar.html
  3. 8 6
      dashboard/templates/base.html
  4. 24 0
      review/background_job.py

+ 7 - 0
dashboard/static/main.css

@@ -86,4 +86,11 @@ a.article-title:hover {
 .article-link {
     text-decoration: none;
     color: #2e333a;
+}
+
+.scrollable-section {
+   position: fixed;
+   max-height: 90%;
+   overflow: auto;
+   width: 18%;
 }

+ 4 - 4
dashboard/templates/_reportsidebar.html

@@ -1,5 +1,5 @@
 <div class="content-section" style="padding: 0px">
-<div class="card" >
+<div class="card">
   <div class="card-body">
     <h5 class="card-title">Intent Ranking</h5>
     <hr>
@@ -16,18 +16,18 @@
   <div class="card-body">
     <h5 class="card-title">Replies</h5>
     <hr>
-      {% for key, data in replies.items %}
+        {% for key, data in replies.items %}
         <div class="card">
           <h5 class="card-header">{{key}}</h5>
           <div class="card-body" style="padding: 1px">
             <ul class="list-group list-group-item-action">
                 {% for reply in data %}
-                  <li class="list-group-item" style="font-size: 14px"><p>{{ reply.reply }}</p></li>
+                  <li class="list-group-item" style="font-size: 14px" ><p>{{ reply.reply }}</p></li>
                 {% endfor %}
             </ul>
-          </div>
         </div>
       {% endfor %}
+      </div>
   </div>
 </div>
 </div>

+ 8 - 6
dashboard/templates/base.html

@@ -47,12 +47,14 @@
           {% block content %}{% endblock %}
         </div>
         <div class="col-md-4">
-        {% if intents %}
-          {% include '_reportsidebar.html' %}
-        {% endif %}
-        {% if locations %}
-            {% include '_locationsidebar.html' %}
-        {% endif %}
+            <div class="scrollable-section">
+                {% if intents %}
+                  {% include '_reportsidebar.html' %}
+                {% endif %}
+                {% if locations %}
+                    {% include '_locationsidebar.html' %}
+                {% endif %}
+            </div>
         </div>
       </div>
     </main>

+ 24 - 0
review/background_job.py

@@ -0,0 +1,24 @@
+from threading import Thread
+from time import sleep
+from django.utils import timezone
+
+from .models import Review, CustomReply
+from .review_utils import populate_reviews
+
+
+def un_replied_reviews_with_no_comment():
+    now = timezone.now()
+    date = now - timezone.timedelta(days=30)
+    reviews = Review.objects.filter(comment=None, reply=None, star_rating=2, update_time__gte=date).order_by('update_time')
+    return reviews
+
+
+def task():
+    while True:
+        populate_reviews()
+        # TODO: reply reviews in background
+        sleep(60*60*6)
+
+
+thread = Thread(target=task)
+# thread.start()