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
=== modified file 'wlhelp/management/commands/update_help.py'
--- wlhelp/management/commands/update_help.py 2016-07-02 12:38:06 +0000
+++ wlhelp/management/commands/update_help.py 2017-07-21 14:54:39 +0000
@@ -24,6 +24,7 @@
24import re24import re
25import json25import json
26import subprocess26import subprocess
27import collections
2728
28from settings import MEDIA_ROOT, WIDELANDS_SVN_DIR, MEDIA_URL29from settings import MEDIA_ROOT, WIDELANDS_SVN_DIR, MEDIA_URL
2930
@@ -209,6 +210,10 @@
209 element_set = {}210 element_set = {}
210 for element in json_:211 for element in json_:
211 element_set[element['name']] = str(element['amount'])212 element_set[element['name']] = str(element['amount'])
213 # Sort the dictionary alphabetical. Otherwise a wrong relation will
214 # be made, e.g. build_cost and build_wares in
215 # models.get_build_cost() and other functions over there.
216 element_set = collections.OrderedDict(sorted(element_set.items()))
212 counts = ' '.join(element_set.values())217 counts = ' '.join(element_set.values())
213 objects = [objtype.objects.get_or_create(name=w, tribe=self._to)[218 objects = [objtype.objects.get_or_create(name=w, tribe=self._to)[
214 0] for w in element_set.keys()]219 0] for w in element_set.keys()]
215220
=== modified file 'wlhelp/models.py'
--- wlhelp/models.py 2016-07-02 12:38:06 +0000
+++ wlhelp/models.py 2017-07-21 14:54:39 +0000
@@ -55,6 +55,9 @@
55 # This limit shall probably cover the longest help (found 209, nothing55 # This limit shall probably cover the longest help (found 209, nothing
56 # more)56 # more)
57 help = models.TextField(max_length=256)57 help = models.TextField(max_length=256)
58
59 class Meta:
60 ordering = ['name']
5861
59 if settings.USE_SPHINX:62 if settings.USE_SPHINX:
60 search = SphinxSearch(63 search = SphinxSearch(
@@ -176,6 +179,8 @@
176 return (self.build_wares.all().count() != 0)179 return (self.build_wares.all().count() != 0)
177180
178 def get_build_cost(self):181 def get_build_cost(self):
182 # Creating the relation between build_cost and build_wares
183 # Querying the wares returns the wares in alphabetical order!
179 count = map(int, self.build_costs.split())184 count = map(int, self.build_costs.split())
180 for c, w in zip(count, self.build_wares.all()):185 for c, w in zip(count, self.build_wares.all()):
181 yield [w] * c186 yield [w] * c

Subscribers

People subscribed via source and target branches