1 from django.db import models
2 from django.template.defaultfilters import slugify
3
4 -class Theme(models.Model):
5 display_name = models.CharField(max_length=100)
6 name = models.CharField(max_length=100)
7 header_image = models.CharField(max_length=255, blank=True, null=True)
8 header_attrib = models.CharField(max_length=255, blank=True, null=True)
9 overview = models.TextField(blank=True, null=True)
10 description = models.TextField(blank=True, null=True)
11 thumbnail = models.URLField(max_length=255, blank=True, null=True)
12 factsheet_thumb = models.CharField(max_length=255, blank=True, null=True)
13 factsheet_link = models.CharField(max_length=255, blank=True, null=True)
14
15 feature_image = models.CharField(max_length=255, blank=True, null=True)
16 feature_excerpt = models.TextField(blank=True, null=True)
17 feature_link = models.CharField(max_length=255, blank=True, null=True)
18
20 return unicode('%s' % (self.name))
21
22 @property
24 return '/learn/%s' % (self.name)
25
26 @property
37
38 -class Layer(models.Model):
39 TYPE_CHOICES = (
40 ('XYZ', 'XYZ'),
41 ('WMS', 'WMS'),
42 ('ArcRest', 'ArcRest'),
43 ('radio', 'radio'),
44 ('checkbox', 'checkbox'),
45 ('Vector', 'Vector'),
46 ('placeholder', 'placeholder'),
47 )
48 name = models.CharField(max_length=100)
49 layer_type = models.CharField(max_length=50, choices=TYPE_CHOICES)
50 url = models.CharField(max_length=255, blank=True, null=True)
51 arcgis_layers = models.CharField(max_length=255, blank=True, null=True)
52 subdomains = models.CharField(max_length=255, blank=True, null=True)
53 sublayers = models.ManyToManyField('self', blank=True, null=True)
54 themes = models.ManyToManyField("Theme", blank=True, null=True)
55 is_sublayer = models.BooleanField(default=False)
56 legend = models.CharField(max_length=255, blank=True, null=True)
57 legend_title = models.CharField(max_length=255, blank=True, null=True)
58 legend_subtitle = models.CharField(max_length=255, blank=True, null=True)
59 utfurl = models.CharField(max_length=255, blank=True, null=True)
60 default_on = models.BooleanField(default=False)
61
62
63 description = models.TextField(blank=True, null=True)
64
65
66 data_overview = models.TextField(blank=True, null=True)
67 data_status = models.CharField(max_length=255, blank=True, null=True)
68 data_source = models.CharField(max_length=512, blank=True, null=True)
69 data_notes = models.TextField(blank=True, null=True)
70
71
72 bookmark = models.CharField(max_length=755, blank=True, null=True)
73 map_tiles = models.CharField(max_length=255, blank=True, null=True)
74 kml = models.CharField(max_length=255, blank=True, null=True)
75 data_download = models.CharField(max_length=255, blank=True, null=True)
76 learn_more = models.CharField(max_length=255, blank=True, null=True)
77 metadata = models.CharField(max_length=255, blank=True, null=True)
78 fact_sheet = models.CharField(max_length=255, blank=True, null=True)
79 source = models.CharField(max_length=512, blank=True, null=True)
80 thumbnail = models.URLField(max_length=255, blank=True, null=True)
81
82
83 EVENT_CHOICES = (
84 ('click', 'click'),
85 ('mouseover', 'mouseover')
86 )
87 attribute_title = models.CharField(max_length=255, blank=True, null=True)
88 attribute_fields = models.ManyToManyField('AttributeInfo', blank=True, null=True)
89 compress_display = models.BooleanField(default=False)
90 attribute_event = models.CharField(max_length=35, choices=EVENT_CHOICES, default='click')
91 lookup_field = models.CharField(max_length=255, blank=True, null=True)
92 lookup_table = models.ManyToManyField('LookupInfo', blank=True, null=True)
93 vector_color = models.CharField(max_length=7, blank=True, null=True)
94 vector_fill = models.FloatField(blank=True, null=True)
95 vector_graphic = models.CharField(max_length=255, blank=True, null=True)
96 opacity = models.FloatField(default=.5, blank=True, null=True)
97
99 return unicode('%s' % (self.name))
100
101 @property
110
111 @property
114
115 @property
120
121 @property
123 return slugify(self.name)
124
125 @property
127 if not self.data_overview and self.is_sublayer:
128 return self.parent.data_overview
129 else:
130 return self.data_overview
131
132 @property
134 if not self.data_source and self.is_sublayer:
135 return self.parent.data_source
136 else:
137 return self.data_source
138
139 @property
140 - def data_notes_text(self):
141 if not self.data_notes and self.is_sublayer:
142 return self.parent.data_notes
143 else:
144 return self.data_notes
145
146 @property
152
153 @property
161
162 @property
170
171 @property
179
180 @property
182 if self.learn_more:
183 return self.learn_more
184 else:
185 return None
186 """
187 # TODO
188 else:
189 try:
190 theme = self.themes.all()[0]
191 except IndexError:
192 return ""
193 return "%s#%s" %(theme.learn_link, self.slug)
194 """
195
196 @property
198 theme_name = self.themes.all()[0].name
199 return '/learn/%s#%s' % (theme_name, self.slug)
200
201 @property
209
210 @property
216
217 @property
221
222 @property
224 sublayers = [
225 {
226 'id': layer.id,
227 'name': layer.name,
228 'type': layer.layer_type,
229 'url': layer.calculate_url,
230 'arcgis_layers': layer.arcgis_layers,
231 'utfurl': layer.utfurl,
232 'parent': self.id,
233 'legend': layer.legend,
234 'legend_title': layer.legend_title,
235 'legend_subtitle': layer.legend_subtitle,
236 'description': layer.tooltip,
237 'learn_link': layer.learn_link,
238 'attributes': layer.serialize_attributes,
239 'lookups': layer.serialize_lookups,
240 'color': layer.vector_color,
241 'fill_opacity': layer.vector_fill,
242 'graphic': layer.vector_graphic,
243 'data_source': layer.data_source,
244 'opacity': layer.opacity
245 }
246 for layer in self.sublayers.all()
247 ]
248 layers_dict = {
249 'id': self.id,
250 'name': self.name,
251 'type': self.layer_type,
252 'url': self.calculate_url,
253 'arcgis_layers': self.arcgis_layers,
254 'utfurl': self.utfurl,
255 'subLayers': sublayers,
256 'legend': self.legend,
257 'legend_title': self.legend_title,
258 'legend_subtitle': self.legend_subtitle,
259 'description': self.description,
260 'learn_link': self.learn_link,
261 'attributes': self.serialize_attributes,
262 'lookups': self.serialize_lookups,
263 'default_on': self.default_on,
264 'color': self.vector_color,
265 'fill_opacity': self.vector_fill,
266 'graphic': self.vector_graphic,
267 'data_source': self.data_source,
268 'opacity': self.opacity
269 }
270 return layers_dict
271
280
282 DASH_CHOICES = (
283 ('dot', 'dot'),
284 ('dash', 'dash'),
285 ('dashdot', 'dashdot'),
286 ('longdash', 'longdash'),
287 ('longdashdot', 'longdashdot'),
288 ('solid', 'solid')
289 )
290 value = models.CharField(max_length=255, blank=True, null=True)
291 color = models.CharField(max_length=7, blank=True, null=True)
292 dashstyle = models.CharField(max_length=11, choices=DASH_CHOICES, default='solid')
293 fill = models.BooleanField(default=False)
294 graphic = models.CharField(max_length=255, blank=True, null=True)
295
297 return unicode('%s' % (self.value))
298
301 name = models.CharField(max_length=100)
302 archived = models.BooleanField(default=False)
303 description = models.TextField(blank=True, null=True)
304 source = models.CharField(max_length=255, blank=True, null=True)
305 status = models.TextField(blank=True, null=True)
306 contact = models.CharField(max_length=255, blank=True, null=True)
307 contact_email = models.CharField(max_length=255, blank=True, null=True)
308 expected_date = models.CharField(max_length=255, blank=True, null=True)
309 notes = models.TextField(blank=True, null=True)
310 themes = models.ManyToManyField("Theme", blank=True, null=True)
311
312 @property
314 return self.name.lower().replace(' ', '-')
315
317 return unicode('%s' % (self.name))
318