Skip to content

Commit fce1154

Browse files
committed
initial commit
1 parent 272fe17 commit fce1154

File tree

13 files changed

+224
-0
lines changed

13 files changed

+224
-0
lines changed

.gitignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
*.log
2+
*.pot
3+
local_settings.py
4+
settings_local.py
5+
*.py[co]
6+
7+
# Packages
8+
*.egg
9+
*.egg-info
10+
dist
11+
build
12+
eggs
13+
parts
14+
bin
15+
develop-eggs
16+
.installed.cfg
17+
18+
# Installer logs
19+
pip-log.txt
20+
21+
# Unit test / coverage reports
22+
.coverage
23+
.tox
24+
*.pydevproject
25+
.project
26+
.metadata
27+
bin/**
28+
tmp/**
29+
tmp/**/*
30+
*.tmp
31+
*.bak
32+
*.swp
33+
*~.nib
34+
local.properties
35+
.classpath
36+
.settings/
37+
.loadpath
38+
39+
# CDT-specific
40+
.cproject

LICENSE.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) City Live nv and individual contributors.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice,
8+
this list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above copyright
11+
notice, this list of conditions and the following disclaimer in the
12+
documentation and/or other materials provided with the distribution.
13+
14+
3. Neither the name of City Live nor the names of its contributors may be used
15+
to endorse or promote products derived from this software without
16+
specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

keyvaluestore/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import datetime
2+
import os
3+
import subprocess
4+
5+
def get_git_version():
6+
git_dir = os.path.abspath(
7+
os.path.join(
8+
os.path.abspath(os.path.dirname(__file__)),
9+
'..',
10+
'.git'
11+
)
12+
)
13+
try:
14+
# Python 2.7 has subprocess.check_output
15+
# 2.6 needs this longer version
16+
git_info = subprocess.Popen(['git', '--git-dir=%s' % git_dir, 'log', '--pretty=%ct %h', '-1'], stdout=subprocess.PIPE).communicate()[0].split()
17+
git_time = datetime.datetime.fromtimestamp(float(git_info[0]))
18+
except Exception:
19+
git_time = datetime.datetime.now()
20+
git_info = ('', '0000000')
21+
return git_time.strftime('%Y.%m.%d') + '.' + git_info[1]
22+
23+
__version__ = get_git_version()

keyvaluestore/admin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.contrib import admin
2+
3+
from keyvaluestore.models import KeyValueStore
4+
5+
class KeyValueStoreAdmin(admin.ModelAdmin):
6+
list_display = ('key', 'value')
7+
search_fields = ('key', 'value')
8+
admin.site.register(KeyValueStore, KeyValueStoreAdmin)

keyvaluestore/exceptions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
class KeyNotExistingException:
3+
def __init__(self, msg=None, form=None):
4+
if form is not None:
5+
msg = u''
6+
for k in form.errors.keys():
7+
for e in form.errors[k]:
8+
msg += u' ' + e
9+
self.msg = e
10+
else:
11+
self.msg = u'%s' % msg

keyvaluestore/managers.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from django.db import models
2+
from django.core.cache import cache
3+
from django.utils.translation import ugettext as _
4+
5+
from keyvaluestore.exceptions import KeyNotExistingException
6+
7+
class KeyValueStoreManager(models.Manager):
8+
def get_value_for_key(self, key):
9+
key = key.upper()
10+
cached = cache.get(key)
11+
12+
if not cached:
13+
try:
14+
obj = self.get(key=key)
15+
cache.set('kvs_%s' % (key,), obj.value)
16+
17+
return obj.value
18+
except:
19+
raise KeyNotExistingException(_(u"The request key '%s' could not be found." % (key,)))
20+
else:
21+
return cached
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# encoding: utf-8
2+
import datetime
3+
from south.db import db
4+
from south.v2 import SchemaMigration
5+
from django.db import models
6+
7+
class Migration(SchemaMigration):
8+
9+
def forwards(self, orm):
10+
11+
# Adding model 'KeyValueStore'
12+
db.create_table('keyvaluestore_keyvaluestore', (
13+
('key', self.gf('django.db.models.fields.CharField')(unique=True, max_length=200, primary_key=True, db_index=True)),
14+
('value', self.gf('django.db.models.fields.TextField')()),
15+
))
16+
db.send_create_signal('keyvaluestore', ['KeyValueStore'])
17+
18+
19+
def backwards(self, orm):
20+
21+
# Deleting model 'KeyValueStore'
22+
db.delete_table('keyvaluestore_keyvaluestore')
23+
24+
25+
models = {
26+
'keyvaluestore.keyvaluestore': {
27+
'Meta': {'object_name': 'KeyValueStore'},
28+
'key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '200', 'primary_key': 'True', 'db_index': 'True'}),
29+
'value': ('django.db.models.fields.TextField', [], {})
30+
}
31+
}
32+
33+
complete_apps = ['keyvaluestore']
1.68 KB
Binary file not shown.

keyvaluestore/migrations/__init__.py

Whitespace-only changes.
165 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)