Package madrona :: Package layer_manager :: Module models
[hide private]

Source Code for Module madrona.layer_manager.models

  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 # not really using these atm 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
19 - def __unicode__(self):
20 return unicode('%s' % (self.name))
21 22 @property 25 26 @property
27 - def toDict(self):
28 layers = [layer.id for layer in self.layer_set.filter(is_sublayer=False).exclude(layer_type='placeholder')] 29 themes_dict = { 30 'id': self.id, 31 'display_name': self.display_name, 32 'learn_link': self.learn_link, 33 'layers': layers, 34 'description': self.description 35 } 36 return themes_dict
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 #tooltip 63 description = models.TextField(blank=True, null=True) 64 65 #data description (updated fact sheet) (now the Learn pages) 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 #data catalog links 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 #geojson javascript attribution 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
98 - def __unicode__(self):
99 return unicode('%s' % (self.name))
100 101 @property
102 - def calculate_url(self):
103 if self.subdomains: 104 urls = [] 105 for sd in self.subdomains.split(","): 106 urls.append(self.url.replace("${s}",sd)) 107 return urls 108 else: 109 return self.url
110 111 @property
112 - def is_parent(self):
113 return self.sublayers.all().count() > 0 and not self.is_sublayer
114 115 @property
116 - def parent(self):
117 if self.is_sublayer: 118 return self.sublayers.all()[0] 119 return self
120 121 @property
122 - def slug(self):
123 return slugify(self.name)
124 125 @property
126 - def data_overview_text(self):
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
133 - def data_source_text(self):
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 195 196 @property 200 201 @property
202 - def tooltip(self):
203 if self.description and self.description.strip() != '': 204 return self.description 205 elif self.parent.description and self.parent.description.strip() != '': 206 return self.parent.description 207 else: 208 return None
209 210 @property
211 - def serialize_attributes(self):
212 return {'title': self.attribute_title, 213 'compress_attributes': self.compress_display, 214 'event': self.attribute_event, 215 'attributes': [{'display': attr.display_name, 'field': attr.field_name, 'precision': attr.precision} for attr in self.attribute_fields.all().order_by('order')]}
216 217 @property
218 - def serialize_lookups(self):
219 return {'field': self.lookup_field, 220 'details': [{'value': lookup.value, 'color': lookup.color, 'dashstyle': lookup.dashstyle, 'fill': lookup.fill, 'graphic': lookup.graphic} for lookup in self.lookup_table.all()]}
221 222 @property
223 - def toDict(self):
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
272 -class AttributeInfo(models.Model):
273 display_name = models.CharField(max_length=255, blank=True, null=True) 274 field_name = models.CharField(max_length=255, blank=True, null=True) 275 precision = models.IntegerField(blank=True, null=True) 276 order = models.IntegerField(default=1) 277
278 - def __unicode__(self):
279 return unicode('%s' % (self.field_name))
280
281 -class LookupInfo(models.Model):
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
296 - def __unicode__(self):
297 return unicode('%s' % (self.value))
298
299 300 -class DataNeed(models.Model):
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
313 - def html_name(self):
314 return self.name.lower().replace(' ', '-')
315
316 - def __unicode__(self):
317 return unicode('%s' % (self.name))
318