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

Proposed by kaputtnik
Status: Merged
Merged at revision: 466
Proposed branch: lp:~widelands-dev/widelands-website/fix_wares_for_encyclopedia
Merge into: lp:widelands-website
Diff against target: 45 lines (+10/-0)
2 files modified
wlhelp/management/commands/update_help.py (+5/-0)
wlhelp/models.py (+5/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands-website/fix_wares_for_encyclopedia
Reviewer Review Type Date Requested Status
kaputtnik (community) Needs Resubmitting
GunChleoc Approve
Review via email: mp+327737@code.launchpad.net

Commit message

Fix wares oredring in encyclopedia by ordering of wares.

Description of the change

This fixes bug 1704955 by sorting a dict and provide a default ordering when querying a ware.

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

LGTM :)

Maybe add a comment to the line as to why this was done?

review: Approve
467. By kaputtnik

added comments

Revision history for this message
kaputtnik (franku) wrote :

I forgot: This is tested locally for 'build_cost' and 'produces'. But only for the mentioned buildings which have known faulty entries.

Commenting is a good idea... Added some comments, please review if the comments fit, are understandable and worded correctly :-)

Thanks for the review :-)

review: Needs Resubmitting
Revision history for this message
GunChleoc (gunchleoc) wrote :

1 Nit. Let's get this in and do more testing on the live site.

468. By kaputtnik

adjusted comment

Revision history for this message
kaputtnik (franku) wrote :

This is pushed onto the server now, but not committed yet.

The encyclopedia is manually updated so the new code is executed and the wares should appear properly (hopefully).

Revision history for this message
kaputtnik (franku) wrote :

After worldsavior confirmed that all is working, the changes are comittet.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'wlhelp/management/commands/update_help.py'
2--- wlhelp/management/commands/update_help.py 2016-07-02 12:38:06 +0000
3+++ wlhelp/management/commands/update_help.py 2017-07-21 14:54:39 +0000
4@@ -24,6 +24,7 @@
5 import re
6 import json
7 import subprocess
8+import collections
9
10 from settings import MEDIA_ROOT, WIDELANDS_SVN_DIR, MEDIA_URL
11
12@@ -209,6 +210,10 @@
13 element_set = {}
14 for element in json_:
15 element_set[element['name']] = str(element['amount'])
16+ # Sort the dictionary alphabetical. Otherwise a wrong relation will
17+ # be made, e.g. build_cost and build_wares in
18+ # models.get_build_cost() and other functions over there.
19+ element_set = collections.OrderedDict(sorted(element_set.items()))
20 counts = ' '.join(element_set.values())
21 objects = [objtype.objects.get_or_create(name=w, tribe=self._to)[
22 0] for w in element_set.keys()]
23
24=== modified file 'wlhelp/models.py'
25--- wlhelp/models.py 2016-07-02 12:38:06 +0000
26+++ wlhelp/models.py 2017-07-21 14:54:39 +0000
27@@ -55,6 +55,9 @@
28 # This limit shall probably cover the longest help (found 209, nothing
29 # more)
30 help = models.TextField(max_length=256)
31+
32+ class Meta:
33+ ordering = ['name']
34
35 if settings.USE_SPHINX:
36 search = SphinxSearch(
37@@ -176,6 +179,8 @@
38 return (self.build_wares.all().count() != 0)
39
40 def get_build_cost(self):
41+ # Creating the relation between build_cost and build_wares
42+ # Querying the wares returns the wares in alphabetical order!
43 count = map(int, self.build_costs.split())
44 for c, w in zip(count, self.build_wares.all()):
45 yield [w] * c

Subscribers

People subscribed via source and target branches