pandora/pandora/app/models.py

56 lines
1.3 KiB
Python
Raw Normal View History

2010-02-27 11:37:22 +00:00
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
2011-02-22 14:54:38 +00:00
from __future__ import division, with_statement
2013-10-22 15:57:05 +00:00
import json
from django.db import models
2011-01-01 11:44:42 +00:00
2012-01-31 17:12:03 +00:00
from changelog.models import Changelog
2011-01-21 15:44:46 +00:00
import monkey_patch
2010-02-10 13:10:14 +00:00
class Page(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
name = models.CharField(max_length=1024, unique=True)
2012-02-18 11:59:50 +00:00
text = models.TextField(blank=True)
2010-02-10 13:10:14 +00:00
def __unicode__(self):
return self.name
2010-02-27 10:49:06 +00:00
2012-01-31 17:12:03 +00:00
def log(self):
c = Changelog(type='page')
c.value = {
'name': self.name,
2012-02-18 11:59:50 +00:00
'text': self.text,
2012-01-31 17:12:03 +00:00
}
c.save()
2013-10-22 15:57:05 +00:00
class Settings(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
key = models.CharField(max_length=1024, unique=True)
value = models.TextField(blank=True)
def __unicode__(self):
return self.key
@classmethod
def set(cls, key, value):
o, created = cls.objects.get_or_create(key=key)
o.value = json.dumps(value)
o.save()
@classmethod
def get(cls, key, default=None):
if cls.objects.filter(key=key).exists():
value = json.loads(cls.objects.get(key=key).value)
else:
value = default
return value