~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to online_help/models.py

  • Committer: Holger Rapp
  • Date: 2010-01-01 21:35:23 UTC
  • mto: (173.3.2 widelands)
  • mto: This revision was merged to the branch mainline in revision 176.
  • Revision ID: rapp@mrt.uka.de-20100101213523-53rcapbemm69ep6u
Made the site compatible to django 1.1 and all the various packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
import settings
4
4
if settings.USE_SPHINX:
5
 
    from djangosphinx.models import SphinxSearch
 
5
    from djangosphinx import SphinxSearch
6
6
 
7
7
class Tribe(models.Model):
8
8
    name = models.CharField(max_length=100)
9
9
    displayname = models.CharField(max_length=100)
10
10
 
11
11
 
12
 
class Worker(models.Model):
13
 
    if settings.USE_SPHINX:
14
 
        search          = SphinxSearch(
15
 
            weights = {
16
 
                'displayname': 100,
17
 
                'help': 60,
18
 
                'name': 20,
19
 
                }
20
 
        )
21
 
 
22
 
    name = models.CharField(max_length=100)
23
 
    displayname = models.CharField(max_length=100)
24
 
    tribe = models.ForeignKey(Tribe)
25
 
    image_url = models.CharField( max_length=256 ) # URL to include this, i wasn't able to feed django local images
26
 
    graph_url = models.CharField( max_length=256 ) # URL to the help graph
27
 
    imagemap = models.TextField() # the image map for the help graph
28
 
 
29
 
    help = models.TextField(max_length=256) # This limit shall probably cover the longest help (found 209, nothing more)
30
 
    exp = models.TextField(max_length=8) # Just in case
31
 
    becomes = models.OneToOneField('self', related_name="trained_by_experience", blank=True, null=True)
32
 
 
33
 
    def __unicode__(self):
34
 
        return u'%s' % self.name
35
 
 
36
 
 
37
12
class Ware(models.Model):
38
13
    name = models.CharField(max_length=100)
39
14
    displayname = models.CharField(max_length=100)
40
15
    tribe = models.ForeignKey(Tribe)
41
16
    image_url = models.CharField( max_length=256 ) # URL to include this, i wasn't able to feed django local images
42
 
    graph_url = models.CharField( max_length=256 ) # URL to the help graph
43
 
    imagemap = models.TextField() # the image map for the help graph
44
17
 
45
18
    help = models.TextField(max_length=256) # This limit shall probably cover the longest help (found 209, nothing more)
46
 
 
 
19
    
47
20
    if settings.USE_SPHINX:
48
21
        search          = SphinxSearch(
49
22
            weights = {
103
76
    displayname = models.CharField(max_length=100)
104
77
    tribe = models.ForeignKey(Tribe)
105
78
    image_url = models.CharField( max_length=256 ) # URL to include this, i wasn't able to feed django local images
106
 
    graph_url = models.CharField( max_length=256 ) # URL to the help graph
107
 
    imagemap = models.TextField() # the image map for the help graph
108
 
 
 
79
   
109
80
    size = models.CharField(max_length=1,choices=SIZES)
110
81
    type = models.CharField( max_length=1, choices=TYPES) # productionsite...
111
82
 
112
83
    help = models.TextField(blank=True)
113
 
 
 
84
    
114
85
    # Enhances to
115
 
    enhancement = models.OneToOneField('self', related_name='enhanced_from', blank=True, null=True)
 
86
    enhancement = models.OneToOneField('self',related_name='enhanced_from', blank=True, null=True)
116
87
 
117
88
    # Build cost
118
89
    build_wares = models.ManyToManyField(Ware, related_name="build_ware_for_buildings", blank=True)
119
 
    build_costs = models.CharField(max_length=100, blank=True) # ' '.joined() integer strings
120
 
 
121
 
    # Workers
122
 
    workers_types = models.ManyToManyField(Worker, related_name="workers_for_buildings", blank=True)
123
 
    workers_count = models.CharField(max_length=100, blank=True) # ' '.joined() integer strings
 
90
    build_costs = models.CharField(max_length=100,blank=True) # ' '.joined() integer strings
124
91
 
125
92
    # Store
126
 
    store_wares = models.ManyToManyField(Ware, related_name="stored_ware_for_buildings", blank=True)
 
93
    store_wares = models.ManyToManyField(Ware, related_name="stored_ware_for_buildings",blank=True)
127
94
    store_count = models.CharField(max_length=100, blank=True) # ' '.joined() integer strings
128
 
 
 
95
    
129
96
    # Output
130
 
    output_wares = models.ManyToManyField(Ware, related_name="produced_by_buildings", blank=True)
131
 
    output_workers = models.ManyToManyField(Worker, related_name="trained_by_buildings", blank=True)
132
 
 
133
 
    def save(self, *args, **kwargs):
134
 
 
135
 
        tdict = dict((b,a) for a,b in self.TYPES)
136
 
        sdict = dict((b,a) for a,b in self.SIZES)
137
 
 
138
 
        self.type = tdict.get(self.type, self.type)
139
 
        self.size = sdict.get(self.size, self.size)
140
 
 
141
 
        return models.Model.save(self, *args, **kwargs)
 
97
    output_wares = models.ManyToManyField(Ware, related_name="produced_by_buildings",blank=True)
142
98
 
143
99
    def has_build_cost(self):
144
100
        return (self.build_wares.all().count() != 0)
146
102
        count = map(int,self.build_costs.split( ))
147
103
        for c,w in zip(count,self.build_wares.all()):
148
104
            yield [w]*c
149
 
 
150
 
    def has_workers(self):
151
 
        return (self.workers_types.all().count() != 0)
152
 
    def get_workers(self):
153
 
        count = map(int,self.workers_count.split( ))
154
 
        for c,wor in zip(count,self.workers_types.all()):
155
 
            yield [wor]*c
156
 
 
 
105
    
157
106
    def produces(self):
158
107
        return (self.output_wares.all().count() != 0)
159
108
    def get_outputs(self):
160
109
        return self.output_wares.all()
161
 
    def trains(self):
162
 
        return (self.output_workers.all().count() != 0)
163
 
    def get_worker_outputs(self):
164
 
        return self.output_workers.all()
165
 
    def has_outputs(self):
166
 
        return (self.output_workers.all().count() != 0 or self.output_wares.all().count() != 0)
167
 
 
 
110
    
168
111
    def has_stored_wares(self):
169
112
        return (self.store_wares.all().count() != 0)
170
113
    def get_stored_wares(self):