Merge lp:~widelands-dev/widelands-website/replace_djangoratings into lp:widelands-website

Proposed by kaputtnik
Status: Merged
Merged at revision: 508
Proposed branch: lp:~widelands-dev/widelands-website/replace_djangoratings
Merge into: lp:widelands-website
Diff against target: 195 lines (+62/-3)
10 files modified
media/css/base.css (+4/-0)
pip_requirements.txt (+1/-0)
settings.py (+9/-0)
templates/star_rating/average.html (+7/-0)
templates/star_rating/rate.html (+27/-0)
templates/wlmaps/base.html (+3/-0)
templates/wlmaps/index.html (+5/-1)
templates/wlmaps/map_detail.html (+4/-1)
urls.py (+1/-0)
wlmaps/templatetags/wlmaps_extra.py (+1/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands-website/replace_djangoratings
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+358958@code.launchpad.net

Commit message

Exchange old app djangoratings with django-star-ratings

Description of the change

Another cleanup for the update of python. Exchange the old unmaintained app djangoratings with an up-to-date app.

I decided to get this in in two steps:

1. This branch adds the new app. The conversion of old votes to new votes can be done in the django shell (see below). In this branch the old values remains visible, so we can check if the conversion is done correctly.

2. In a another branch we clean up the code to remove the old app djangorating.

After merging this branch it is important to delete a remaining .pyc file:

djangoratings/templatetags/ratings.pyc

We can import the old ratings as follows in the django shell:

from djangoratings.models import Score, Vote
from star_ratings.models import Rating, UserRating

for obj in Score.objects.all():
   vote_obj = Rating.objects.create(object_id=obj.object_id, content_type=obj.content_type)
   for v in Vote.objects.filter(object_id=obj.object_id, content_type=obj.content_type):
      vote = UserRating.objects.create(user=v.user, ip=v.ip_address, score=v.score, rating=vote_obj)
      vote.save()
   vote_obj.calculate()

To post a comment you must log in.
507. By kaputtnik

forgotton to add custom templates

508. By kaputtnik

fixed comment

Revision history for this message
GunChleoc (gunchleoc) wrote :

LGTM :)

review: Approve
Revision history for this message
kaputtnik (franku) wrote :

Merged and deployed.

Thanks for the review, and sorry for server errors... forgot some steps after merging the branch :-S

I have checked also the first 10 pages of the maps for the voting and all looks fine.

Some old Votings had no map associated map (map got deleted, but the voting objects remain), i deleted them.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== renamed file 'djangoratings/templatetags/ratings.py' => 'djangoratings/templatetags/ratings_old.py'
2=== modified file 'media/css/base.css'
3--- media/css/base.css 2018-10-15 07:13:24 +0000
4+++ media/css/base.css 2018-11-18 21:30:49 +0000
5@@ -108,6 +108,10 @@
6 font-weight: bold;
7 }
8
9+.star-ratings input, button {
10+ padding: inherit;
11+}
12+
13 textarea {
14 font-weight: normal;
15 font-size: 0.9em;
16
17=== modified file 'pip_requirements.txt'
18--- pip_requirements.txt 2018-11-05 17:12:12 +0000
19+++ pip_requirements.txt 2018-11-18 21:30:49 +0000
20@@ -7,6 +7,7 @@
21 # Do not install newer versions because our notifications app is affected
22 -e git://github.com/arneb/django-messages.git@2d8dabb755e0b5ace876bde25f45d07c2051ac37#egg=django_messages
23 django-nocaptcha-recaptcha==0.0.19
24+django-star-ratings==0.7.0
25 dj-pagination==2.3.2
26 django-registration==2.4.1
27 django-tagging==0.4.5
28
29=== modified file 'settings.py'
30--- settings.py 2018-11-12 19:36:22 +0000
31+++ settings.py 2018-11-18 21:30:49 +0000
32@@ -110,6 +110,7 @@
33 'django_messages_wl.apps.WLDjangoMessagesConfig',
34 'dj_pagination',
35 'tagging',
36+ 'star_ratings',
37 'djangoratings', # included as wlapp
38 ]
39
40@@ -333,6 +334,14 @@
41 # See: https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-age
42 CSRF_COOKIE_AGE = None
43
44+#############################
45+# star_rating configuration #
46+#############################
47+
48+STAR_RATINGS_STAR_HEIGHT = 14
49+STAR_RATINGS_STAR_WIDTH = 14
50+STAR_RATINGS_RANGE = 10
51+
52 try:
53 from local_settings import *
54 except ImportError:
55
56=== added directory 'templates/star_rating'
57=== added file 'templates/star_rating/average.html'
58--- templates/star_rating/average.html 1970-01-01 00:00:00 +0000
59+++ templates/star_rating/average.html 2018-11-18 21:30:49 +0000
60@@ -0,0 +1,7 @@
61+{% extends "star_ratings/widget_base.html" %}
62+{% block rating_stars %}
63+ {# No stars here #}
64+{% endblock %}
65+{% block rating_detail %}
66+{{ rating.average|floatformat:"-2" }} ({{ rating.count }} Vote{{ rating.count|pluralize }})
67+{% endblock %}
68\ No newline at end of file
69
70=== added file 'templates/star_rating/rate.html'
71--- templates/star_rating/rate.html 1970-01-01 00:00:00 +0000
72+++ templates/star_rating/rate.html 2018-11-18 21:30:49 +0000
73@@ -0,0 +1,27 @@
74+{% extends "star_ratings/widget_base.html" %}
75+{% load i18n %}
76+
77+{% block rating_detail %}
78+{% if not user.is_authenticated and not anonymous_ratings and not read_only %}
79+ <p>
80+ {{ rating.average|floatformat:"-2" }} ({{ rating.count }} Vote{{ rating.count|pluralize }})
81+ <a href="{% url 'auth_login' %}?next={{ request.path }}">{% trans 'Please log in to vote.' %}</a>
82+ </p>
83+{% else %}
84+ {% block rating_user %}
85+ <p class="star-ratings-rating-user">
86+ {{ rating.average|floatformat:"-2" }} ({{ rating.count }} Vote{{ rating.count|pluralize }}) -
87+ {% trans 'You voted: ' %}
88+ <span class='star-ratings-rating-value'>
89+ {% if user_rating %}
90+ {{ user_rating.score }}
91+ {% else %}
92+ {% trans 'Not voted' %}
93+ {% endif %}
94+ </span>
95+ </p>
96+ {% endblock rating_user %}
97+ <p class="star-ratings-errors"><p>
98+{% endif %}
99+{% endblock rating_detail %}
100+
101
102=== modified file 'templates/wlmaps/base.html'
103--- templates/wlmaps/base.html 2015-02-18 22:30:08 +0000
104+++ templates/wlmaps/base.html 2018-11-18 21:30:49 +0000
105@@ -1,4 +1,5 @@
106 {% extends "base.html" %}
107+{% load static %}
108
109 {% comment %}
110 vim:ft=htmldjango
111@@ -7,6 +8,8 @@
112 {% block extra_head %}
113 <link rel="stylesheet" type="text/css" media="all" href="{{ MEDIA_URL }}css/forum.css" />
114 <link rel="stylesheet" type="text/css" media="all" href="{{ MEDIA_URL }}css/maps.css" />
115+<link rel="stylesheet" href="{% static 'star-ratings/css/star-ratings.css' %}">
116+<script type="text/javascript" src="{% static 'star-ratings/js/dist/star-ratings.min.js' %}"></script>
117 {{block.super}}
118 {% endblock %}
119
120
121=== modified file 'templates/wlmaps/index.html'
122--- templates/wlmaps/index.html 2018-10-14 13:24:15 +0000
123+++ templates/wlmaps/index.html 2018-11-18 21:30:49 +0000
124@@ -8,6 +8,8 @@
125 {% load wlmaps_extra %}
126 {% load threadedcommentstags %}
127 {% load pagination_tags %}
128+{% load ratings %}
129+{% load ratings_old %}
130
131 {% block content_header %}
132 <h1>Maps</h1>
133@@ -55,7 +57,9 @@
134 </tr>
135 <tr>
136 <td class="grey">Rating:</td>
137- <td>{{ map.rating|average_rating }} ({{ map.rating.votes }} Votes)</td>
138+ <td>
139+ {% ratings map read_only template_name='star_rating/average.html' %}
140+ {{ map.rating|average_rating }} ({{ map.rating.votes }} Votes)</td>
141 <td class="spacer"></td>
142 {% get_comment_count for map as ccount %}
143 <td class="grey">Comments:</td><td>{{ ccount }}</td>
144
145=== modified file 'templates/wlmaps/map_detail.html'
146--- templates/wlmaps/map_detail.html 2018-10-14 13:24:15 +0000
147+++ templates/wlmaps/map_detail.html 2018-11-18 21:30:49 +0000
148@@ -8,6 +8,8 @@
149 {% load wlprofile_extras %}
150 {% load threadedcommentstags %}
151 {% load wl_markdown %}
152+{% load ratings %}
153+{% load ratings_old %}
154
155 {% block title %}{{ map.name }} - {{ block.super }}{% endblock %}
156
157@@ -29,6 +31,7 @@
158 });
159 });
160 </script>
161+
162 {% endif %}
163 {% endblock %}
164
165@@ -94,7 +97,7 @@
166 </tr>
167 <tr>
168 <td class="grey">Rating:</td>
169- <td>
170+ <td>{% ratings map template_name='star_rating/rate.html' %}
171 {{ map.rating|average_rating }} ({{ map.rating.votes }} Votes)
172 {% if not user.is_anonymous %}
173 <span id="vote"></span>
174
175=== modified file 'urls.py'
176--- urls.py 2018-10-10 17:04:53 +0000
177+++ urls.py 2018-11-18 21:30:49 +0000
178@@ -27,6 +27,7 @@
179 url(r'^accounts/', include('registration.backends.hmac.urls')),
180 url('^', include('django.contrib.auth.urls')),
181
182+ url(r'^ratings/', include('star_ratings.urls', namespace='ratings', app_name='ratings')),
183 # Formerly 3rd party
184 url(r'^notification/', include('notification.urls')),
185
186
187=== modified file 'wlmaps/templatetags/wlmaps_extra.py'
188--- wlmaps/templatetags/wlmaps_extra.py 2016-12-13 18:28:51 +0000
189+++ wlmaps/templatetags/wlmaps_extra.py 2018-11-18 21:30:49 +0000
190@@ -12,4 +12,4 @@
191 avg = '%.1f' % (float(rating.score) / rating.votes)
192 else:
193 avg = '0.0'
194- return avg
195+ return 'Old: {}'.format(avg)

Subscribers

People subscribed via source and target branches