32
by Holger Rapp
First version of widelands online help |
1 |
from django.db import models |
2 |
||
404.1.20
by GunChleoc
Ran pyformat. |
3 |
|
32
by Holger Rapp
First version of widelands online help |
4 |
class Tribe(models.Model): |
5 |
name = models.CharField(max_length=100) |
|
6 |
displayname = models.CharField(max_length=100) |
|
325.1.21
by Shevonar
Lots of work and fixes on wlhelp |
7 |
descr = models.TextField() |
404.1.20
by GunChleoc
Ran pyformat. |
8 |
icon_url = models.CharField(max_length=256) |
9 |
network_pdf_url = models.CharField(max_length=256) |
|
10 |
network_gif_url = models.CharField(max_length=256) |
|
492.1.1
by franku
fixed server error for py-modindex; fixes some warnings |
11 |
|
12 |
class Meta: |
|
13 |
ordering = ['name'] |
|
14 |
||
32
by Holger Rapp
First version of widelands online help |
15 |
|
462.3.7
by franku
added encyclopedia workers; own templates for the search view |
16 |
def __unicode__(self): |
17 |
return u'%s' % self.name |
|
18 |
||
32
by Holger Rapp
First version of widelands online help |
19 |
|
194.1.1
by Stanislaw Gackowski
Very basic Workers display in the online_help - only worker types (not carriers and soldiers) and only the basic info. |
20 |
class Worker(models.Model): |
21 |
||
212.1.1
by Stanisław Gackowski
Added experience and becomes for workers. |
22 |
name = models.CharField(max_length=100) |
23 |
displayname = models.CharField(max_length=100) |
|
24 |
tribe = models.ForeignKey(Tribe) |
|
404.1.20
by GunChleoc
Ran pyformat. |
25 |
# URL to include this, i wasn't able to feed django local images
|
26 |
image_url = models.CharField(max_length=256) |
|
27 |
graph_url = models.CharField(max_length=256) # URL to the help graph |
|
28 |
imagemap = models.TextField() # the image map for the help graph |
|
212.1.1
by Stanisław Gackowski
Added experience and becomes for workers. |
29 |
|
404.1.20
by GunChleoc
Ran pyformat. |
30 |
# This limit shall probably cover the longest help (found 209, nothing
|
31 |
# more)
|
|
32 |
help = models.TextField(max_length=256) |
|
33 |
exp = models.TextField(max_length=8) # Just in case |
|
34 |
becomes = models.OneToOneField( |
|
35 |
'self', related_name='trained_by_experience', blank=True, null=True) |
|
194.1.1
by Stanislaw Gackowski
Very basic Workers display in the online_help - only worker types (not carriers and soldiers) and only the basic info. |
36 |
|
492.1.1
by franku
fixed server error for py-modindex; fixes some warnings |
37 |
class Meta: |
38 |
ordering = ['name'] |
|
39 |
||
40 |
||
194.1.1
by Stanislaw Gackowski
Very basic Workers display in the online_help - only worker types (not carriers and soldiers) and only the basic info. |
41 |
def __unicode__(self): |
42 |
return u'%s' % self.name |
|
43 |
||
44 |
||
32
by Holger Rapp
First version of widelands online help |
45 |
class Ware(models.Model): |
46 |
name = models.CharField(max_length=100) |
|
47 |
displayname = models.CharField(max_length=100) |
|
48 |
tribe = models.ForeignKey(Tribe) |
|
404.1.20
by GunChleoc
Ran pyformat. |
49 |
# URL to include this, i wasn't able to feed django local images
|
50 |
image_url = models.CharField(max_length=256) |
|
51 |
graph_url = models.CharField(max_length=256) # URL to the help graph |
|
52 |
imagemap = models.TextField() # the image map for the help graph |
|
32
by Holger Rapp
First version of widelands online help |
53 |
|
404.1.20
by GunChleoc
Ran pyformat. |
54 |
# This limit shall probably cover the longest help (found 209, nothing
|
55 |
# more)
|
|
56 |
help = models.TextField(max_length=256) |
|
492.1.1
by franku
fixed server error for py-modindex; fixes some warnings |
57 |
|
465.1.1
by franku
fixes displaying of wares in encyclopedia by sorting of items |
58 |
class Meta: |
59 |
ordering = ['name'] |
|
212.1.1
by Stanisław Gackowski
Added experience and becomes for workers. |
60 |
|
492.1.1
by franku
fixed server error for py-modindex; fixes some warnings |
61 |
|
32
by Holger Rapp
First version of widelands online help |
62 |
def __unicode__(self): |
63 |
return u'%s' % self.name |
|
64 |
||
65 |
||
66 |
class BuildingManager(models.Manager): |
|
404.1.20
by GunChleoc
Ran pyformat. |
67 |
|
32
by Holger Rapp
First version of widelands online help |
68 |
def small(self): |
404.1.20
by GunChleoc
Ran pyformat. |
69 |
return self.all().filter(size='S') |
70 |
||
32
by Holger Rapp
First version of widelands online help |
71 |
def medium(self): |
404.1.20
by GunChleoc
Ran pyformat. |
72 |
return self.all().filter(size='M') |
73 |
||
32
by Holger Rapp
First version of widelands online help |
74 |
def big(self): |
404.1.20
by GunChleoc
Ran pyformat. |
75 |
return self.all().filter(size='B') |
76 |
||
32
by Holger Rapp
First version of widelands online help |
77 |
def mine(self): |
404.1.20
by GunChleoc
Ran pyformat. |
78 |
return self.all().filter(size='I') |
79 |
||
325.1.21
by Shevonar
Lots of work and fixes on wlhelp |
80 |
def port(self): |
404.1.20
by GunChleoc
Ran pyformat. |
81 |
return self.all().filter(size='P') |
82 |
||
404.1.3
by fios at foramnagaidhlig
We have buildings! :) |
83 |
def headquarters(self): |
404.1.20
by GunChleoc
Ran pyformat. |
84 |
return self.all().filter(size='H') |
32
by Holger Rapp
First version of widelands online help |
85 |
|
86 |
# return self.build_wares.count()
|
|
87 |
||
88 |
pass
|
|
89 |
||
404.1.20
by GunChleoc
Ran pyformat. |
90 |
|
32
by Holger Rapp
First version of widelands online help |
91 |
class Building(models.Model): |
92 |
SIZES = ( |
|
93 |
('S', 'small'), |
|
94 |
('M', 'medium'), |
|
95 |
('B', 'big'), |
|
96 |
('I', 'mine'), |
|
325.1.19
by Shevonar
Moved and fixed online_help to fit add wlprefix. Will only work with next commit! |
97 |
('P', 'port'), |
404.1.3
by fios at foramnagaidhlig
We have buildings! :) |
98 |
('H', 'headquarters'), |
32
by Holger Rapp
First version of widelands online help |
99 |
)
|
100 |
TYPES = ( |
|
101 |
('P', 'productionsite'), |
|
102 |
('W', 'warehouse'), |
|
404.1.3
by fios at foramnagaidhlig
We have buildings! :) |
103 |
('M', 'militarysite'), |
484.1.2
by franku
Added internal name to wares and workers; added column 'Woks at' for workers |
104 |
('T', 'trainingsite'), |
105 |
('m', 'market'), |
|
32
by Holger Rapp
First version of widelands online help |
106 |
)
|
404.1.3
by fios at foramnagaidhlig
We have buildings! :) |
107 |
|
32
by Holger Rapp
First version of widelands online help |
108 |
objects = BuildingManager() |
404.1.3
by fios at foramnagaidhlig
We have buildings! :) |
109 |
|
32
by Holger Rapp
First version of widelands online help |
110 |
name = models.CharField(max_length=100) |
111 |
displayname = models.CharField(max_length=100) |
|
112 |
tribe = models.ForeignKey(Tribe) |
|
404.1.20
by GunChleoc
Ran pyformat. |
113 |
# URL to include this, i wasn't able to feed django local images
|
114 |
image_url = models.CharField(max_length=256) |
|
115 |
graph_url = models.CharField(max_length=256) # URL to the help graph |
|
116 |
imagemap = models.TextField() # the image map for the help graph |
|
224.1.3
by Timo Paulssen
make graphs available via the database and views |
117 |
|
404.1.20
by GunChleoc
Ran pyformat. |
118 |
size = models.CharField(max_length=1, choices=SIZES) |
119 |
type = models.CharField(max_length=1, choices=TYPES) # productionsite... |
|
32
by Holger Rapp
First version of widelands online help |
120 |
|
121 |
help = models.TextField(blank=True) |
|
224.1.3
by Timo Paulssen
make graphs available via the database and views |
122 |
|
32
by Holger Rapp
First version of widelands online help |
123 |
# Enhances to
|
404.1.20
by GunChleoc
Ran pyformat. |
124 |
enhancement = models.OneToOneField( |
125 |
'self', related_name='enhanced_from', blank=True, null=True) |
|
32
by Holger Rapp
First version of widelands online help |
126 |
|
127 |
# Build cost
|
|
404.1.20
by GunChleoc
Ran pyformat. |
128 |
build_wares = models.ManyToManyField( |
129 |
Ware, related_name='build_ware_for_buildings', blank=True) |
|
130 |
# ' '.joined() integer strings
|
|
131 |
build_costs = models.CharField(max_length=100, blank=True) |
|
32
by Holger Rapp
First version of widelands online help |
132 |
|
212.1.2
by Stanisław Gackowski
Check for workers in buildings - not displayed in help yet, will be there later on. |
133 |
# Workers
|
404.1.20
by GunChleoc
Ran pyformat. |
134 |
workers_types = models.ManyToManyField( |
135 |
Worker, related_name='workers_for_buildings', blank=True) |
|
136 |
# ' '.joined() integer strings
|
|
137 |
workers_count = models.CharField(max_length=100, blank=True) |
|
212.1.2
by Stanisław Gackowski
Check for workers in buildings - not displayed in help yet, will be there later on. |
138 |
|
32
by Holger Rapp
First version of widelands online help |
139 |
# Store
|
404.1.20
by GunChleoc
Ran pyformat. |
140 |
store_wares = models.ManyToManyField( |
141 |
Ware, related_name='stored_ware_for_buildings', blank=True) |
|
142 |
# ' '.joined() integer strings
|
|
143 |
store_count = models.CharField(max_length=100, blank=True) |
|
224.1.3
by Timo Paulssen
make graphs available via the database and views |
144 |
|
32
by Holger Rapp
First version of widelands online help |
145 |
# Output
|
404.1.20
by GunChleoc
Ran pyformat. |
146 |
output_wares = models.ManyToManyField( |
147 |
Ware, related_name='produced_by_buildings', blank=True) |
|
148 |
output_workers = models.ManyToManyField( |
|
149 |
Worker, related_name='trained_by_buildings', blank=True) |
|
492.1.1
by franku
fixed server error for py-modindex; fixes some warnings |
150 |
|
151 |
class Meta: |
|
152 |
ordering = ['name'] |
|
153 |
||
32
by Holger Rapp
First version of widelands online help |
154 |
|
232
by Holger Rapp
Quickfix for old mysql |
155 |
def save(self, *args, **kwargs): |
156 |
||
404.1.20
by GunChleoc
Ran pyformat. |
157 |
tdict = dict((b, a) for a, b in self.TYPES) |
158 |
sdict = dict((b, a) for a, b in self.SIZES) |
|
232
by Holger Rapp
Quickfix for old mysql |
159 |
|
160 |
self.type = tdict.get(self.type, self.type) |
|
161 |
self.size = sdict.get(self.size, self.size) |
|
162 |
||
163 |
return models.Model.save(self, *args, **kwargs) |
|
164 |
||
32
by Holger Rapp
First version of widelands online help |
165 |
def has_build_cost(self): |
166 |
return (self.build_wares.all().count() != 0) |
|
404.1.20
by GunChleoc
Ran pyformat. |
167 |
|
32
by Holger Rapp
First version of widelands online help |
168 |
def get_build_cost(self): |
465.1.2
by franku
added comments |
169 |
# Creating the relation between build_cost and build_wares
|
170 |
# Querying the wares returns the wares in alphabetical order!
|
|
404.1.20
by GunChleoc
Ran pyformat. |
171 |
count = map(int, self.build_costs.split()) |
172 |
for c, w in zip(count, self.build_wares.all()): |
|
173 |
yield [w] * c |
|
212.1.2
by Stanisław Gackowski
Check for workers in buildings - not displayed in help yet, will be there later on. |
174 |
|
175 |
def has_workers(self): |
|
176 |
return (self.workers_types.all().count() != 0) |
|
404.1.20
by GunChleoc
Ran pyformat. |
177 |
|
212.1.2
by Stanisław Gackowski
Check for workers in buildings - not displayed in help yet, will be there later on. |
178 |
def get_workers(self): |
404.1.20
by GunChleoc
Ran pyformat. |
179 |
count = map(int, self.workers_count.split()) |
180 |
for c, wor in zip(count, self.workers_types.all()): |
|
181 |
yield [wor] * c |
|
212.1.2
by Stanisław Gackowski
Check for workers in buildings - not displayed in help yet, will be there later on. |
182 |
|
32
by Holger Rapp
First version of widelands online help |
183 |
def produces(self): |
184 |
return (self.output_wares.all().count() != 0) |
|
404.1.20
by GunChleoc
Ran pyformat. |
185 |
|
325.1.21
by Shevonar
Lots of work and fixes on wlhelp |
186 |
def get_ware_outputs(self): |
32
by Holger Rapp
First version of widelands online help |
187 |
return self.output_wares.all() |
404.1.20
by GunChleoc
Ran pyformat. |
188 |
|
211
by Stanisław Gackowski
A quickfix for help generation - checks for recruit program in work section of the config. I'll update the templates later today. |
189 |
def trains(self): |
190 |
return (self.output_workers.all().count() != 0) |
|
404.1.20
by GunChleoc
Ran pyformat. |
191 |
|
211
by Stanisław Gackowski
A quickfix for help generation - checks for recruit program in work section of the config. I'll update the templates later today. |
192 |
def get_worker_outputs(self): |
193 |
return self.output_workers.all() |
|
404.1.20
by GunChleoc
Ran pyformat. |
194 |
|
212
by Stanisław Gackowski
Now displays outputs of workers (covered all the possible cases). |
195 |
def has_outputs(self): |
196 |
return (self.output_workers.all().count() != 0 or self.output_wares.all().count() != 0) |
|
212.1.2
by Stanisław Gackowski
Check for workers in buildings - not displayed in help yet, will be there later on. |
197 |
|
138.1.1
by Stanislaw Gackowski
Added new stored_wares to online_help and used it - new 'Requires' column |
198 |
def has_stored_wares(self): |
199 |
return (self.store_wares.all().count() != 0) |
|
404.1.20
by GunChleoc
Ran pyformat. |
200 |
|
138.1.1
by Stanislaw Gackowski
Added new stored_wares to online_help and used it - new 'Requires' column |
201 |
def get_stored_wares(self): |
404.1.20
by GunChleoc
Ran pyformat. |
202 |
count = map(int, self.store_count.split()) |
203 |
for c, w in zip(count, self.store_wares.all()): |
|
204 |
yield [w] * c |
|
138.1.1
by Stanislaw Gackowski
Added new stored_wares to online_help and used it - new 'Requires' column |
205 |
|
32
by Holger Rapp
First version of widelands online help |
206 |
def __unicode__(self): |
404.1.20
by GunChleoc
Ran pyformat. |
207 |
return u"%s/%s" % (self.tribe.name, self.name) |