def value(self): from forum.models import KeyValue try: kv = KeyValue.objects.get(key=self.name) except: kv = KeyValue(key=self.name, value=self._parse(self.default)) kv.save() return kv.value
def value(self): from forum.models import KeyValue try: kv = KeyValue.objects.get(key=self.name) except: kv = KeyValue(key=self.name, value=pickle.dumps(self.default)) kv.save() return pickle.loads(kv.value.encode('utf-8'))
def set_value(self, new_value): new_value = self._parse(new_value) from forum.models import KeyValue try: kv = KeyValue.objects.get(key=self.name) except: kv = KeyValue(key=self.name) kv.value = pickle.dumps(new_value) kv.save()
def set_value(self, new_value): new_value = self._parse(new_value) from forum.models import KeyValue try: kv = KeyValue.objects.get(key=self.name) old_value = kv.value except: kv = KeyValue(key=self.name) old_value = self.default kv.value = pickle.dumps(new_value) kv.save() setting_update.send(sender=self, old_value=old_value, new_value=new_value)
def set_value(self, new_value): new_value = self._parse(new_value) from forum.models import KeyValue try: kv = KeyValue.objects.get(key=self.name) old_value = kv.value except: kv = KeyValue(key=self.name) old_value = self.default kv.value = new_value kv.save() setting_update.send(sender=self, old_value=old_value, new_value=new_value)
def handle_noargs(self, **options): digest_control = EMAIL_DIGEST_CONTROL.value if digest_control is None: digest_control = KeyValue(key='DIGEST_CONTROL', value={ 'LAST_DAILY': datetime.now() - timedelta(days=1), 'LAST_WEEKLY': datetime.now() - timedelta(days=1), }) self.send_digest('daily', 'd', digest_control.value['LAST_DAILY']) digest_control.value['LAST_DAILY'] = datetime.now() if digest_control.value['LAST_WEEKLY'] + timedelta(days=7) <= datetime.now(): self.send_digest('weekly', 'w', digest_control.value['LAST_WEEKLY']) digest_control.value['LAST_WEEKLY'] = datetime.now() EMAIL_DIGEST_CONTROL.set_value(digest_control)
def save(self, value): from forum.models import KeyValue try: kv = KeyValue.objects.get(key=self.name) except KeyValue.DoesNotExist: kv = KeyValue(key=self.name) except Exception, e: logging.error("Error savin setting to database (%s): %s" % (self.name, str(e))) return
def get_digest_control(self): try: digest_control = KeyValue.objects.get(key='DIGEST_CONTROL') except: digest_control = KeyValue(key='DIGEST_CONTROL', value={ 'LAST_DAILY': datetime.now() - timedelta(days=1), 'LAST_WEEKLY': datetime.now() - timedelta(days=1), }) return digest_control
if version < VERSION: install = True except: install = True if install: f = open(os.path.join(os.path.dirname(__file__), 'pg_fts_install.sql'), 'r') try: cursor = connection.cursor() cursor.execute(f.read()) transaction.commit_unless_managed() try: kv = KeyValue.objects.get(key=KEY) except: kv = KeyValue(key=KEY) kv.value = VERSION kv.save() except Exception, e: #import sys, traceback #traceback.print_exc(file=sys.stdout) pass finally: cursor.close() f.close()