widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #15354
[Merge] lp:~widelands-dev/widelands-website/replace_djangoratings into lp:widelands-website
kaputtnik has proposed merging lp:~widelands-dev/widelands-website/replace_djangoratings into lp:widelands-website.
Commit message:
Exchange old app djangoratings with django-star-ratings
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1762158 in Widelands Website: "Replace django-ratings with an up to date app"
https://bugs.launchpad.net/widelands-website/+bug/1762158
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands-website/replace_djangoratings/+merge/358958
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 conversation of old votes to new votes (see below) can be done in the django shell. 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.
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()
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands-website/replace_djangoratings into lp:widelands-website.
=== renamed file 'djangoratings/templatetags/ratings.py' => 'djangoratings/templatetags/ratings_old.py'
=== modified file 'media/css/base.css'
--- media/css/base.css 2018-10-15 07:13:24 +0000
+++ media/css/base.css 2018-11-18 16:46:02 +0000
@@ -108,6 +108,10 @@
font-weight: bold;
}
+.star-ratings input, button {
+ padding: inherit;
+}
+
textarea {
font-weight: normal;
font-size: 0.9em;
=== modified file 'pip_requirements.txt'
--- pip_requirements.txt 2018-11-05 17:12:12 +0000
+++ pip_requirements.txt 2018-11-18 16:46:02 +0000
@@ -7,6 +7,7 @@
# Do not install newer versions because our notifications app is affected
-e git://github.com/arneb/django-messages.git@2d8dabb755e0b5ace876bde25f45d07c2051ac37#egg=django_messages
django-nocaptcha-recaptcha==0.0.19
+django-star-ratings==0.7.0
dj-pagination==2.3.2
django-registration==2.4.1
django-tagging==0.4.5
=== modified file 'settings.py'
--- settings.py 2018-11-12 19:36:22 +0000
+++ settings.py 2018-11-18 16:46:02 +0000
@@ -110,6 +110,7 @@
'django_messages_wl.apps.WLDjangoMessagesConfig',
'dj_pagination',
'tagging',
+ 'star_ratings',
'djangoratings', # included as wlapp
]
@@ -333,6 +334,14 @@
# See: https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-age
CSRF_COOKIE_AGE = None
+##############################
+# star_rarting configuration #
+##############################
+
+STAR_RATINGS_STAR_HEIGHT = 14
+STAR_RATINGS_STAR_WIDTH = 14
+STAR_RATINGS_RANGE = 10
+
try:
from local_settings import *
except ImportError:
=== modified file 'templates/wlmaps/base.html'
--- templates/wlmaps/base.html 2015-02-18 22:30:08 +0000
+++ templates/wlmaps/base.html 2018-11-18 16:46:02 +0000
@@ -1,4 +1,5 @@
{% extends "base.html" %}
+{% load static %}
{% comment %}
vim:ft=htmldjango
@@ -7,6 +8,8 @@
{% block extra_head %}
<link rel="stylesheet" type="text/css" media="all" href="{{ MEDIA_URL }}css/forum.css" />
<link rel="stylesheet" type="text/css" media="all" href="{{ MEDIA_URL }}css/maps.css" />
+<link rel="stylesheet" href="{% static 'star-ratings/css/star-ratings.css' %}">
+<script type="text/javascript" src="{% static 'star-ratings/js/dist/star-ratings.min.js' %}"></script>
{{block.super}}
{% endblock %}
=== modified file 'templates/wlmaps/index.html'
--- templates/wlmaps/index.html 2018-10-14 13:24:15 +0000
+++ templates/wlmaps/index.html 2018-11-18 16:46:02 +0000
@@ -8,6 +8,8 @@
{% load wlmaps_extra %}
{% load threadedcommentstags %}
{% load pagination_tags %}
+{% load ratings %}
+{% load ratings_old %}
{% block content_header %}
<h1>Maps</h1>
@@ -55,7 +57,9 @@
</tr>
<tr>
<td class="grey">Rating:</td>
- <td>{{ map.rating|average_rating }} ({{ map.rating.votes }} Votes)</td>
+ <td>
+ {% ratings map read_only template_name='star_rating/average.html' %}
+ {{ map.rating|average_rating }} ({{ map.rating.votes }} Votes)</td>
<td class="spacer"></td>
{% get_comment_count for map as ccount %}
<td class="grey">Comments:</td><td>{{ ccount }}</td>
=== modified file 'templates/wlmaps/map_detail.html'
--- templates/wlmaps/map_detail.html 2018-10-14 13:24:15 +0000
+++ templates/wlmaps/map_detail.html 2018-11-18 16:46:02 +0000
@@ -8,6 +8,8 @@
{% load wlprofile_extras %}
{% load threadedcommentstags %}
{% load wl_markdown %}
+{% load ratings %}
+{% load ratings_old %}
{% block title %}{{ map.name }} - {{ block.super }}{% endblock %}
@@ -29,6 +31,7 @@
});
});
</script>
+
{% endif %}
{% endblock %}
@@ -94,7 +97,7 @@
</tr>
<tr>
<td class="grey">Rating:</td>
- <td>
+ <td>{% ratings map template_name='star_rating/rate.html' %}
{{ map.rating|average_rating }} ({{ map.rating.votes }} Votes)
{% if not user.is_anonymous %}
<span id="vote"></span>
=== modified file 'urls.py'
--- urls.py 2018-10-10 17:04:53 +0000
+++ urls.py 2018-11-18 16:46:02 +0000
@@ -27,6 +27,7 @@
url(r'^accounts/', include('registration.backends.hmac.urls')),
url('^', include('django.contrib.auth.urls')),
+ url(r'^ratings/', include('star_ratings.urls', namespace='ratings', app_name='ratings')),
# Formerly 3rd party
url(r'^notification/', include('notification.urls')),
=== modified file 'wlmaps/templatetags/wlmaps_extra.py'
--- wlmaps/templatetags/wlmaps_extra.py 2016-12-13 18:28:51 +0000
+++ wlmaps/templatetags/wlmaps_extra.py 2018-11-18 16:46:02 +0000
@@ -12,4 +12,4 @@
avg = '%.1f' % (float(rating.score) / rating.votes)
else:
avg = '0.0'
- return avg
+ return 'Old: {}'.format(avg)
Follow ups