~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to wlhelp/models.py

  • Committer: Holger Rapp
  • Date: 2009-02-20 12:25:18 UTC
  • Revision ID: holgerrapp@gmx.net-20090220122518-feaq34ta973snnct
Imported wikiapp into our repository, because we did some local changes (users must be logged in to edit wiki pages)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from django.db import models
2
 
 
3
 
 
4
 
class Tribe(models.Model):
5
 
    name = models.CharField(max_length=100)
6
 
    displayname = models.CharField(max_length=100)
7
 
    descr = models.TextField()
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)
11
 
    
12
 
    class Meta:
13
 
        ordering = ['name']
14
 
 
15
 
 
16
 
    def __unicode__(self):
17
 
        return u'%s' % self.name
18
 
 
19
 
 
20
 
class Worker(models.Model):
21
 
 
22
 
    name = models.CharField(max_length=100)
23
 
    displayname = models.CharField(max_length=100)
24
 
    tribe = models.ForeignKey(Tribe)
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
29
 
 
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)
36
 
 
37
 
    class Meta:
38
 
        ordering = ['name']
39
 
 
40
 
 
41
 
    def __unicode__(self):
42
 
        return u'%s' % self.name
43
 
 
44
 
 
45
 
class Ware(models.Model):
46
 
    name = models.CharField(max_length=100)
47
 
    displayname = models.CharField(max_length=100)
48
 
    tribe = models.ForeignKey(Tribe)
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
53
 
 
54
 
    # This limit shall probably cover the longest help (found 209, nothing
55
 
    # more)
56
 
    help = models.TextField(max_length=256)
57
 
 
58
 
    class Meta:
59
 
        ordering = ['name']
60
 
 
61
 
 
62
 
    def __unicode__(self):
63
 
        return u'%s' % self.name
64
 
 
65
 
 
66
 
class BuildingManager(models.Manager):
67
 
 
68
 
    def small(self):
69
 
        return self.all().filter(size='S')
70
 
 
71
 
    def medium(self):
72
 
        return self.all().filter(size='M')
73
 
 
74
 
    def big(self):
75
 
        return self.all().filter(size='B')
76
 
 
77
 
    def mine(self):
78
 
        return self.all().filter(size='I')
79
 
 
80
 
    def port(self):
81
 
        return self.all().filter(size='P')
82
 
 
83
 
    def headquarters(self):
84
 
        return self.all().filter(size='H')
85
 
 
86
 
        # return self.build_wares.count()
87
 
 
88
 
    pass
89
 
 
90
 
 
91
 
class Building(models.Model):
92
 
    SIZES = (
93
 
            ('S', 'small'),
94
 
            ('M', 'medium'),
95
 
            ('B', 'big'),
96
 
            ('I', 'mine'),
97
 
            ('P', 'port'),
98
 
            ('H', 'headquarters'),
99
 
    )
100
 
    TYPES = (
101
 
            ('P', 'productionsite'),
102
 
            ('W', 'warehouse'),
103
 
            ('M', 'militarysite'),
104
 
            ('T', 'trainingsite'),
105
 
            ('m', 'market'),
106
 
    )
107
 
 
108
 
    objects = BuildingManager()
109
 
 
110
 
    name = models.CharField(max_length=100)
111
 
    displayname = models.CharField(max_length=100)
112
 
    tribe = models.ForeignKey(Tribe)
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
117
 
 
118
 
    size = models.CharField(max_length=1, choices=SIZES)
119
 
    type = models.CharField(max_length=1, choices=TYPES)  # productionsite...
120
 
 
121
 
    help = models.TextField(blank=True)
122
 
 
123
 
    # Enhances to
124
 
    enhancement = models.OneToOneField(
125
 
        'self', related_name='enhanced_from', blank=True, null=True)
126
 
 
127
 
    # Build cost
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)
132
 
 
133
 
    # Workers
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)
138
 
 
139
 
    # Store
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)
144
 
 
145
 
    # Output
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)
150
 
    
151
 
    class Meta:
152
 
        ordering = ['name']
153
 
 
154
 
 
155
 
    def save(self, *args, **kwargs):
156
 
 
157
 
        tdict = dict((b, a) for a, b in self.TYPES)
158
 
        sdict = dict((b, a) for a, b in self.SIZES)
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
 
 
165
 
    def has_build_cost(self):
166
 
        return (self.build_wares.all().count() != 0)
167
 
 
168
 
    def get_build_cost(self):
169
 
        # Creating the relation between build_cost and build_wares
170
 
        # Querying the wares returns the wares in alphabetical order!
171
 
        count = map(int, self.build_costs.split())
172
 
        for c, w in zip(count, self.build_wares.all()):
173
 
            yield [w] * c
174
 
 
175
 
    def has_workers(self):
176
 
        return (self.workers_types.all().count() != 0)
177
 
 
178
 
    def get_workers(self):
179
 
        count = map(int, self.workers_count.split())
180
 
        for c, wor in zip(count, self.workers_types.all()):
181
 
            yield [wor] * c
182
 
 
183
 
    def produces(self):
184
 
        return (self.output_wares.all().count() != 0)
185
 
 
186
 
    def get_ware_outputs(self):
187
 
        return self.output_wares.all()
188
 
 
189
 
    def trains(self):
190
 
        return (self.output_workers.all().count() != 0)
191
 
 
192
 
    def get_worker_outputs(self):
193
 
        return self.output_workers.all()
194
 
 
195
 
    def has_outputs(self):
196
 
        return (self.output_workers.all().count() != 0 or self.output_wares.all().count() != 0)
197
 
 
198
 
    def has_stored_wares(self):
199
 
        return (self.store_wares.all().count() != 0)
200
 
 
201
 
    def get_stored_wares(self):
202
 
        count = map(int, self.store_count.split())
203
 
        for c, w in zip(count, self.store_wares.all()):
204
 
            yield [w] * c
205
 
 
206
 
    def __unicode__(self):
207
 
        return u"%s/%s" % (self.tribe.name, self.name)