allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [allura] 04/04: More polishing
Date Mon, 06 Jan 2020 23:05:12 GMT
This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 7f41e1514f224cad7394de389b08f1fa8d5e6898
Author: Dave Brondsema <dave@brondsema.net>
AuthorDate: Mon Jan 6 17:06:29 2020 -0500

    More polishing
---
 Allura/allura/templates/jinja_master/nav_menu.html | 14 +++++++++----
 ForgeFeedback/forgefeedback/__init__.py            | 16 +++++++++++++++
 ForgeFeedback/forgefeedback/feedback_main.py       | 24 +++++++++++-----------
 ForgeFeedback/forgefeedback/model/feedback.py      |  4 ++++
 ForgeFeedback/forgefeedback/templates/__init__.py  | 16 +++++++++++++++
 5 files changed, 58 insertions(+), 16 deletions(-)

diff --git a/Allura/allura/templates/jinja_master/nav_menu.html b/Allura/allura/templates/jinja_master/nav_menu.html
index 9509334..3904896 100644
--- a/Allura/allura/templates/jinja_master/nav_menu.html
+++ b/Allura/allura/templates/jinja_master/nav_menu.html
@@ -64,6 +64,7 @@
     {% endif %}
 {% endif %}
 
+{% if c.project.rating %}{# hide if ratings haven't been used (project/site may not use ForgeFeedback)
#}
 <script>
  document.getElementById("stars").innerHTML = getStars("{{c.project.rating}}");
 
@@ -74,17 +75,22 @@ function getStars(ratings) {
   let output = [];
 
   // Append all the filled whole stars
-  for (var i = ratings; i >= 1; i--)
+  var i;
+  for (i = ratings; i >= 1; i--) {
     output.push('<i class="fa fa-star" aria-hidden="true" style="color: orange;"></i>&nbsp;');
+  }
 
   // If there is a half a star, append it
-  if (i == .5) output.push('<i class="fa fa-star-half-o" aria-hidden="true" style="color:
orange;"></i>&nbsp;');
+  if (i === .5) {
+    output.push('<i class="fa fa-star-half-o" aria-hidden="true" style="color: orange;"></i>&nbsp;');
+  }
 
   // Fill the empty stars
-  for (let i = (5 - ratings); i >= 1; i--)
+  for (let i = (5 - ratings); i >= 1; i--) {
     output.push('<i class="fa fa-star-o" aria-hidden="true" style="color: orange;"></i>&nbsp;');
-
+  }
   return output.join('');
 
  }
  </script>
+{% endif %}
\ No newline at end of file
diff --git a/ForgeFeedback/forgefeedback/__init__.py b/ForgeFeedback/forgefeedback/__init__.py
index e69de29..144e298 100755
--- a/ForgeFeedback/forgefeedback/__init__.py
+++ b/ForgeFeedback/forgefeedback/__init__.py
@@ -0,0 +1,16 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
diff --git a/ForgeFeedback/forgefeedback/feedback_main.py b/ForgeFeedback/forgefeedback/feedback_main.py
index 4f04b61..889c0f1 100755
--- a/ForgeFeedback/forgefeedback/feedback_main.py
+++ b/ForgeFeedback/forgefeedback/feedback_main.py
@@ -20,7 +20,7 @@ import pymongo
 
 # Non-stdlib imports
 
-from tg import expose, flash, url, config, request
+from tg import expose, flash, url, config, request, redirect
 from tg.decorators import with_trailing_slash, without_trailing_slash
 from tg import tmpl_context as c, app_globals as g
 from ming.odm import session
@@ -121,7 +121,7 @@ class RootController(BaseController, FeedController):
         rating_by_user = Feedback.query.find({
             'reported_by_id': c.user._id, 'project_id': c.project._id}
         ).count()
-        if (rating_by_user > 0):
+        if rating_by_user > 0:
             user_has_already_reviewed = True
         return dict(review_list=self.get_review_list(),
                     user_has_already_reviewed=user_has_already_reviewed,
@@ -150,8 +150,8 @@ class RootController(BaseController, FeedController):
         M.main_orm_session.flush()
         g.director.create_activity(c.user, 'posted', p, related_nodes=[
                                    c.project], tags=['description'])
-        return dict(review_list=self.get_review_list(),
-                    rating=self.getRating())
+        self.getRating()  # force recalculation
+        redirect(c.app.url)
 
     # called on click of the Feedback link
     @with_trailing_slash
@@ -183,8 +183,8 @@ class RootController(BaseController, FeedController):
         g.director.create_activity(
             c.user, 'modified', self.rating,
             related_nodes=[c.project], tags=['description'])
-        return dict(
-            review_list=self.get_review_list(), rating=self.getRating())
+        self.getRating()  # force recalculation
+        redirect(c.app.url)
 
     # called when user clicks on delete link in feedback page
     @without_trailing_slash
@@ -198,7 +198,7 @@ class RootController(BaseController, FeedController):
             Feedback.query.remove(dict(
                 {'reported_by_id': c.user._id, 'project_id': c.project._id}))
             M.main_orm_session.flush()
-            self.getRating()
+            self.getRating()  # force recalculation
             flash('Feedback successfully deleted')
             return 'Success'
         else:
@@ -231,7 +231,7 @@ class RootController(BaseController, FeedController):
         sum_of_ratings = float(
             fivestarcount + fourstarcount + threestarcount + twostarcount +
             onestarcount)
-        if (sum_of_ratings != 0):
+        if sum_of_ratings != 0:
             average_user_ratings = float(
                 (5*fivestarcount) + (4*fourstarcount) +
                 (3*threestarcount) + (2*twostarcount) +
@@ -239,12 +239,12 @@ class RootController(BaseController, FeedController):
             float_rating = float(average_user_ratings)
             int_rating = int(float_rating)
             float_point_value = float_rating - int_rating
-            if(float_point_value < 0.25):
+            if float_point_value < 0.25:
                 c.project.rating = int_rating
-            elif(float_point_value >= 0.25 < 0.75):
+            elif float_point_value >= 0.25 < 0.75:
                 c.project.rating = 0.5 + int_rating
-            elif(float_point_value >= 0.75):
+            elif float_point_value >= 0.75:
                 c.project.rating = float(int_rating)+1
             return average_user_ratings
-        if (sum_of_ratings == 0):
+        if sum_of_ratings == 0:
             c.project.rating = 0.0
diff --git a/ForgeFeedback/forgefeedback/model/feedback.py b/ForgeFeedback/forgefeedback/model/feedback.py
index 7cb61e5..9498f70 100755
--- a/ForgeFeedback/forgefeedback/model/feedback.py
+++ b/ForgeFeedback/forgefeedback/model/feedback.py
@@ -41,6 +41,9 @@ class Feedback(VersionedArtifact, ActivityObject):
 
     class __mongometa__:
         name = 'feedback'
+        indexes = [
+            ('project_id', 'reported_by_id'),
+        ]
 
     type_s = 'Feedback'
     _id = FieldProperty(schema.ObjectId)
@@ -55,6 +58,7 @@ class Feedback(VersionedArtifact, ActivityObject):
         result = VersionedArtifact.index(self)
         result.update(
             created_date_dt=self.created_date,
+            reported_by_username_t=self.reported_by.username,
             text=self.description,
         )
         return result
diff --git a/ForgeFeedback/forgefeedback/templates/__init__.py b/ForgeFeedback/forgefeedback/templates/__init__.py
index e69de29..144e298 100755
--- a/ForgeFeedback/forgefeedback/templates/__init__.py
+++ b/ForgeFeedback/forgefeedback/templates/__init__.py
@@ -0,0 +1,16 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.


Mime
View raw message