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
=== added file 'notification/migrations/0003_auto_20190409_0924.py'
--- notification/migrations/0003_auto_20190409_0924.py 1970-01-01 00:00:00 +0000
+++ notification/migrations/0003_auto_20190409_0924.py 2019-04-10 16:02:18 +0000
@@ -0,0 +1,20 @@
1# -*- coding: utf-8 -*-
2# Generated by Django 1.11.20 on 2019-04-09 09:24
3from __future__ import unicode_literals
4
5from django.db import migrations, models
6
7
8class Migration(migrations.Migration):
9
10 dependencies = [
11 ('notification', '0002_auto_20170417_1857'),
12 ]
13
14 operations = [
15 migrations.AlterField(
16 model_name='noticetype',
17 name='display',
18 field=models.CharField(help_text='Used as subject when sending emails.', max_length=50, verbose_name='display'),
19 ),
20 ]
021
=== added file 'wlhelp/migrations/0002_auto_20190410_1734.py'
--- wlhelp/migrations/0002_auto_20190410_1734.py 1970-01-01 00:00:00 +0000
+++ wlhelp/migrations/0002_auto_20190410_1734.py 2019-04-10 16:02:18 +0000
@@ -0,0 +1,36 @@
1# -*- coding: utf-8 -*-
2# Generated by Django 1.11.20 on 2019-04-10 17:34
3from __future__ import unicode_literals
4
5from django.db import migrations, models
6
7
8class Migration(migrations.Migration):
9
10 dependencies = [
11 ('wlhelp', '0001_initial'),
12 ]
13
14 operations = [
15 migrations.AlterModelOptions(
16 name='building',
17 options={'ordering': ['name']},
18 ),
19 migrations.AlterModelOptions(
20 name='tribe',
21 options={'ordering': ['name']},
22 ),
23 migrations.AlterModelOptions(
24 name='ware',
25 options={'ordering': ['name']},
26 ),
27 migrations.AlterModelOptions(
28 name='worker',
29 options={'ordering': ['name']},
30 ),
31 migrations.AlterField(
32 model_name='building',
33 name='type',
34 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),
35 ),
36 ]
037
=== modified file 'wlscreens/admin.py'
--- wlscreens/admin.py 2016-12-13 18:28:51 +0000
+++ wlscreens/admin.py 2019-04-10 16:02:18 +0000
@@ -5,10 +5,16 @@
5from django.contrib import admin5from django.contrib import admin
66
77
8class ScreenshotsInline(admin.TabularInline):
9 model = Screenshot
10 fields = ('screenshot', 'name', 'comment', 'position')
11
12
8class CategoryAdmin(admin.ModelAdmin):13class CategoryAdmin(admin.ModelAdmin):
9 prepopulated_fields = {'slug': ('name',)}14 prepopulated_fields = {'slug': ('name',)}
10 search_fields = ['name']15 search_fields = ['name']
11 list_display = ['name']16 list_display = ['name']
17 inlines = [ScreenshotsInline,]
1218
13admin.site.register(Category, CategoryAdmin)19admin.site.register(Category, CategoryAdmin)
1420
@@ -16,5 +22,6 @@
16class ScreenshotAdmin(admin.ModelAdmin):22class ScreenshotAdmin(admin.ModelAdmin):
17 search_fields = ['name']23 search_fields = ['name']
18 list_filter = ['category']24 list_filter = ['category']
25 list_display = ['category', 'name', 'position']
1926
20admin.site.register(Screenshot, ScreenshotAdmin)27admin.site.register(Screenshot, ScreenshotAdmin)
2128
=== added file 'wlscreens/migrations/0002_auto_20190410_1737.py'
--- wlscreens/migrations/0002_auto_20190410_1737.py 1970-01-01 00:00:00 +0000
+++ wlscreens/migrations/0002_auto_20190410_1737.py 2019-04-10 16:02:18 +0000
@@ -0,0 +1,28 @@
1# -*- coding: utf-8 -*-
2# Generated by Django 1.11.20 on 2019-04-10 17:37
3from __future__ import unicode_literals
4
5from django.db import migrations, models
6
7
8class Migration(migrations.Migration):
9
10 dependencies = [
11 ('wlscreens', '0001_initial'),
12 ]
13
14 operations = [
15 migrations.AlterModelOptions(
16 name='category',
17 options={'ordering': ['-name']},
18 ),
19 migrations.AlterModelOptions(
20 name='screenshot',
21 options={'ordering': ['-category__name', 'position']},
22 ),
23 migrations.AddField(
24 model_name='screenshot',
25 name='position',
26 field=models.IntegerField(blank=True, default=0, help_text=b'The position inside the category', null=True),
27 ),
28 ]
029
=== modified file 'wlscreens/models.py'
--- wlscreens/models.py 2019-03-31 11:08:21 +0000
+++ wlscreens/models.py 2019-04-10 16:02:18 +0000
@@ -29,15 +29,15 @@
29 name = models.CharField(max_length=255)29 name = models.CharField(max_length=255)
30 slug = models.SlugField(max_length=255, unique=True, blank=True)30 slug = models.SlugField(max_length=255, unique=True, blank=True)
3131
32 class Meta:
33 ordering = ['-name']
34
32 def save(self, *args, **kwargs):35 def save(self, *args, **kwargs):
33 if not self.slug:36 if not self.slug:
34 self.slug = slugify(self.name)37 self.slug = slugify(self.name)
3538
36 return super(Category, self).save(*args, **kwargs)39 return super(Category, self).save(*args, **kwargs)
3740
38 def get_absolute_url(self):
39 return reverse('wlscreens_category', kwargs={'category_slug': self.slug})
40
41 def __unicode__(self):41 def __unicode__(self):
42 return u"%s" % self.name42 return u"%s" % self.name
4343
@@ -65,35 +65,54 @@
65 editable=False,65 editable=False,
66 storage=OverwriteStorage(),66 storage=OverwriteStorage(),
67 )67 )
68 comment = models.TextField(null=True, blank=True)68 comment = models.TextField(
69 category = models.ForeignKey(Category, related_name='screenshots')69 null=True,
70 blank=True
71 )
72 category = models.ForeignKey(
73 Category,
74 related_name='screenshots'
75 )
76 position = models.IntegerField(
77 null=True,
78 blank=True,
79 default=0,
80 help_text='The position inside the category',
81 )
7082
71 class Meta:83 class Meta:
72 unique_together = ('name', 'category')84 unique_together = ('name', 'category')
85 ordering = ['-category__name', 'position']
7386
74 def save(self, *args, **kwargs):87 def save(self, *args, **kwargs):
75 # Open original screenshot which we want to thumbnail using PIL's Image88 # Open original screenshot which we want to thumbnail using PIL's Image
76 # object89 # object
77 image = Image.open(self.screenshot)90 try:
7891 image = Image.open(self.screenshot)
79 # Convert to RGB if necessary92
80 if image.mode not in ('L', 'RGB'):93 # Convert to RGB if necessary
81 image = image.convert('RGB')94 if image.mode not in ('L', 'RGB'):
8295 image = image.convert('RGB')
83 image.thumbnail(settings.THUMBNAIL_SIZE, Image.ANTIALIAS)96
8497 image.thumbnail(settings.THUMBNAIL_SIZE, Image.ANTIALIAS)
85 # Save the thumbnail98
86 temp_handle = StringIO()99 # Save the thumbnail
87 image.save(temp_handle, 'png')100 temp_handle = StringIO()
88 temp_handle.seek(0)101 image.save(temp_handle, 'png')
89102 temp_handle.seek(0)
90 # Save to the thumbnail field103
91 suf = SimpleUploadedFile(os.path.split(self.screenshot.name)[-1],104 # Save to the thumbnail field
92 temp_handle.read(), content_type='image/png')105 suf = SimpleUploadedFile(os.path.split(self.screenshot.name)[-1],
93 self.thumbnail.save(suf.name + '.png', suf, save=False)106 temp_handle.read(), content_type='image/png')
94107 self.thumbnail.save(suf.name + '.png', suf, save=False)
95 # Save this photo instance108
96 super(Screenshot, self).save(*args, **kwargs)109 # Save this photo instance
110 super(Screenshot, self).save(*args, **kwargs)
111 except IOError:
112 # Likely we have a screenshot in the database which didn't exist
113 # on the filesystem at the given path. Ignore it.
114 pass
115
97116
98 def __unicode__(self):117 def __unicode__(self):
99 return u"%s:%s" % (self.category.name, self.name)118 return u"%s:%s" % (self.category.name, self.name)
100119
=== modified file 'wlscreens/templates/wlscreens/index.html'
--- wlscreens/templates/wlscreens/index.html 2018-11-26 17:39:05 +0000
+++ wlscreens/templates/wlscreens/index.html 2019-04-10 16:02:18 +0000
@@ -24,6 +24,7 @@
24{% block content_header %}24{% block content_header %}
25 <h1>Screenshots</h1>25 <h1>Screenshots</h1>
26{% endblock %}26{% endblock %}
27
27{% block content_main %}28{% block content_main %}
28{% for c in categories %}29{% for c in categories %}
29 <div class="blogEntry">30 <div class="blogEntry">
3031
=== modified file 'wlscreens/urls.py'
--- wlscreens/urls.py 2016-12-13 18:28:51 +0000
+++ wlscreens/urls.py 2019-04-10 16:02:18 +0000
@@ -5,6 +5,5 @@
5from views import *5from views import *
66
7urlpatterns = [7urlpatterns = [
8 url(r'^$', index, name='wlscreens_index'),8 url(r'^$', CategoryList.as_view(), name='wlscreens_index'),
9 url(r'^(?P<category_slug>[-\w]+)/$', category, name='wlscreens_category'),
10]9]
1110
=== modified file 'wlscreens/views.py'
--- wlscreens/views.py 2018-04-05 18:55:35 +0000
+++ wlscreens/views.py 2019-04-10 16:02:18 +0000
@@ -1,19 +1,9 @@
1# Create your views here.1# Create your views here.
22
3from models import Category, Screenshot3from models import Category
4from django.shortcuts import render4from django.views.generic.list import ListView
5from django.http import Http4045
66class CategoryList(ListView):
77 model = Category
8def index(request):8 template_name = 'wlscreens/index.html'
9 c = Category.objects.order_by('-name')9 context_object_name = 'categories'
10
11 return render(request, 'wlscreens/index.html',
12 {'categories': c, }
13 )
14
15
16def category(request, category_slug):
17 """Not implemented at the moment."""
18
19 raise Http404

Subscribers

People subscribed via source and target branches