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

Proposed by kaputtnik
Status: Merged
Merged at revision: 532
Proposed branch: lp:~widelands-dev/widelands-website/screshot_ordering
Merge into: lp:widelands-website
Diff against target: 281 lines (+144/-44)
8 files modified
notification/migrations/0003_auto_20190409_0924.py (+20/-0)
wlhelp/migrations/0002_auto_20190410_1734.py (+36/-0)
wlscreens/admin.py (+7/-0)
wlscreens/migrations/0002_auto_20190410_1737.py (+28/-0)
wlscreens/models.py (+44/-25)
wlscreens/templates/wlscreens/index.html (+1/-0)
wlscreens/urls.py (+1/-2)
wlscreens/views.py (+7/-17)
To merge this branch: bzr merge lp:~widelands-dev/widelands-website/screshot_ordering
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+365763@code.launchpad.net

Commit message

Allow ordering of screenshots by applying a new database column.

Description of the change

Add a new database column 'position' to the model of wlscreens_screenshot. This makes it possible to reorder the screenshots after uploading.

In the admin page a list of screenshots is added to a category. E.g. clicking on Category 'Build 20' all screenshots for 'Build 20' will be listet. One can edit (upload, change) the screenshots in this list. So one don't have to edit each screenshot by its own.

Removed: url for displaying screenshots by one category, which leads only into a 404.

Changed: Replaced the view function with a django class based view.

I thought also to have the screenshot list paginated, to speed up loading time, but i didn't found a good solution to display the pagination bar. This can be done later on.

To get this in:
merge the branch
run: ./manage.py migrate
restart the website

To post a comment you must log in.
Revision history for this message
GunChleoc (gunchleoc) wrote :

LGTM. Thanks for implementing this :)

review: Approve
535. By kaputtnik

applied some default ordering

536. By kaputtnik

added new migration file for wlscreens; added also migration files for notification and wlhelp which reflect the last small changes

Revision history for this message
kaputtnik (franku) wrote :

Did also applied some default orderings and reworked also the admmin page for 'Screenshots'.

Merged and deployed, happy reordering :-)

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks a lot!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'notification/migrations/0003_auto_20190409_0924.py'
2--- notification/migrations/0003_auto_20190409_0924.py 1970-01-01 00:00:00 +0000
3+++ notification/migrations/0003_auto_20190409_0924.py 2019-04-10 16:02:18 +0000
4@@ -0,0 +1,20 @@
5+# -*- coding: utf-8 -*-
6+# Generated by Django 1.11.20 on 2019-04-09 09:24
7+from __future__ import unicode_literals
8+
9+from django.db import migrations, models
10+
11+
12+class Migration(migrations.Migration):
13+
14+ dependencies = [
15+ ('notification', '0002_auto_20170417_1857'),
16+ ]
17+
18+ operations = [
19+ migrations.AlterField(
20+ model_name='noticetype',
21+ name='display',
22+ field=models.CharField(help_text='Used as subject when sending emails.', max_length=50, verbose_name='display'),
23+ ),
24+ ]
25
26=== added file 'wlhelp/migrations/0002_auto_20190410_1734.py'
27--- wlhelp/migrations/0002_auto_20190410_1734.py 1970-01-01 00:00:00 +0000
28+++ wlhelp/migrations/0002_auto_20190410_1734.py 2019-04-10 16:02:18 +0000
29@@ -0,0 +1,36 @@
30+# -*- coding: utf-8 -*-
31+# Generated by Django 1.11.20 on 2019-04-10 17:34
32+from __future__ import unicode_literals
33+
34+from django.db import migrations, models
35+
36+
37+class Migration(migrations.Migration):
38+
39+ dependencies = [
40+ ('wlhelp', '0001_initial'),
41+ ]
42+
43+ operations = [
44+ migrations.AlterModelOptions(
45+ name='building',
46+ options={'ordering': ['name']},
47+ ),
48+ migrations.AlterModelOptions(
49+ name='tribe',
50+ options={'ordering': ['name']},
51+ ),
52+ migrations.AlterModelOptions(
53+ name='ware',
54+ options={'ordering': ['name']},
55+ ),
56+ migrations.AlterModelOptions(
57+ name='worker',
58+ options={'ordering': ['name']},
59+ ),
60+ migrations.AlterField(
61+ model_name='building',
62+ name='type',
63+ field=models.CharField(choices=[(b'P', b'productionsite'), (b'W', b'warehouse'), (b'M', b'militarysite'), (b'T', b'trainingsite'), (b'm', b'market')], max_length=1),
64+ ),
65+ ]
66
67=== modified file 'wlscreens/admin.py'
68--- wlscreens/admin.py 2016-12-13 18:28:51 +0000
69+++ wlscreens/admin.py 2019-04-10 16:02:18 +0000
70@@ -5,10 +5,16 @@
71 from django.contrib import admin
72
73
74+class ScreenshotsInline(admin.TabularInline):
75+ model = Screenshot
76+ fields = ('screenshot', 'name', 'comment', 'position')
77+
78+
79 class CategoryAdmin(admin.ModelAdmin):
80 prepopulated_fields = {'slug': ('name',)}
81 search_fields = ['name']
82 list_display = ['name']
83+ inlines = [ScreenshotsInline,]
84
85 admin.site.register(Category, CategoryAdmin)
86
87@@ -16,5 +22,6 @@
88 class ScreenshotAdmin(admin.ModelAdmin):
89 search_fields = ['name']
90 list_filter = ['category']
91+ list_display = ['category', 'name', 'position']
92
93 admin.site.register(Screenshot, ScreenshotAdmin)
94
95=== added file 'wlscreens/migrations/0002_auto_20190410_1737.py'
96--- wlscreens/migrations/0002_auto_20190410_1737.py 1970-01-01 00:00:00 +0000
97+++ wlscreens/migrations/0002_auto_20190410_1737.py 2019-04-10 16:02:18 +0000
98@@ -0,0 +1,28 @@
99+# -*- coding: utf-8 -*-
100+# Generated by Django 1.11.20 on 2019-04-10 17:37
101+from __future__ import unicode_literals
102+
103+from django.db import migrations, models
104+
105+
106+class Migration(migrations.Migration):
107+
108+ dependencies = [
109+ ('wlscreens', '0001_initial'),
110+ ]
111+
112+ operations = [
113+ migrations.AlterModelOptions(
114+ name='category',
115+ options={'ordering': ['-name']},
116+ ),
117+ migrations.AlterModelOptions(
118+ name='screenshot',
119+ options={'ordering': ['-category__name', 'position']},
120+ ),
121+ migrations.AddField(
122+ model_name='screenshot',
123+ name='position',
124+ field=models.IntegerField(blank=True, default=0, help_text=b'The position inside the category', null=True),
125+ ),
126+ ]
127
128=== modified file 'wlscreens/models.py'
129--- wlscreens/models.py 2019-03-31 11:08:21 +0000
130+++ wlscreens/models.py 2019-04-10 16:02:18 +0000
131@@ -29,15 +29,15 @@
132 name = models.CharField(max_length=255)
133 slug = models.SlugField(max_length=255, unique=True, blank=True)
134
135+ class Meta:
136+ ordering = ['-name']
137+
138 def save(self, *args, **kwargs):
139 if not self.slug:
140 self.slug = slugify(self.name)
141
142 return super(Category, self).save(*args, **kwargs)
143
144- def get_absolute_url(self):
145- return reverse('wlscreens_category', kwargs={'category_slug': self.slug})
146-
147 def __unicode__(self):
148 return u"%s" % self.name
149
150@@ -65,35 +65,54 @@
151 editable=False,
152 storage=OverwriteStorage(),
153 )
154- comment = models.TextField(null=True, blank=True)
155- category = models.ForeignKey(Category, related_name='screenshots')
156+ comment = models.TextField(
157+ null=True,
158+ blank=True
159+ )
160+ category = models.ForeignKey(
161+ Category,
162+ related_name='screenshots'
163+ )
164+ position = models.IntegerField(
165+ null=True,
166+ blank=True,
167+ default=0,
168+ help_text='The position inside the category',
169+ )
170
171 class Meta:
172 unique_together = ('name', 'category')
173+ ordering = ['-category__name', 'position']
174
175 def save(self, *args, **kwargs):
176 # Open original screenshot which we want to thumbnail using PIL's Image
177 # object
178- image = Image.open(self.screenshot)
179-
180- # Convert to RGB if necessary
181- if image.mode not in ('L', 'RGB'):
182- image = image.convert('RGB')
183-
184- image.thumbnail(settings.THUMBNAIL_SIZE, Image.ANTIALIAS)
185-
186- # Save the thumbnail
187- temp_handle = StringIO()
188- image.save(temp_handle, 'png')
189- temp_handle.seek(0)
190-
191- # Save to the thumbnail field
192- suf = SimpleUploadedFile(os.path.split(self.screenshot.name)[-1],
193- temp_handle.read(), content_type='image/png')
194- self.thumbnail.save(suf.name + '.png', suf, save=False)
195-
196- # Save this photo instance
197- super(Screenshot, self).save(*args, **kwargs)
198+ try:
199+ image = Image.open(self.screenshot)
200+
201+ # Convert to RGB if necessary
202+ if image.mode not in ('L', 'RGB'):
203+ image = image.convert('RGB')
204+
205+ image.thumbnail(settings.THUMBNAIL_SIZE, Image.ANTIALIAS)
206+
207+ # Save the thumbnail
208+ temp_handle = StringIO()
209+ image.save(temp_handle, 'png')
210+ temp_handle.seek(0)
211+
212+ # Save to the thumbnail field
213+ suf = SimpleUploadedFile(os.path.split(self.screenshot.name)[-1],
214+ temp_handle.read(), content_type='image/png')
215+ self.thumbnail.save(suf.name + '.png', suf, save=False)
216+
217+ # Save this photo instance
218+ super(Screenshot, self).save(*args, **kwargs)
219+ except IOError:
220+ # Likely we have a screenshot in the database which didn't exist
221+ # on the filesystem at the given path. Ignore it.
222+ pass
223+
224
225 def __unicode__(self):
226 return u"%s:%s" % (self.category.name, self.name)
227
228=== modified file 'wlscreens/templates/wlscreens/index.html'
229--- wlscreens/templates/wlscreens/index.html 2018-11-26 17:39:05 +0000
230+++ wlscreens/templates/wlscreens/index.html 2019-04-10 16:02:18 +0000
231@@ -24,6 +24,7 @@
232 {% block content_header %}
233 <h1>Screenshots</h1>
234 {% endblock %}
235+
236 {% block content_main %}
237 {% for c in categories %}
238 <div class="blogEntry">
239
240=== modified file 'wlscreens/urls.py'
241--- wlscreens/urls.py 2016-12-13 18:28:51 +0000
242+++ wlscreens/urls.py 2019-04-10 16:02:18 +0000
243@@ -5,6 +5,5 @@
244 from views import *
245
246 urlpatterns = [
247- url(r'^$', index, name='wlscreens_index'),
248- url(r'^(?P<category_slug>[-\w]+)/$', category, name='wlscreens_category'),
249+ url(r'^$', CategoryList.as_view(), name='wlscreens_index'),
250 ]
251
252=== modified file 'wlscreens/views.py'
253--- wlscreens/views.py 2018-04-05 18:55:35 +0000
254+++ wlscreens/views.py 2019-04-10 16:02:18 +0000
255@@ -1,19 +1,9 @@
256 # Create your views here.
257
258-from models import Category, Screenshot
259-from django.shortcuts import render
260-from django.http import Http404
261-
262-
263-def index(request):
264- c = Category.objects.order_by('-name')
265-
266- return render(request, 'wlscreens/index.html',
267- {'categories': c, }
268- )
269-
270-
271-def category(request, category_slug):
272- """Not implemented at the moment."""
273-
274- raise Http404
275+from models import Category
276+from django.views.generic.list import ListView
277+
278+class CategoryList(ListView):
279+ model = Category
280+ template_name = 'wlscreens/index.html'
281+ context_object_name = 'categories'

Subscribers

People subscribed via source and target branches