浏览代码

add weekly review summary on location page

Mohidul Islam 3 年之前
父节点
当前提交
3a9ac3df7b
共有 3 个文件被更改,包括 61 次插入9 次删除
  1. 31 0
      gauth/models.py
  2. 18 8
      manager/templates/locations.html
  3. 12 1
      static/user-dashboard.css

+ 31 - 0
gauth/models.py

@@ -1,4 +1,5 @@
 from django.db import models
+from django.utils import timezone
 from django.contrib.auth.models import User
 
 
@@ -36,6 +37,36 @@ class Location(models.Model):
     def all_google_review(self):
         return self.review_set.all()
 
+    @property
+    def last_week_pos_google_review_count(self):
+        end_date = timezone.now() - timezone.timedelta(days=7)
+        return self.review_set.filter(create_time__gte=end_date, star_rating__gte=4).count()
+
+    @property
+    def last_week_pos_facebook_review_count(self):
+        end_date = timezone.now() - timezone.timedelta(days=7)
+        return self.facebookpage.facebookreview_set.filter(create_time__gte=end_date, recommendation_type=True).count()
+
+    @property
+    def last_week_pos_yelp_review_count(self):
+        end_date = timezone.now() - timezone.timedelta(days=7)
+        return self.yelplocation.yelpreview_set.filter(date_posted__gte=end_date, rating__gte=4).count()
+
+    @property
+    def last_week_neg_google_review_count(self):
+        end_date = timezone.now() - timezone.timedelta(days=7)
+        return self.review_set.filter(create_time__gte=end_date, star_rating__lte=3).count()
+
+    @property
+    def last_week_neg_facebook_review_count(self):
+        end_date = timezone.now() - timezone.timedelta(days=7)
+        return self.facebookpage.facebookreview_set.filter(create_time__gte=end_date, recommendation_type=False).count()
+
+    @property
+    def last_week_neg_yelp_review_count(self):
+        end_date = timezone.now() - timezone.timedelta(days=7)
+        return self.yelplocation.yelpreview_set.filter(date_posted__gte=end_date, rating__lte=3).count()
+
 
 class LocationManager(models.Model):
     name = models.CharField(max_length=255)

+ 18 - 8
manager/templates/locations.html

@@ -71,7 +71,7 @@
     <div class="container">
       <div class="row">
       {% for loc in all_locations %}
-          <div class="col-sm-6">
+          <div class="col-sm-4">
             <a href="{% url 'location-analytics-man' loc.location_id %}">
             <div class="card mt-2 mb-2 graph-card-shadow">
               <div class="card-header">
@@ -82,13 +82,23 @@
                 </span>
               </div>
               <div class="card-body">
-    <!--            <span>Google Review URL: <a href="{{ loc.website_url }}">{{ loc.website_url }}</a></span><br>-->
-    <!--            <span>Facebook Page URL: <a href="https://web.facebook.com/{{ loc.facebookpage.id }}">"https://web.facebook.com/{{ loc.facebookpage.id }}</a></span>-->
-                <span>
-                  Total Review:
-                  <span > <i class="fa fa-google" aria-hidden="true" style="color: #ff7700; margin-left: 1rem;"></i> {{ loc.all_google_review.count }}</span>
-                  <span > <i class="fa fa-facebook" aria-hidden="true" style="color: blue; margin-left: 2rem;"></i> {{ loc.all_facebook_review.count }} </span>
-                </span>
+                <table class="table">
+                  <tr>
+                    <td><i class="fa fa-google" aria-hidden="true" style="color: #ff7700; margin-left: 1rem;">oogle</i></td>
+                    <td style="color: #212F3D;"><i class="fa fa-thumbs-o-up" style="color: green;" aria-hidden="true"></i> {{ loc.last_week_pos_google_review_count }}</td>
+                    <td style="color: #212F3D;"><i class="fa fa-thumbs-o-down" style="color: red;" aria-hidden="true"></i> {{ loc.last_week_neg_google_review_count }}</td>
+                  </tr>
+                  <tr>
+                    <td><i class="fa fa-facebook" aria-hidden="true" style="color: blue; margin-left: 2rem;">acebook</i></td>
+                    <td style="color: #212F3D;"><i class="fa fa-thumbs-o-up" style="color: green;" aria-hidden="true"></i> {{ loc.last_week_pos_facebook_review_count }}</td>
+                    <td style="color: #212F3D;"><i class="fa fa-thumbs-o-down" style="color: red;" aria-hidden="true"></i> {{ loc.last_week_neg_facebook_review_count }}</td>
+                  </tr>
+                  <tr>
+                    <td><i class="fa fa-yelp" aria-hidden="true" style="color: red; margin-left: 2rem;"> Yelp</i></td>
+                    <td style="color: #212F3D;"><i class="fa fa-thumbs-o-up" style="color: green;" aria-hidden="true"></i> {{ loc.last_week_pos_yelp_review_count }}</td>
+                    <td style="color: #212F3D;"><i class="fa fa-thumbs-o-down" style="color: red;" aria-hidden="true"></i> {{ loc.last_week_neg_yelp_review_count }}</td>
+                  </tr>
+                </table>
               </div>
             </div>
             </a>

+ 12 - 1
static/user-dashboard.css

@@ -33,6 +33,7 @@ body {
   color: #333;
 }
 
+
 .sidebar .nav-link .feather {
   margin-right: 4px;
   color: #999;
@@ -188,4 +189,14 @@ body {
     width: 20px;
     color: black;
     font-size: small;
-}
+}
+
+.card-body .table-card td, .table th {
+    padding: .5rem;
+    vertical-align: top;
+    border-top: 0px solid #dee2e6;
+    color: white;
+    font-size: larger;
+    font-family: serif;
+    font-weight: bold;
+}