diff --git a/Changelog b/Changelog
new file mode 100644
index 0000000..e69de29
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..8b42070
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,2 @@
+include README Changelog
+include distribute_setup.py
diff --git a/README b/README
new file mode 100644
index 0000000..e69de29
diff --git a/distribute_setup.py b/distribute_setup.py
new file mode 100644
index 0000000..10d6684
--- /dev/null
+++ b/distribute_setup.py
@@ -0,0 +1,485 @@
+#!python
+"""Bootstrap distribute installation
+
+If you want to use setuptools in your package's setup.py, just include this
+file in the same directory with it, and add this to the top of your setup.py::
+
+ from distribute_setup import use_setuptools
+ use_setuptools()
+
+If you want to require a specific version of setuptools, set a download
+mirror, or use an alternate download directory, you can do so by supplying
+the appropriate options to ``use_setuptools()``.
+
+This file can also be run as a script to install or upgrade setuptools.
+"""
+import os
+import sys
+import time
+import fnmatch
+import tempfile
+import tarfile
+from distutils import log
+
+try:
+ from site import USER_SITE
+except ImportError:
+ USER_SITE = None
+
+try:
+ import subprocess
+
+ def _python_cmd(*args):
+ args = (sys.executable,) + args
+ return subprocess.call(args) == 0
+
+except ImportError:
+ # will be used for python 2.3
+ def _python_cmd(*args):
+ args = (sys.executable,) + args
+ # quoting arguments if windows
+ if sys.platform == 'win32':
+ def quote(arg):
+ if ' ' in arg:
+ return '"%s"' % arg
+ return arg
+ args = [quote(arg) for arg in args]
+ return os.spawnl(os.P_WAIT, sys.executable, *args) == 0
+
+DEFAULT_VERSION = "0.6.10"
+DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/"
+SETUPTOOLS_FAKED_VERSION = "0.6c11"
+
+SETUPTOOLS_PKG_INFO = """\
+Metadata-Version: 1.0
+Name: setuptools
+Version: %s
+Summary: xxxx
+Home-page: xxx
+Author: xxx
+Author-email: xxx
+License: xxx
+Description: xxx
+""" % SETUPTOOLS_FAKED_VERSION
+
+
+def _install(tarball):
+ # extracting the tarball
+ tmpdir = tempfile.mkdtemp()
+ log.warn('Extracting in %s', tmpdir)
+ old_wd = os.getcwd()
+ try:
+ os.chdir(tmpdir)
+ tar = tarfile.open(tarball)
+ _extractall(tar)
+ tar.close()
+
+ # going in the directory
+ subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
+ os.chdir(subdir)
+ log.warn('Now working in %s', subdir)
+
+ # installing
+ log.warn('Installing Distribute')
+ if not _python_cmd('setup.py', 'install'):
+ log.warn('Something went wrong during the installation.')
+ log.warn('See the error message above.')
+ finally:
+ os.chdir(old_wd)
+
+
+def _build_egg(egg, tarball, to_dir):
+ # extracting the tarball
+ tmpdir = tempfile.mkdtemp()
+ log.warn('Extracting in %s', tmpdir)
+ old_wd = os.getcwd()
+ try:
+ os.chdir(tmpdir)
+ tar = tarfile.open(tarball)
+ _extractall(tar)
+ tar.close()
+
+ # going in the directory
+ subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
+ os.chdir(subdir)
+ log.warn('Now working in %s', subdir)
+
+ # building an egg
+ log.warn('Building a Distribute egg in %s', to_dir)
+ _python_cmd('setup.py', '-q', 'bdist_egg', '--dist-dir', to_dir)
+
+ finally:
+ os.chdir(old_wd)
+ # returning the result
+ log.warn(egg)
+ if not os.path.exists(egg):
+ raise IOError('Could not build the egg.')
+
+
+def _do_download(version, download_base, to_dir, download_delay):
+ egg = os.path.join(to_dir, 'distribute-%s-py%d.%d.egg'
+ % (version, sys.version_info[0], sys.version_info[1]))
+ if not os.path.exists(egg):
+ tarball = download_setuptools(version, download_base,
+ to_dir, download_delay)
+ _build_egg(egg, tarball, to_dir)
+ sys.path.insert(0, egg)
+ import setuptools
+ setuptools.bootstrap_install_from = egg
+
+
+def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
+ to_dir=os.curdir, download_delay=15, no_fake=True):
+ # making sure we use the absolute path
+ to_dir = os.path.abspath(to_dir)
+ was_imported = 'pkg_resources' in sys.modules or \
+ 'setuptools' in sys.modules
+ try:
+ try:
+ import pkg_resources
+ if not hasattr(pkg_resources, '_distribute'):
+ if not no_fake:
+ _fake_setuptools()
+ raise ImportError
+ except ImportError:
+ return _do_download(version, download_base, to_dir, download_delay)
+ try:
+ pkg_resources.require("distribute>="+version)
+ return
+ except pkg_resources.VersionConflict:
+ e = sys.exc_info()[1]
+ if was_imported:
+ sys.stderr.write(
+ "The required version of distribute (>=%s) is not available,\n"
+ "and can't be installed while this script is running. Please\n"
+ "install a more recent version first, using\n"
+ "'easy_install -U distribute'."
+ "\n\n(Currently using %r)\n" % (version, e.args[0]))
+ sys.exit(2)
+ else:
+ del pkg_resources, sys.modules['pkg_resources'] # reload ok
+ return _do_download(version, download_base, to_dir,
+ download_delay)
+ except pkg_resources.DistributionNotFound:
+ return _do_download(version, download_base, to_dir,
+ download_delay)
+ finally:
+ if not no_fake:
+ _create_fake_setuptools_pkg_info(to_dir)
+
+def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
+ to_dir=os.curdir, delay=15):
+ """Download distribute from a specified location and return its filename
+
+ `version` should be a valid distribute version number that is available
+ as an egg for download under the `download_base` URL (which should end
+ with a '/'). `to_dir` is the directory where the egg will be downloaded.
+ `delay` is the number of seconds to pause before an actual download
+ attempt.
+ """
+ # making sure we use the absolute path
+ to_dir = os.path.abspath(to_dir)
+ try:
+ from urllib.request import urlopen
+ except ImportError:
+ from urllib2 import urlopen
+ tgz_name = "distribute-%s.tar.gz" % version
+ url = download_base + tgz_name
+ saveto = os.path.join(to_dir, tgz_name)
+ src = dst = None
+ if not os.path.exists(saveto): # Avoid repeated downloads
+ try:
+ log.warn("Downloading %s", url)
+ src = urlopen(url)
+ # Read/write all in one block, so we don't create a corrupt file
+ # if the download is interrupted.
+ data = src.read()
+ dst = open(saveto, "wb")
+ dst.write(data)
+ finally:
+ if src:
+ src.close()
+ if dst:
+ dst.close()
+ return os.path.realpath(saveto)
+
+def _no_sandbox(function):
+ def __no_sandbox(*args, **kw):
+ try:
+ from setuptools.sandbox import DirectorySandbox
+ if not hasattr(DirectorySandbox, '_old'):
+ def violation(*args):
+ pass
+ DirectorySandbox._old = DirectorySandbox._violation
+ DirectorySandbox._violation = violation
+ patched = True
+ else:
+ patched = False
+ except ImportError:
+ patched = False
+
+ try:
+ return function(*args, **kw)
+ finally:
+ if patched:
+ DirectorySandbox._violation = DirectorySandbox._old
+ del DirectorySandbox._old
+
+ return __no_sandbox
+
+def _patch_file(path, content):
+ """Will backup the file then patch it"""
+ existing_content = open(path).read()
+ if existing_content == content:
+ # already patched
+ log.warn('Already patched.')
+ return False
+ log.warn('Patching...')
+ _rename_path(path)
+ f = open(path, 'w')
+ try:
+ f.write(content)
+ finally:
+ f.close()
+ return True
+
+_patch_file = _no_sandbox(_patch_file)
+
+def _same_content(path, content):
+ return open(path).read() == content
+
+def _rename_path(path):
+ new_name = path + '.OLD.%s' % time.time()
+ log.warn('Renaming %s into %s', path, new_name)
+ os.rename(path, new_name)
+ return new_name
+
+def _remove_flat_installation(placeholder):
+ if not os.path.isdir(placeholder):
+ log.warn('Unkown installation at %s', placeholder)
+ return False
+ found = False
+ for file in os.listdir(placeholder):
+ if fnmatch.fnmatch(file, 'setuptools*.egg-info'):
+ found = True
+ break
+ if not found:
+ log.warn('Could not locate setuptools*.egg-info')
+ return
+
+ log.warn('Removing elements out of the way...')
+ pkg_info = os.path.join(placeholder, file)
+ if os.path.isdir(pkg_info):
+ patched = _patch_egg_dir(pkg_info)
+ else:
+ patched = _patch_file(pkg_info, SETUPTOOLS_PKG_INFO)
+
+ if not patched:
+ log.warn('%s already patched.', pkg_info)
+ return False
+ # now let's move the files out of the way
+ for element in ('setuptools', 'pkg_resources.py', 'site.py'):
+ element = os.path.join(placeholder, element)
+ if os.path.exists(element):
+ _rename_path(element)
+ else:
+ log.warn('Could not find the %s element of the '
+ 'Setuptools distribution', element)
+ return True
+
+_remove_flat_installation = _no_sandbox(_remove_flat_installation)
+
+def _after_install(dist):
+ log.warn('After install bootstrap.')
+ placeholder = dist.get_command_obj('install').install_purelib
+ _create_fake_setuptools_pkg_info(placeholder)
+
+def _create_fake_setuptools_pkg_info(placeholder):
+ if not placeholder or not os.path.exists(placeholder):
+ log.warn('Could not find the install location')
+ return
+ pyver = '%s.%s' % (sys.version_info[0], sys.version_info[1])
+ setuptools_file = 'setuptools-%s-py%s.egg-info' % \
+ (SETUPTOOLS_FAKED_VERSION, pyver)
+ pkg_info = os.path.join(placeholder, setuptools_file)
+ if os.path.exists(pkg_info):
+ log.warn('%s already exists', pkg_info)
+ return
+
+ log.warn('Creating %s', pkg_info)
+ f = open(pkg_info, 'w')
+ try:
+ f.write(SETUPTOOLS_PKG_INFO)
+ finally:
+ f.close()
+
+ pth_file = os.path.join(placeholder, 'setuptools.pth')
+ log.warn('Creating %s', pth_file)
+ f = open(pth_file, 'w')
+ try:
+ f.write(os.path.join(os.curdir, setuptools_file))
+ finally:
+ f.close()
+
+_create_fake_setuptools_pkg_info = _no_sandbox(_create_fake_setuptools_pkg_info)
+
+def _patch_egg_dir(path):
+ # let's check if it's already patched
+ pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')
+ if os.path.exists(pkg_info):
+ if _same_content(pkg_info, SETUPTOOLS_PKG_INFO):
+ log.warn('%s already patched.', pkg_info)
+ return False
+ _rename_path(path)
+ os.mkdir(path)
+ os.mkdir(os.path.join(path, 'EGG-INFO'))
+ pkg_info = os.path.join(path, 'EGG-INFO', 'PKG-INFO')
+ f = open(pkg_info, 'w')
+ try:
+ f.write(SETUPTOOLS_PKG_INFO)
+ finally:
+ f.close()
+ return True
+
+_patch_egg_dir = _no_sandbox(_patch_egg_dir)
+
+def _before_install():
+ log.warn('Before install bootstrap.')
+ _fake_setuptools()
+
+
+def _under_prefix(location):
+ if 'install' not in sys.argv:
+ return True
+ args = sys.argv[sys.argv.index('install')+1:]
+ for index, arg in enumerate(args):
+ for option in ('--root', '--prefix'):
+ if arg.startswith('%s=' % option):
+ top_dir = arg.split('root=')[-1]
+ return location.startswith(top_dir)
+ elif arg == option:
+ if len(args) > index:
+ top_dir = args[index+1]
+ return location.startswith(top_dir)
+ if arg == '--user' and USER_SITE is not None:
+ return location.startswith(USER_SITE)
+ return True
+
+
+def _fake_setuptools():
+ log.warn('Scanning installed packages')
+ try:
+ import pkg_resources
+ except ImportError:
+ # we're cool
+ log.warn('Setuptools or Distribute does not seem to be installed.')
+ return
+ ws = pkg_resources.working_set
+ try:
+ setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools',
+ replacement=False))
+ except TypeError:
+ # old distribute API
+ setuptools_dist = ws.find(pkg_resources.Requirement.parse('setuptools'))
+
+ if setuptools_dist is None:
+ log.warn('No setuptools distribution found')
+ return
+ # detecting if it was already faked
+ setuptools_location = setuptools_dist.location
+ log.warn('Setuptools installation detected at %s', setuptools_location)
+
+ # if --root or --preix was provided, and if
+ # setuptools is not located in them, we don't patch it
+ if not _under_prefix(setuptools_location):
+ log.warn('Not patching, --root or --prefix is installing Distribute'
+ ' in another location')
+ return
+
+ # let's see if its an egg
+ if not setuptools_location.endswith('.egg'):
+ log.warn('Non-egg installation')
+ res = _remove_flat_installation(setuptools_location)
+ if not res:
+ return
+ else:
+ log.warn('Egg installation')
+ pkg_info = os.path.join(setuptools_location, 'EGG-INFO', 'PKG-INFO')
+ if (os.path.exists(pkg_info) and
+ _same_content(pkg_info, SETUPTOOLS_PKG_INFO)):
+ log.warn('Already patched.')
+ return
+ log.warn('Patching...')
+ # let's create a fake egg replacing setuptools one
+ res = _patch_egg_dir(setuptools_location)
+ if not res:
+ return
+ log.warn('Patched done.')
+ _relaunch()
+
+
+def _relaunch():
+ log.warn('Relaunching...')
+ # we have to relaunch the process
+ # pip marker to avoid a relaunch bug
+ if sys.argv[:3] == ['-c', 'install', '--single-version-externally-managed']:
+ sys.argv[0] = 'setup.py'
+ args = [sys.executable] + sys.argv
+ sys.exit(subprocess.call(args))
+
+
+def _extractall(self, path=".", members=None):
+ """Extract all members from the archive to the current working
+ directory and set owner, modification time and permissions on
+ directories afterwards. `path' specifies a different directory
+ to extract to. `members' is optional and must be a subset of the
+ list returned by getmembers().
+ """
+ import copy
+ import operator
+ from tarfile import ExtractError
+ directories = []
+
+ if members is None:
+ members = self
+
+ for tarinfo in members:
+ if tarinfo.isdir():
+ # Extract directories with a safe mode.
+ directories.append(tarinfo)
+ tarinfo = copy.copy(tarinfo)
+ tarinfo.mode = 448 # decimal for oct 0700
+ self.extract(tarinfo, path)
+
+ # Reverse sort directories.
+ if sys.version_info < (2, 4):
+ def sorter(dir1, dir2):
+ return cmp(dir1.name, dir2.name)
+ directories.sort(sorter)
+ directories.reverse()
+ else:
+ directories.sort(key=operator.attrgetter('name'), reverse=True)
+
+ # Set correct owner, mtime and filemode on directories.
+ for tarinfo in directories:
+ dirpath = os.path.join(path, tarinfo.name)
+ try:
+ self.chown(tarinfo, dirpath)
+ self.utime(tarinfo, dirpath)
+ self.chmod(tarinfo, dirpath)
+ except ExtractError:
+ e = sys.exc_info()[1]
+ if self.errorlevel > 1:
+ raise
+ else:
+ self._dbg(1, "tarfile: %s" % e)
+
+
+def main(argv, version=DEFAULT_VERSION):
+ """Install or upgrade setuptools and EasyInstall"""
+ tarball = download_setuptools()
+ _install(tarball)
+
+
+if __name__ == '__main__':
+ main(sys.argv[1:])
diff --git a/examples/keda.gunicorn b/examples/keda.gunicorn
new file mode 100644
index 0000000..aff6da5
--- /dev/null
+++ b/examples/keda.gunicorn
@@ -0,0 +1,19 @@
+CONFIG = {
+ 'mode': 'django',
+ 'environment': {
+ 'PYTHONPATH': '/root/',
+ 'DJANGO_SETTINGS_MODULE': 'keda.settings',
+ },
+ 'working_dir': '/root/keda/',
+ 'user': 'root',
+ 'group': 'root',
+ 'args': (
+ '--bind=127.0.0.1:8888',
+ '--workers=1',
+ # '--worker-class=egg:gunicorn#sync',
+ # '--timeout=30',
+ '--debug',
+ '--log-level=debug',
+ ),
+}
+
diff --git a/examples/keda.nginx b/examples/keda.nginx
new file mode 100644
index 0000000..a107c8c
--- /dev/null
+++ b/examples/keda.nginx
@@ -0,0 +1,46 @@
+server {
+ listen 80;
+ server_name 83.212.117.60;
+ root /root/keda/;
+ access_log /var/log/nginx/domain-access.log;
+
+ #rewrite ^/admin(.*) https://83.212.117.60/admin$1 permanent;
+
+ location /static {
+ root /usr/share/pyshared/django/contrib/admin;
+ }
+ location /media {
+ root /root/keda/reception;
+ }
+ location / {
+ proxy_pass_header Server;
+ proxy_set_header Host $http_host;
+ proxy_redirect off;
+ proxy_set_header X-Forwarded-For $remote_addr;
+ proxy_set_header X-Scheme $scheme;
+ proxy_connect_timeout 10;
+ proxy_read_timeout 10;
+ proxy_pass http://127.0.0.1:8888/;
+ }
+
+}
+server {
+ listen 443;
+ server_name 83.212.117.60;
+
+ ssl on;
+ ssl_certificate /root/certificate.pem;
+ ssl_certificate_key /root/key.pem;
+
+ ssl_session_timeout 5m;
+
+ ssl_protocols SSLv3 TLSv1;
+ ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
+ ssl_prefer_server_ciphers on;
+
+ location / {
+ root html;
+ index index.html index.htm;
+ }
+}
+
diff --git a/reception/nested_inlines/__init__.py b/nested_inlines/__init__.py
similarity index 100%
rename from reception/nested_inlines/__init__.py
rename to nested_inlines/__init__.py
diff --git a/reception/nested_inlines/admin.py b/nested_inlines/admin.py
similarity index 100%
rename from reception/nested_inlines/admin.py
rename to nested_inlines/admin.py
diff --git a/reception/nested_inlines/forms.py b/nested_inlines/forms.py
similarity index 100%
rename from reception/nested_inlines/forms.py
rename to nested_inlines/forms.py
diff --git a/reception/nested_inlines/helpers.py b/nested_inlines/helpers.py
similarity index 100%
rename from reception/nested_inlines/helpers.py
rename to nested_inlines/helpers.py
diff --git a/reception/nested_inlines/models.py b/nested_inlines/models.py
similarity index 100%
rename from reception/nested_inlines/models.py
rename to nested_inlines/models.py
diff --git a/reception/nested_inlines/static/admin/css/nested.css b/nested_inlines/static/admin/css/nested.css
similarity index 100%
rename from reception/nested_inlines/static/admin/css/nested.css
rename to nested_inlines/static/admin/css/nested.css
diff --git a/reception/nested_inlines/static/admin/js/inlines.js b/nested_inlines/static/admin/js/inlines.js
similarity index 100%
rename from reception/nested_inlines/static/admin/js/inlines.js
rename to nested_inlines/static/admin/js/inlines.js
diff --git a/reception/nested_inlines/static/admin/js/inlines.min.js b/nested_inlines/static/admin/js/inlines.min.js
similarity index 100%
rename from reception/nested_inlines/static/admin/js/inlines.min.js
rename to nested_inlines/static/admin/js/inlines.min.js
diff --git a/reception/nested_inlines/static/admin/js/nested.js b/nested_inlines/static/admin/js/nested.js
similarity index 100%
rename from reception/nested_inlines/static/admin/js/nested.js
rename to nested_inlines/static/admin/js/nested.js
diff --git a/reception/nested_inlines/templates/admin/edit_inline/stacked.html b/nested_inlines/templates/admin/edit_inline/stacked.html
similarity index 100%
rename from reception/nested_inlines/templates/admin/edit_inline/stacked.html
rename to nested_inlines/templates/admin/edit_inline/stacked.html
diff --git a/reception/nested_inlines/templates/admin/edit_inline/tabular.html b/nested_inlines/templates/admin/edit_inline/tabular.html
similarity index 100%
rename from reception/nested_inlines/templates/admin/edit_inline/tabular.html
rename to nested_inlines/templates/admin/edit_inline/tabular.html
diff --git a/reception/nested_inlines/views.py b/nested_inlines/views.py
similarity index 100%
rename from reception/nested_inlines/views.py
rename to nested_inlines/views.py
diff --git a/reception/admin.py b/reception/admin.py
index 74fa69f..3b7cdca 100644
--- a/reception/admin.py
+++ b/reception/admin.py
@@ -1,5 +1,5 @@
from django.contrib import admin
-from keda.reception.nested_inlines.admin import NestedModelAdmin, NestedStackedInline, NestedTabularInline
+from nested_inlines.admin import NestedModelAdmin, NestedStackedInline, NestedTabularInline
from keda.reception.models import *
class RelativeInline(admin.TabularInline):
diff --git a/reception/views.py b/reception/views.py
index 60f00ef..2c8336d 100644
--- a/reception/views.py
+++ b/reception/views.py
@@ -1 +1,402 @@
-# Create your views here.
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+from django.http import *
+import datetime
+from django import template
+from django.utils import simplejson
+from django.conf import settings
+from django.template.loader import get_template
+from django.template import Context, RequestContext
+from django.forms.models import modelformset_factory
+from django.forms.models import inlineformset_factory
+from django.shortcuts import render_to_response
+from reception.models import *
+from django.db.models import Q
+from django.core.context_processors import csrf
+from django import forms
+from itertools import chain
+
+
+def home(request):
+ date = datetime.date.today()
+ now = datetime.datetime.now()
+ return render_to_response("welcome.html", {"now" : now,"date": date}, context_instance=RequestContext(request))
+
+
+def display_meta(request):
+ values = request.META.items()
+ values.sort()
+ html = []
+ for k, v in values:
+ html.append('
%s | %s |
' % (k, v))
+ return HttpResponse('' % '\n'.join(html))
+
+
+def value2id(value):
+ if value:
+ try:
+ return int(value)
+ except ValueError:
+ pass
+
+ return value
+
+
+def id_from_request(qd, name):
+ return value2id(qd.get(name))
+
+
+def check_period(avail, check_in, check_out):
+ err = None
+ ret = []
+ if (check_out and check_out <= check_in):
+ err = "ERROR: Check-out before Check-in!!!"
+ else:
+ for a in avail:
+ ok = True
+ for r in a.reservations.all():
+ if r.status in ("CONFIRMED", "PENDING", "UNKNOWN") and r.inside(check_in, check_out):
+ ok = False
+ break
+ if ok:
+ ret.append(a)
+
+ return (ret, err)
+
+
+def availability(request):
+ period, start, end = get_start_end(request)
+ area = request.GET.get("area")
+ category = id_from_request(request.GET, "category")
+ damaged = request.GET.get("damaged", False)
+
+ avail = Appartment.objects.all()
+ if area:
+ avail = avail.filter(area=area)
+
+ if damaged:
+ avail = avail.exclude(damages__fixed=False)
+
+ if category:
+ avail = avail.filter(category=category)
+
+ date_errors = None
+ avail, date_errors = check_period(avail, start, end)
+ avail = sorted(avail, key=lambda a: (a.area, int(a.no)))
+
+ ctx = {
+ "period": period,
+ "start": start,
+ "end": end,
+ "periods": Period.objects.all(),
+ "date_errors": date_errors,
+ "area": area,
+ "areas": Appartment.AREAS,
+ "category": category,
+ "categories": Category.objects.values(),
+ "damaged": damaged,
+ "avail": avail,
+ }
+ return render_to_response("availability.html", ctx, context_instance=RequestContext(request))
+
+
+def appartments(request):
+ period, start, end = get_start_end(request)
+ area = request.GET.get("area")
+ category = id_from_request(request.GET, "category")
+ damaged = request.GET.get("damaged", False)
+
+ appartments = Appartment.objects.all()
+ if area:
+ appartments = appartments.filter(area=area)
+
+ if damaged:
+ appartments = appartments.exclude(damages__fixed=False)
+
+ if category:
+ appartments = appartments.filter(category=category)
+
+ appartments = sorted(appartments, key=lambda a: (a.area, int(a.no)))
+ appres = []
+ for a in appartments:
+ reserved = False
+ for r in a.reservations.all():
+ if r.status in ("CONFIRMED", "PENDING", "UNKNOWN") and r.inside(start, end):
+ reserved = True
+ appres.append((a, r))
+ if not reserved:
+ appres.append((a, None))
+
+ ctx = {
+ "period": period,
+ "start": start,
+ "end": end,
+ "periods": Period.objects.all(),
+ "areas": Appartment.AREAS,
+ "categories": Category.objects.values(),
+ "appartments": appartments,
+ "appres": appres,
+ }
+ return render_to_response("appartments.html", ctx, context_instance=RequestContext(request))
+
+
+def parousiologio(request):
+ staff = Staff.objects.all().order_by("rank__level", "extra", "-surname").reverse()
+ ctx = {
+ "date": datetime.date.today(),
+ "staff": staff,
+ }
+ return render_to_response("parousiologio.html", ctx, context_instance=RequestContext(request))
+
+
+def get_datetime(value):
+ if value:
+ y, m, d = map(int, value.split("-"))
+ return datetime.date(y, m, d)
+ else:
+ return datetime.date.today()
+
+def get_start_end(request):
+ period = id_from_request(request.GET, "period")
+ start = request.GET.get("start", None)
+ end = request.GET.get("end", None)
+ if period:
+ period = Period.objects.get(id=period)
+ start = period.start
+ end = period.end
+ elif start and end:
+ start = get_datetime(start)
+ end = get_datetime(end)
+ else:
+ start = get_datetime(start)
+ end = start + datetime.timedelta(days=1)
+
+ return period, start, end
+
+def info(request):
+ period, start, end = get_start_end(request)
+ rtype = request.GET.get("rtype", None)
+ status = request.GET.get("status", None)
+ reservations = Reservation.objects.all()
+ if rtype:
+ reservations = reservations.filter(res_type=rtype)
+ if status:
+ reservations = reservations.filter(status=status)
+ reservations = filter(lambda x: x.inside(start, end), reservations)
+ reservations = Reservation.objects.filter(id__in=[r.id for r in reservations])
+ reservations = reservations.all().prefetch_related(
+ "owner__rank",
+ "owner__relatives",
+ "owner__contacts",
+ "owner__vehicles",
+ "appartment",
+ "receipts")
+ reservations = sorted(reservations, key=lambda x: x.owner.surname)
+ ctx = {
+ "period": period,
+ "start": start,
+ "end": end,
+ "rtype": rtype,
+ "status": status,
+ "rtypes": Reservation.RESERVATION_TYPES,
+ "statuses": Reservation.STATUSES,
+ "periods": Period.objects.all(),
+ "reservations": reservations,
+ }
+ return render_to_response("info.html", ctx, context_instance=RequestContext(request))
+
+def reservations(request):
+
+ period, start, end = get_start_end(request)
+ rtype = request.GET.get("rtype", None)
+ status = request.GET.get("status", None)
+ reservations = Reservation.objects.all()
+ if rtype:
+ reservations = reservations.filter(res_type=rtype)
+ if status:
+ reservations = reservations.filter(status=status)
+
+ reservations = filter(lambda x: x.inside(start, end), reservations)
+ reservations = Reservation.objects.filter(id__in=[r.id for r in reservations])
+ reservations = reservations.prefetch_related("owner", "appartment", "receipts")
+ reservations = sorted(reservations, key=lambda x: x.owner.surname)
+ ctx = {
+ "period": period,
+ "start": start,
+ "end": end,
+ "rtype": rtype,
+ "status": status,
+ "rtypes": Reservation.RESERVATION_TYPES,
+ "statuses": Reservation.STATUSES,
+ "periods": Period.objects.all(),
+ "reservations": reservations,
+ }
+ return render_to_response("reservations.html", ctx, context_instance=RequestContext(request))
+
+def logistic(request):
+
+ period, start, end = get_start_end(request)
+ rtype = request.GET.get("rtype", None)
+ status = request.GET.get("status", None)
+ receipt_type = request.GET.get("receipt_type", None)
+ first = request.GET.get("first", None)
+ last = request.GET.get("last", None)
+ receipts = Receipt.objects.all().order_by("no")
+ if rtype:
+ receipts = receipts.filter(reservation__res_type=rtype)
+ if receipt_type:
+ receipts = receipts.filter(rtype=receipt_type)
+ if status:
+ receipts = receipts.filter(reservation__status=status)
+ if first:
+ receipts = [r for r in receipts if r.inside(first, last)]
+ else:
+ receipts = [r for r in receipts if r.reservation.inside(start, end)]
+
+ l = lambda x: [r.euro for r in x]
+ ctx = {
+ "period": period,
+ "start": start,
+ "end": end,
+ "rtype": rtype,
+ "status": status,
+ "sum": sum(l(receipts)),
+ "periods": Period.objects.all(),
+ "receipts": receipts,
+ "rtypes": Reservation.RESERVATION_TYPES,
+ "statuses": Reservation.STATUSES,
+ "receipt_types": Receipt.RECEIPT_TYPES,
+ "receipt_type": receipt_type,
+ }
+ return render_to_response("logistic.html", ctx, context_instance=RequestContext(request))
+
+def th(request):
+
+ period, start, end = get_start_end(request)
+ reservations = Reservation.objects.filter(status="CONFIRMED", telephone=True)
+ reservations = [r for r in reservations if r.inside(start, end)]
+ reservations = sorted(reservations, key=lambda r: (r.appartment.area, int(r.appartment.no)) if r.appartment else None)
+
+ ctx = {
+ "period": period,
+ "start": start,
+ "end": end,
+ "periods": Period.objects.all(),
+ "reservations": reservations,
+ }
+ return render_to_response("th.html", ctx, context_instance=RequestContext(request))
+
+def damages(request):
+
+ date = datetime.date.today()
+ damages = Damage.objects.filter(fixed=False).order_by("tag")
+
+ ctx = {
+ "damages": damages,
+ "date":date,
+ }
+ return render_to_response("damages.html", ctx, context_instance=RequestContext(request))
+
+
+def gmap(request):
+ period, start, end = get_start_end(request)
+ url = "/gmap_data/?period="
+ if period:
+ url += str(period.id)
+ url += "&start="
+ if start:
+ url += start.isoformat()
+ url += "&end="
+ if end:
+ url += end.isoformat()
+ ctx = {
+ "date": datetime.date.today(),
+ "period": period,
+ "start": start,
+ "end": end,
+ "url": url,
+ "periods": Period.objects.all(),
+ }
+ return render_to_response("map.html", ctx, context_instance=RequestContext(request))
+
+
+def gmap_data(request):
+ period, start, end = get_start_end(request)
+ f = open("latlng.json")
+ content = f.read()
+ info = simplejson.loads(content)
+ appartments = Appartment.objects.all()
+ for a in appartments:
+ fr = True
+ try:
+ info[a.area]["url"] = "/appartments/?period=&start=&end=&area=%s&category=" % a.area
+ info[a.appartment]["url"] = "/admin/reception/appartment/%s/" % a.id
+ except:
+ print "Cannot add url for " + a.appartment
+ for r in a.reservations.all():
+ if r.status in ("CONFIRMED", "PENDING", "UNKNOWN") and r.inside(start, end):
+ fr = False
+ if info.get(a.appartment, None):
+ info[a.appartment]["status"] = r.status
+ info[a.appartment]["reservation"] = u"Όνομα: %s
Period: %s
Type:%s" % (r.owner, r.period, r.get_res_type_display())
+ if info.get(a.area, None):
+ info[a.area]["reserved"].append([a.appartment, r.status])
+ if fr and info.get(a.area, None):
+ info[a.area]["free"].append(a.appartment)
+ if fr and info.get(a.appartment, None):
+ info[a.appartment]["status"] = "FREE"
+ info[a.appartment]["reservation"] = "Free!!"
+ return HttpResponse(simplejson.dumps(info))
+
+def persons(request):
+ period, start, end = get_start_end(request)
+ persons = MilitaryPerson.objects.all()
+ persons = filter(lambda p: [p for r in p.reservations.all() if r.inside(start, end)], persons)
+ persons = MilitaryPerson.objects.filter(id__in=[p.id for p in persons])
+ persons = persons.all().prefetch_related("reservations", "contacts", "rank")
+ persons = sorted(persons, key=lambda p: p.surname)
+ ctx = {
+ "period": period,
+ "start": start,
+ "end": end,
+ "periods": Period.objects.all(),
+ "persons": persons,
+ }
+ return render_to_response("persons.html", ctx, context_instance=RequestContext(request))
+
+
+
+def test(request):
+
+ period, start, end = get_start_end(request)
+ rtype = request.GET.get("rtype", None)
+ status = request.GET.get("status", None)
+ order = request.GET.get("order", None)
+
+ reservations = Reservation.objects.all()
+
+ if rtype:
+ reservations = reservations.filter(res_type=rtype)
+ if status:
+ reservations = reservations.filter(status=status)
+
+ reservations = [r for r in reservations if r.inside(start, end)]
+
+ if order == "apartment":
+ reservations = sorted(reservations, key=lambda r: (r.appartment.area, int(r.appartment.no)) if r.appartment else None)
+ else:
+ reservations = sorted(reservations, key=lambda r: r.owner.surname)
+
+ #visitors = Visitor.objects.all()
+ ctx = {
+ "period": period,
+ "start": start,
+ "end": end,
+ "rtype": rtype,
+ "status": status,
+ "rtypes": Reservation.RESERVATION_TYPES,
+ "statuses": Reservation.STATUSES,
+ "periods": Period.objects.all(),
+ "reservations": reservations,
+ }
+ return render_to_response("test.html", ctx, context_instance=RequestContext(request))
diff --git a/settings.py b/settings.py
index f0f64bd..3d44cf1 100644
--- a/settings.py
+++ b/settings.py
@@ -108,7 +108,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
- 'reception.nested_inlines',
+ 'nested_inlines',
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..1d8167c
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,89 @@
+# Copyright 2011 GRNET S.A. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or
+# without modification, are permitted provided that the following
+# conditions are met:
+#
+# 1. Redistributions of source code must retain the above
+# copyright notice, this list of conditions and the following
+# disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following
+# disclaimer in the documentation and/or other materials
+# provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# The views and conclusions contained in the software and
+# documentation are those of the authors and should not be
+# interpreted as representing official policies, either expressed
+# or implied, of GRNET S.A.
+#
+
+import distribute_setup
+distribute_setup.use_setuptools()
+
+import os
+
+from distutils.util import convert_path
+from fnmatch import fnmatchcase
+from setuptools import setup, find_packages
+
+HERE = os.path.abspath(os.path.normpath(os.path.dirname(__file__)))
+
+
+__version__ = "0.1"
+
+# Package info
+VERSION = __version__
+README = open(os.path.join(HERE, 'README')).read()
+CHANGES = open(os.path.join(HERE, 'Changelog')).read()
+SHORT_DESCRIPTION = 'Booking management and much more for KEDA/Z'
+
+PACKAGES_ROOT = '.'
+PACKAGES = find_packages(PACKAGES_ROOT)
+
+# Package meta
+CLASSIFIERS = []
+
+# Package requirements
+INSTALL_REQUIRES = []
+
+setup(
+ name = 'keda',
+ version = VERSION,
+ license = 'BSD',
+ url = 'https://github.com/dimara/keda.git',
+ description = SHORT_DESCRIPTION,
+ long_description=README + '\n\n' + CHANGES,
+ classifiers = CLASSIFIERS,
+
+ author='Dimitris Aragiorgis & Tasos Alexiou',
+ author_email='dimara@grnet.gr',
+ maintainer='Dimitris Aragiorgis & Tasos Alexiou',
+ maintainer_email='dimara@grnet.gr',
+
+ packages = PACKAGES,
+ package_dir= {'': PACKAGES_ROOT},
+ include_package_data = True,
+ zip_safe = False,
+
+ install_requires = INSTALL_REQUIRES,
+
+ dependency_links = ['http://docs.dev.grnet.gr/pypi'],
+ entry_points={
+ 'console_scripts': [],
+ },
+)
diff --git a/urls.py b/urls.py
index d079a32..6d02444 100644
--- a/urls.py
+++ b/urls.py
@@ -1,15 +1,13 @@
from django.conf.urls.defaults import *
from django.views.generic import list_detail
-from keda.views import *
-import settings
+from reception.views import *
+from django.conf import settings
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
-from keda.reception import *
-
urlpatterns = patterns('',
# Example:
diff --git a/views.py b/views.py
deleted file mode 100644
index 684c407..0000000
--- a/views.py
+++ /dev/null
@@ -1,402 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-from django.http import *
-import datetime
-from django import template
-from django.utils import simplejson
-import settings
-from django.template.loader import get_template
-from django.template import Context, RequestContext
-from django.forms.models import modelformset_factory
-from django.forms.models import inlineformset_factory
-from django.shortcuts import render_to_response
-from reception.models import *
-from django.db.models import Q
-from django.core.context_processors import csrf
-from django import forms
-from itertools import chain
-
-
-def home(request):
- date = datetime.date.today()
- now = datetime.datetime.now()
- return render_to_response("welcome.html", {"now" : now,"date": date}, context_instance=RequestContext(request))
-
-
-def display_meta(request):
- values = request.META.items()
- values.sort()
- html = []
- for k, v in values:
- html.append('%s | %s |
' % (k, v))
- return HttpResponse('' % '\n'.join(html))
-
-
-def value2id(value):
- if value:
- try:
- return int(value)
- except ValueError:
- pass
-
- return value
-
-
-def id_from_request(qd, name):
- return value2id(qd.get(name))
-
-
-def check_period(avail, check_in, check_out):
- err = None
- ret = []
- if (check_out and check_out <= check_in):
- err = "ERROR: Check-out before Check-in!!!"
- else:
- for a in avail:
- ok = True
- for r in a.reservations.all():
- if r.status in ("CONFIRMED", "PENDING", "UNKNOWN") and r.inside(check_in, check_out):
- ok = False
- break
- if ok:
- ret.append(a)
-
- return (ret, err)
-
-
-def availability(request):
- period, start, end = get_start_end(request)
- area = request.GET.get("area")
- category = id_from_request(request.GET, "category")
- damaged = request.GET.get("damaged", False)
-
- avail = Appartment.objects.all()
- if area:
- avail = avail.filter(area=area)
-
- if damaged:
- avail = avail.exclude(damages__fixed=False)
-
- if category:
- avail = avail.filter(category=category)
-
- date_errors = None
- avail, date_errors = check_period(avail, start, end)
- avail = sorted(avail, key=lambda a: (a.area, int(a.no)))
-
- ctx = {
- "period": period,
- "start": start,
- "end": end,
- "periods": Period.objects.all(),
- "date_errors": date_errors,
- "area": area,
- "areas": Appartment.AREAS,
- "category": category,
- "categories": Category.objects.values(),
- "damaged": damaged,
- "avail": avail,
- }
- return render_to_response("availability.html", ctx, context_instance=RequestContext(request))
-
-
-def appartments(request):
- period, start, end = get_start_end(request)
- area = request.GET.get("area")
- category = id_from_request(request.GET, "category")
- damaged = request.GET.get("damaged", False)
-
- appartments = Appartment.objects.all()
- if area:
- appartments = appartments.filter(area=area)
-
- if damaged:
- appartments = appartments.exclude(damages__fixed=False)
-
- if category:
- appartments = appartments.filter(category=category)
-
- appartments = sorted(appartments, key=lambda a: (a.area, int(a.no)))
- appres = []
- for a in appartments:
- reserved = False
- for r in a.reservations.all():
- if r.status in ("CONFIRMED", "PENDING", "UNKNOWN") and r.inside(start, end):
- reserved = True
- appres.append((a, r))
- if not reserved:
- appres.append((a, None))
-
- ctx = {
- "period": period,
- "start": start,
- "end": end,
- "periods": Period.objects.all(),
- "areas": Appartment.AREAS,
- "categories": Category.objects.values(),
- "appartments": appartments,
- "appres": appres,
- }
- return render_to_response("appartments.html", ctx, context_instance=RequestContext(request))
-
-
-def parousiologio(request):
- staff = Staff.objects.all().order_by("rank__level", "extra", "-surname").reverse()
- ctx = {
- "date": datetime.date.today(),
- "staff": staff,
- }
- return render_to_response("parousiologio.html", ctx, context_instance=RequestContext(request))
-
-
-def get_datetime(value):
- if value:
- y, m, d = map(int, value.split("-"))
- return datetime.date(y, m, d)
- else:
- return datetime.date.today()
-
-def get_start_end(request):
- period = id_from_request(request.GET, "period")
- start = request.GET.get("start", None)
- end = request.GET.get("end", None)
- if period:
- period = Period.objects.get(id=period)
- start = period.start
- end = period.end
- elif start and end:
- start = get_datetime(start)
- end = get_datetime(end)
- else:
- start = get_datetime(start)
- end = start + datetime.timedelta(days=1)
-
- return period, start, end
-
-def info(request):
- period, start, end = get_start_end(request)
- rtype = request.GET.get("rtype", None)
- status = request.GET.get("status", None)
- reservations = Reservation.objects.all()
- if rtype:
- reservations = reservations.filter(res_type=rtype)
- if status:
- reservations = reservations.filter(status=status)
- reservations = filter(lambda x: x.inside(start, end), reservations)
- reservations = Reservation.objects.filter(id__in=[r.id for r in reservations])
- reservations = reservations.all().prefetch_related(
- "owner__rank",
- "owner__relatives",
- "owner__contacts",
- "owner__vehicles",
- "appartment",
- "receipts")
- reservations = sorted(reservations, key=lambda x: x.owner.surname)
- ctx = {
- "period": period,
- "start": start,
- "end": end,
- "rtype": rtype,
- "status": status,
- "rtypes": Reservation.RESERVATION_TYPES,
- "statuses": Reservation.STATUSES,
- "periods": Period.objects.all(),
- "reservations": reservations,
- }
- return render_to_response("info.html", ctx, context_instance=RequestContext(request))
-
-def reservations(request):
-
- period, start, end = get_start_end(request)
- rtype = request.GET.get("rtype", None)
- status = request.GET.get("status", None)
- reservations = Reservation.objects.all()
- if rtype:
- reservations = reservations.filter(res_type=rtype)
- if status:
- reservations = reservations.filter(status=status)
-
- reservations = filter(lambda x: x.inside(start, end), reservations)
- reservations = Reservation.objects.filter(id__in=[r.id for r in reservations])
- reservations = reservations.prefetch_related("owner", "appartment", "receipts")
- reservations = sorted(reservations, key=lambda x: x.owner.surname)
- ctx = {
- "period": period,
- "start": start,
- "end": end,
- "rtype": rtype,
- "status": status,
- "rtypes": Reservation.RESERVATION_TYPES,
- "statuses": Reservation.STATUSES,
- "periods": Period.objects.all(),
- "reservations": reservations,
- }
- return render_to_response("reservations.html", ctx, context_instance=RequestContext(request))
-
-def logistic(request):
-
- period, start, end = get_start_end(request)
- rtype = request.GET.get("rtype", None)
- status = request.GET.get("status", None)
- receipt_type = request.GET.get("receipt_type", None)
- first = request.GET.get("first", None)
- last = request.GET.get("last", None)
- receipts = Receipt.objects.all().order_by("no")
- if rtype:
- receipts = receipts.filter(reservation__res_type=rtype)
- if receipt_type:
- receipts = receipts.filter(rtype=receipt_type)
- if status:
- receipts = receipts.filter(reservation__status=status)
- if first:
- receipts = [r for r in receipts if r.inside(first, last)]
- else:
- receipts = [r for r in receipts if r.reservation.inside(start, end)]
-
- l = lambda x: [r.euro for r in x]
- ctx = {
- "period": period,
- "start": start,
- "end": end,
- "rtype": rtype,
- "status": status,
- "sum": sum(l(receipts)),
- "periods": Period.objects.all(),
- "receipts": receipts,
- "rtypes": Reservation.RESERVATION_TYPES,
- "statuses": Reservation.STATUSES,
- "receipt_types": Receipt.RECEIPT_TYPES,
- "receipt_type": receipt_type,
- }
- return render_to_response("logistic.html", ctx, context_instance=RequestContext(request))
-
-def th(request):
-
- period, start, end = get_start_end(request)
- reservations = Reservation.objects.filter(status="CONFIRMED", telephone=True)
- reservations = [r for r in reservations if r.inside(start, end)]
- reservations = sorted(reservations, key=lambda r: (r.appartment.area, int(r.appartment.no)) if r.appartment else None)
-
- ctx = {
- "period": period,
- "start": start,
- "end": end,
- "periods": Period.objects.all(),
- "reservations": reservations,
- }
- return render_to_response("th.html", ctx, context_instance=RequestContext(request))
-
-def damages(request):
-
- date = datetime.date.today()
- damages = Damage.objects.filter(fixed=False).order_by("tag")
-
- ctx = {
- "damages": damages,
- "date":date,
- }
- return render_to_response("damages.html", ctx, context_instance=RequestContext(request))
-
-
-def gmap(request):
- period, start, end = get_start_end(request)
- url = "/gmap_data/?period="
- if period:
- url += str(period.id)
- url += "&start="
- if start:
- url += start.isoformat()
- url += "&end="
- if end:
- url += end.isoformat()
- ctx = {
- "date": datetime.date.today(),
- "period": period,
- "start": start,
- "end": end,
- "url": url,
- "periods": Period.objects.all(),
- }
- return render_to_response("map.html", ctx, context_instance=RequestContext(request))
-
-
-def gmap_data(request):
- period, start, end = get_start_end(request)
- f = open("latlng.json")
- content = f.read()
- info = simplejson.loads(content)
- appartments = Appartment.objects.all()
- for a in appartments:
- fr = True
- try:
- info[a.area]["url"] = "/appartments/?period=&start=&end=&area=%s&category=" % a.area
- info[a.appartment]["url"] = "/admin/reception/appartment/%s/" % a.id
- except:
- print "Cannot add url for " + a.appartment
- for r in a.reservations.all():
- if r.status in ("CONFIRMED", "PENDING", "UNKNOWN") and r.inside(start, end):
- fr = False
- if info.get(a.appartment, None):
- info[a.appartment]["status"] = r.status
- info[a.appartment]["reservation"] = u"Όνομα: %s
Period: %s
Type:%s" % (r.owner, r.period, r.get_res_type_display())
- if info.get(a.area, None):
- info[a.area]["reserved"].append([a.appartment, r.status])
- if fr and info.get(a.area, None):
- info[a.area]["free"].append(a.appartment)
- if fr and info.get(a.appartment, None):
- info[a.appartment]["status"] = "FREE"
- info[a.appartment]["reservation"] = "Free!!"
- return HttpResponse(simplejson.dumps(info))
-
-def persons(request):
- period, start, end = get_start_end(request)
- persons = MilitaryPerson.objects.all()
- persons = filter(lambda p: [p for r in p.reservations.all() if r.inside(start, end)], persons)
- persons = MilitaryPerson.objects.filter(id__in=[p.id for p in persons])
- persons = persons.all().prefetch_related("reservations", "contacts", "rank")
- persons = sorted(persons, key=lambda p: p.surname)
- ctx = {
- "period": period,
- "start": start,
- "end": end,
- "periods": Period.objects.all(),
- "persons": persons,
- }
- return render_to_response("persons.html", ctx, context_instance=RequestContext(request))
-
-
-
-def test(request):
-
- period, start, end = get_start_end(request)
- rtype = request.GET.get("rtype", None)
- status = request.GET.get("status", None)
- order = request.GET.get("order", None)
-
- reservations = Reservation.objects.all()
-
- if rtype:
- reservations = reservations.filter(res_type=rtype)
- if status:
- reservations = reservations.filter(status=status)
-
- reservations = [r for r in reservations if r.inside(start, end)]
-
- if order == "apartment":
- reservations = sorted(reservations, key=lambda r: (r.appartment.area, int(r.appartment.no)) if r.appartment else None)
- else:
- reservations = sorted(reservations, key=lambda r: r.owner.surname)
-
- #visitors = Visitor.objects.all()
- ctx = {
- "period": period,
- "start": start,
- "end": end,
- "rtype": rtype,
- "status": status,
- "rtypes": Reservation.RESERVATION_TYPES,
- "statuses": Reservation.STATUSES,
- "periods": Period.objects.all(),
- "reservations": reservations,
- }
- return render_to_response("test.html", ctx, context_instance=RequestContext(request))