Revision 69027b63
/dev/null | ||
---|---|---|
1 |
|
|
2 |
|
/dev/null | ||
---|---|---|
1 |
from .apispec import FSCrudAPI, FSCrudCallpoint |
|
2 |
|
|
3 |
API = FSCrudAPI |
|
4 |
Callpoint = FSCrudCallpoint |
|
5 |
|
/dev/null | ||
---|---|---|
1 |
""" |
|
2 |
This file demonstrates two different styles of tests (one doctest and one |
|
3 |
unittest). These will both pass when you run "manage.py test". |
|
4 |
|
|
5 |
Replace these with more appropriate tests for your application. |
|
6 |
""" |
|
7 |
|
|
8 |
from django.test import TestCase |
|
9 |
|
|
10 |
class SimpleTest(TestCase): |
|
11 |
def test_basic_addition(self): |
|
12 |
""" |
|
13 |
Tests that 1 + 1 always equals 2. |
|
14 |
""" |
|
15 |
self.failUnlessEqual(1 + 1, 2) |
|
16 |
|
|
17 |
__test__ = {"doctest": """ |
|
18 |
Another way to test that 1 + 1 is equal to 2. |
|
19 |
|
|
20 |
>>> 1 + 1 == 2 |
|
21 |
True |
|
22 |
"""} |
|
23 |
|
/dev/null | ||
---|---|---|
1 |
from django.conf.urls.defaults import * |
|
2 |
from views import quotaholder_0_2 |
|
3 |
|
|
4 |
# Uncomment the next two lines to enable the admin: |
|
5 |
# from django.contrib import admin |
|
6 |
# admin.autodiscover() |
|
7 |
|
|
8 |
urlpatterns = patterns('', |
|
9 |
# Example: |
|
10 |
# (r'^quota/', include('quota.foo.urls')), |
|
11 |
|
|
12 |
# Uncomment the admin/doc line below to enable admin documentation: |
|
13 |
# (r'^admin/doc/', include('django.contrib.admindocs.urls')), |
|
14 |
|
|
15 |
# Uncomment the next line to enable the admin: |
|
16 |
# (r'^admin/', include(admin.site.urls)), |
|
17 |
(r'^0.2/(?P<call_name>[_A-Za-z0-9]*)', quotaholder_0_2), |
|
18 |
) |
/dev/null | ||
---|---|---|
1 |
# Create your views here. |
|
2 |
|
|
3 |
from django.http import HttpResponse |
|
4 |
from django.db import transaction |
|
5 |
from quotaholder import QuotaholderException |
|
6 |
from quotaholder.controllers.django_controller import QuotaholderDjangoController |
|
7 |
|
|
8 |
import json |
|
9 |
|
|
10 |
_callpoint = FSCRUDCallpoint() |
|
11 |
|
|
12 |
def _get_body(request): |
|
13 |
body = request.raw_post_data |
|
14 |
if body is None: |
|
15 |
body = request.GET.get('body', None) |
|
16 |
return body |
|
17 |
|
|
18 |
|
|
19 |
@transaction.commit_on_success |
|
20 |
def fscrude_0_1(request, call_name=None): |
|
21 |
body = _get_body(request) |
|
22 |
try: |
|
23 |
body = _callpoint.make_call_from_json(call_name, body) |
|
24 |
status = 200 |
|
25 |
except QuotaholderException, e: |
|
26 |
status, body = _callpoint.http_exception(e) |
|
27 |
|
|
28 |
return HttpResponse(status=status, content=body) |
|
29 |
|
/dev/null | ||
---|---|---|
1 |
#!/usr/bin/python |
|
2 |
from django.core.management import execute_manager |
|
3 |
try: |
|
4 |
import settings # Assumed to be in the same directory. |
|
5 |
except ImportError: |
|
6 |
import sys |
|
7 |
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) |
|
8 |
sys.exit(1) |
|
9 |
|
|
10 |
if __name__ == "__main__": |
|
11 |
execute_manager(settings) |
/dev/null | ||
---|---|---|
1 |
from os.path import expanduser, exists |
|
2 |
from os import getenv, fsync, unlink |
|
3 |
from errno import ENOENT |
|
4 |
from shutil import move |
|
5 |
|
|
6 |
stripchars = '"\' ' |
|
7 |
|
|
8 |
_pvpath_default = getenv('PVDATA_PATH') |
|
9 |
if not _pvpath_default: |
|
10 |
_pvpath_default = expanduser('~/.pvdata') |
|
11 |
|
|
12 |
_pvpath = None |
|
13 |
_pvdict = None |
|
14 |
_pvdata_counter = 0 |
|
15 |
_pvdirty = 0 |
|
16 |
|
|
17 |
def _pvopen(pvpath=_pvpath_default): |
|
18 |
global _pvdict |
|
19 |
if _pvdict is not None: |
|
20 |
return _pvdict |
|
21 |
|
|
22 |
try: |
|
23 |
with open(pvpath) as f: |
|
24 |
pvdata = f.read() |
|
25 |
except IOError, e: |
|
26 |
if e.errno != ENOENT: |
|
27 |
m = "Cannot open pvdata file '%s'" % (pvpath,) |
|
28 |
raise ValueError(m, e) |
|
29 |
|
|
30 |
with open(pvpath, "w") as f: |
|
31 |
pass |
|
32 |
pvdata = '' |
|
33 |
|
|
34 |
global _pvpath |
|
35 |
_pvpath = pvpath |
|
36 |
|
|
37 |
pvdict = {} |
|
38 |
for line in pvdata.splitlines(): |
|
39 |
key, sep, val = line.partition('=') |
|
40 |
if not key or key[0] == '#': |
|
41 |
continue |
|
42 |
|
|
43 |
key = key.strip() |
|
44 |
val = val.strip() |
|
45 |
|
|
46 |
if len(key) > 1 and key[0] == "'" and key[-1] == "'": |
|
47 |
key = key[1:-1] |
|
48 |
|
|
49 |
if len(val) > 1 and val[0] == "'" and val[-1] == "'": |
|
50 |
val = val[1:-1] |
|
51 |
|
|
52 |
pvdict[key] = val |
|
53 |
|
|
54 |
_pvdict = pvdict |
|
55 |
return pvdict |
|
56 |
|
|
57 |
|
|
58 |
def pvsave(pvpath=None, force=0): |
|
59 |
|
|
60 |
if _pvdict is None or not (force or _pvdirty): |
|
61 |
return |
|
62 |
|
|
63 |
if pvpath is None: |
|
64 |
pvpath = _pvpath |
|
65 |
|
|
66 |
pvdata_list = [] |
|
67 |
append = pvdata_list.append |
|
68 |
|
|
69 |
for key, val in _pvdict.items(): |
|
70 |
if not key or '\n' in key or '\n' in val: |
|
71 |
continue |
|
72 |
|
|
73 |
if key[0] == ' ' or key[-1] == ' ': |
|
74 |
key = "'%s'" % (key,) |
|
75 |
|
|
76 |
if val[0] == ' ' or val[-1] == ' ': |
|
77 |
val = "'%s'" % (val,) |
|
78 |
|
|
79 |
append("%s = %s" % (key, val)) |
|
80 |
|
|
81 |
pvdata = '\n'.join(pvdata_list) + '\n' |
|
82 |
|
|
83 |
global _pvdata_counter |
|
84 |
|
|
85 |
while 1: |
|
86 |
pvpath_old = '%s.old.%d' % (pvpath, _pvdata_counter) |
|
87 |
if not exists(pvpath_old): |
|
88 |
break |
|
89 |
|
|
90 |
_pvdata_counter += 1 |
|
91 |
continue |
|
92 |
|
|
93 |
move(pvpath, pvpath_old) |
|
94 |
|
|
95 |
try: |
|
96 |
with open(pvpath, "w") as f: |
|
97 |
f.write(pvdata) |
|
98 |
f.flush() |
|
99 |
fsync(f.fileno()) |
|
100 |
except IOError, e: |
|
101 |
m = "Cannot open pvdata file '%s'" % (pvpath,) |
|
102 |
raise ValueError(m, e) |
|
103 |
|
|
104 |
unlink(pvpath_old) |
|
105 |
|
|
106 |
|
|
107 |
def getpv(key): |
|
108 |
pvdict = _pvopen() |
|
109 |
return pvdict[key] if key in pvdict else '' |
|
110 |
|
|
111 |
def setpv(key, val): |
|
112 |
pvdict = _pvopen() |
|
113 |
global _pvdirty |
|
114 |
_pvdirty = 1 |
|
115 |
pvdict[key] = val |
|
116 |
|
|
117 |
def delpv(key): |
|
118 |
pvdict = _pvopen() |
|
119 |
del pvdict[key] |
|
120 |
|
|
121 |
def savepv(key, val): |
|
122 |
setpv(key, val) |
|
123 |
pvsave() |
|
124 |
|
/dev/null | ||
---|---|---|
1 |
# Django settings for quota project. |
|
2 |
|
|
3 |
DEBUG = True |
|
4 |
TEMPLATE_DEBUG = DEBUG |
|
5 |
|
|
6 |
ADMINS = ( |
|
7 |
# ('Your Name', 'your_email@domain.com'), |
|
8 |
) |
|
9 |
|
|
10 |
MANAGERS = ADMINS |
|
11 |
|
|
12 |
from pvdata import getpv |
|
13 |
|
|
14 |
DATABASES = { |
|
15 |
'default': { |
|
16 |
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. |
|
17 |
'NAME': 'holder', # Or path to database file if using sqlite3. |
|
18 |
'USER': 'holder', # Not used with sqlite3. |
|
19 |
'PASSWORD': getpv('klapeto'), # Not used with sqlite3. |
|
20 |
'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3. |
|
21 |
'PORT': '5432', # Set to empty string for default. Not used with sqlite3. |
|
22 |
} |
|
23 |
} |
|
24 |
|
|
25 |
# Local time zone for this installation. Choices can be found here: |
|
26 |
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name |
|
27 |
# although not all choices may be available on all operating systems. |
|
28 |
# On Unix systems, a value of None will cause Django to use the same |
|
29 |
# timezone as the operating system. |
|
30 |
# If running in a Windows environment this must be set to the same as your |
|
31 |
# system time zone. |
|
32 |
TIME_ZONE = 'Europe/Athens' |
|
33 |
|
|
34 |
# Language code for this installation. All choices can be found here: |
|
35 |
# http://www.i18nguy.com/unicode/language-identifiers.html |
|
36 |
LANGUAGE_CODE = 'en-us' |
|
37 |
|
|
38 |
SITE_ID = 1 |
|
39 |
|
|
40 |
# If you set this to False, Django will make some optimizations so as not |
|
41 |
# to load the internationalization machinery. |
|
42 |
USE_I18N = True |
|
43 |
|
|
44 |
# If you set this to False, Django will not format dates, numbers and |
|
45 |
# calendars according to the current locale |
|
46 |
USE_L10N = True |
|
47 |
|
|
48 |
# Absolute path to the directory that holds media. |
|
49 |
# Example: "/home/media/media.lawrence.com/" |
|
50 |
MEDIA_ROOT = '' |
|
51 |
|
|
52 |
# URL that handles the media served from MEDIA_ROOT. Make sure to use a |
|
53 |
# trailing slash if there is a path component (optional in other cases). |
|
54 |
# Examples: "http://media.lawrence.com", "http://example.com/media/" |
|
55 |
MEDIA_URL = '' |
|
56 |
|
|
57 |
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a |
|
58 |
# trailing slash. |
|
59 |
# Examples: "http://foo.com/media/", "/media/". |
|
60 |
ADMIN_MEDIA_PREFIX = '/media/' |
|
61 |
|
|
62 |
# Make this unique, and don't share it with anybody. |
|
63 |
SECRET_KEY = 'ee=*x%x6sp=hcm7j4zzkvpam27g*7*d59fca-q!azaqma!jx*+' |
|
64 |
|
|
65 |
# List of callables that know how to import templates from various sources. |
|
66 |
TEMPLATE_LOADERS = ( |
|
67 |
'django.template.loaders.filesystem.Loader', |
|
68 |
'django.template.loaders.app_directories.Loader', |
|
69 |
# 'django.template.loaders.eggs.Loader', |
|
70 |
) |
|
71 |
|
|
72 |
MIDDLEWARE_CLASSES = ( |
|
73 |
'django.middleware.common.CommonMiddleware', |
|
74 |
#'django.middleware.transaction.TransactionMiddleware', |
|
75 |
#'django.contrib.sessions.middleware.SessionMiddleware', |
|
76 |
#'django.middleware.csrf.CsrfViewMiddleware', |
|
77 |
#'django.contrib.auth.middleware.AuthenticationMiddleware', |
|
78 |
#'django.contrib.messages.middleware.MessageMiddleware', |
|
79 |
) |
|
80 |
|
|
81 |
ROOT_URLCONF = 'quotaholder.apps.fscrud_django.urls' |
|
82 |
|
|
83 |
TEMPLATE_DIRS = ( |
|
84 |
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". |
|
85 |
# Always use forward slashes, even on Windows. |
|
86 |
# Don't forget to use absolute paths, not relative paths. |
|
87 |
) |
|
88 |
|
|
89 |
INSTALLED_APPS = ( |
|
90 |
#'django.contrib.auth', |
|
91 |
'django.contrib.contenttypes', |
|
92 |
#'django.contrib.sessions', |
|
93 |
#'django.contrib.sites', |
|
94 |
#'django.contrib.messages', |
|
95 |
'quotaholder.backends.django_backend', |
|
96 |
'quotaholder.apps.fscrud_django.fscrud_app', |
|
97 |
# Uncomment the next line to enable the admin: |
|
98 |
# 'django.contrib.admin', |
|
99 |
# Uncomment the next line to enable admin documentation: |
|
100 |
# 'django.contrib.admindocs', |
|
101 |
) |
/dev/null | ||
---|---|---|
1 |
from django.conf.urls.defaults import * |
|
2 |
|
|
3 |
# Uncomment the next two lines to enable the admin: |
|
4 |
# from django.contrib import admin |
|
5 |
# admin.autodiscover() |
|
6 |
|
|
7 |
urlpatterns = patterns('', |
|
8 |
# Example: |
|
9 |
# (r'^quota/', include('quota.foo.urls')), |
|
10 |
|
|
11 |
# Uncomment the admin/doc line below to enable admin documentation: |
|
12 |
# (r'^admin/doc/', include('django.contrib.admindocs.urls')), |
|
13 |
|
|
14 |
# Uncomment the next line to enable the admin: |
|
15 |
# (r'^admin/', include(admin.site.urls)), |
|
16 |
(r'^holder-', include('quotaholder_app.urls')), |
|
17 |
) |
Also available in: Unified diff