-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodels.py
74 lines (63 loc) · 2.91 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from django.db import models
from mezzanine.pages.models import Page
# Block is dependent on Pages app from Mezzanine
class Block(models.Model):
title = models.CharField( max_length=35, blank=False, null=False )
blocktype = models.ForeignKey( "BlockType", blank=False, null=False )
pages = models.ManyToManyField( Page, blank=True, null=True )
position = models.ForeignKey( "BlockPosition", blank=False, null=False )
published = models.BooleanField( blank=True, null=False, default=False )
def __unicode__(self):
return self.title
# Positions for blocks
class BlockPosition(models.Model):
name = models.CharField( max_length=35, blank=False, null=False )
description = models.TextField( blank=True, null=True )
def __unicode__(self):
return self.name
class BlockType(models.Model):
name = models.CharField( max_length= 35, blank=False, null=False )
path = models.CharField( max_length=255, blank=False, null=False )
def __unicode__(self):
return self.name
class BlockTypeSetting( models.Model ):
blocktype = models.ForeignKey( BlockType )
setting_name = models.CharField( max_length=255, blank=False, null=False )
friendly_name = models.CharField( max_length=255, blank=False, null=False )
def __unicode__( self ):
#return "%s.%s" % ( self.blocktype.name, self.setting_name )
return self.friendly_name
class BlockConfig( models.Model ):
block = models.ForeignKey( Block )
setting = models.ForeignKey( BlockTypeSetting )
value = models.CharField( max_length=255, blank=False, null=False )
def __unicode__( self ):
#return "%s.%s: %s" % ( self.setting.blocktype.name, self.setting.setting_name, self.value )
return "%s: %s" % ( self.setting.friendly_name, self.value )
# NOTE: If caching of any kind (memcached or similar) is implemented, this
# should be kept there. It doesn't matter if we loose this data, and it's
# only valid for 10 mins anyway. It'll add extra load to the mysql database,
# etc. For a proof of concept-level thing, that harly matters, so just
# shoving it in there for now.
#
# NOTE: Data here might be deleted *at will*. In fact, it probably *should*
# be deleted every time fresh data is fetched, to avoid filling it with old
# crap.
#
# NOTE: Rule of thumb for using:
# * Delete *all* data more than 2 hours old for *all* places.
# * Do we have any data that's less than 11 mins old? Use it.
# * Can we fetch data? If so, use it, update cache, if not:
# * Do we have any data less than 2 hours old? Use it.
# * Give up.
#
# Typical thing to toss in here would be:
# place = Norge/Hordaland/Bergen/Sandviken
# updated = When the data was fetched
# hour = "10:30", which hour the data is for
# thing = "C" == Celcius
# value = "4" == Number of degrees C
#
# NOTE: Since we won't accumulate logged data, we don't care too much about
# splitting place to a separate table, to keep columns shorter in this one.
# It would give us work, and gain nothing.