Commit fc0478e5 authored by Enrico Zini's avatar Enrico Zini
Browse files

Started porting to stretch

parent 273b226e
......@@ -5,7 +5,7 @@ Debian NM Front Desk web application
### Dependencies
apt-get install python-markdown python-ldap python-psycopg2 python-xapian \
python-django python-django-south python-django-housekeeping \
python-django python-django-housekeeping \
python-debian python-debiancontributors
#### django-housekeeping
......
......@@ -19,7 +19,7 @@ class VisitorMixin(object):
def set_visitor_info(self):
self.impersonator = None
if not self.request.user.is_authenticated():
if not self.request.user.is_authenticated:
self.visitor = None
else:
self.visitor = self.request.user
......
......@@ -289,9 +289,11 @@ class Person(PermissionsMixin, models.Model):
def get_username(self):
return self.username
@property
def is_anonymous(self):
return False
@property
def is_authenticated(self):
return True
......@@ -713,7 +715,7 @@ class PersonAuditLog(models.Model):
"""
Compute the changes between two different instances of a Person model
"""
exclude = ["last_login", "date_joined"]
exclude = ["last_login", "date_joined", "groups", "user_permissions"]
changes = {}
if old_person is None:
for k, nv in model_to_dict(new_person, exclude=exclude).items():
......
......@@ -8,7 +8,6 @@ PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
DATA_DIR = os.path.join(PROJECT_DIR, '../data')
DEBUG = False
TEMPLATE_DEBUG = DEBUG
TESTING = 'test' in sys.argv
ADMINS = (
......@@ -87,13 +86,6 @@ STATICFILES_FINDERS = (
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = [
'nm2.auth.AuthMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
......@@ -114,13 +106,6 @@ AUTH_USER_MODEL = 'backend.Person'
ROOT_URLCONF = 'urls'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
"./", "templates"
)
INSTALLED_APPS = [
'django.contrib.auth',
'django.contrib.contenttypes',
......@@ -154,9 +139,27 @@ INSTALLED_APPS = [
'wizard',
]
TEMPLATE_CONTEXT_PROCESSORS = list(global_settings.TEMPLATE_CONTEXT_PROCESSORS) + [
"django.core.context_processors.request",
"backend.context_processors.const",
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
"./", "templates"
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
"django.template.context_processors.request",
"backend.context_processors.const",
],
},
},
]
# A sample logging configuration. The only tangible logging
......
......@@ -14,7 +14,7 @@ urlpatterns = [
# AM preferences editor
url(r'^amprofile(?:/(?P<key>[^/]+))?$', views.AMProfile.as_view(), name="restricted_amprofile"),
# Show changelogs (minechangelogs)
url(r'^minechangelogs/(?P<key>[^/]+)?$', views.minechangelogs, name="restricted_minechangelogs"),
url(r'^minechangelogs/(?P<key>[^/]+)?$', views.MineChangelogs.as_view(), name="restricted_minechangelogs"),
# Impersonate a user
url(r'^impersonate/(?P<key>[^/]+)?$', views.Impersonate.as_view(), name="impersonate"),
# Export database
......
......@@ -252,68 +252,77 @@ class MinechangelogsForm(forms.Form):
help_text=_("Activate this field to download the changelog instead of displaying it"),
)
def minechangelogs(request, key=None):
if request.user.is_anonymous():
raise PermissionDenied
entries = None
info = mmodels.info()
info["max_ts"] = datetime.datetime.fromtimestamp(info["max_ts"])
info["last_indexed"] = datetime.datetime.fromtimestamp(info["last_indexed"])
if key:
person = bmodels.Person.lookup_or_404(key)
else:
person = None
keywords=None
if request.method == 'POST':
form = MinechangelogsForm(request.POST)
if form.is_valid():
query = form.cleaned_data["query"]
keywords = [x.strip() for x in query.split("\n")]
entries = mmodels.query(keywords)
if form.cleaned_data["download"]:
def send_entries():
for e in entries:
yield e
yield "\n\n"
res = http.HttpResponse(send_entries(), content_type="text/plain")
if person:
res["Content-Disposition"] = 'attachment; filename=changelogs-%s.txt' % person.lookup_key
class MineChangelogs(TemplateView):
template_name = "restricted/minechangelogs.html"
def check_permissions(self):
super(MineChangelogs, self).check_permissions()
if self.visitor is None:
raise PermissionDenied
def get_context_data(self, **kw):
ctx = super(MineChangelogs, self).get_context_data(**kw)
entries = None
info = mmodels.info()
info["max_ts"] = datetime.datetime.fromtimestamp(info["max_ts"])
info["last_indexed"] = datetime.datetime.fromtimestamp(info["last_indexed"])
key = self.kwargs.get("key", None)
if key:
person = bmodels.Person.lookup_or_404(key)
else:
person = None
keywords=None
if request.method == 'POST':
form = MinechangelogsForm(request.POST)
if form.is_valid():
query = form.cleaned_data["query"]
keywords = [x.strip() for x in query.split("\n")]
entries = mmodels.query(keywords)
if form.cleaned_data["download"]:
def send_entries():
for e in entries:
yield e
yield "\n\n"
res = http.HttpResponse(send_entries(), content_type="text/plain")
if person:
res["Content-Disposition"] = 'attachment; filename=changelogs-%s.txt' % person.lookup_key
else:
res["Content-Disposition"] = 'attachment; filename=changelogs.txt'
return res
else:
res["Content-Disposition"] = 'attachment; filename=changelogs.txt'
return res
else:
entries = list(entries)
else:
if person:
query = [
person.fullname,
person.email,
]
if person.cn and person.mn and person.sn:
# some people don't use their middle names in changelogs
query.append("{} {}".format(person.cn, person.sn))
if person.uid:
query.append(person.uid)
form = MinechangelogsForm(initial=dict(query="\n".join(query)))
entries = list(entries)
else:
form = MinechangelogsForm()
return render_to_response("restricted/minechangelogs.html",
dict(
keywords=keywords,
form=form,
info=info,
entries=entries,
person=person,
),
context_instance=template.RequestContext(request))
if person:
query = [
person.fullname,
person.email,
]
if person.cn and person.mn and person.sn:
# some people don't use their middle names in changelogs
query.append("{} {}".format(person.cn, person.sn))
if person.uid:
query.append(person.uid)
form = MinechangelogsForm(initial=dict(query="\n".join(query)))
else:
form = MinechangelogsForm()
ctx.update(
keywords=keywords,
form=form,
info=info,
entries=entries,
person=person,
)
return ctx
class Impersonate(View):
def get(self, request, key=None, *args, **kw):
visitor = request.user
if not visitor.is_authenticated() or not visitor.is_admin: raise PermissionDenied
if not visitor.is_authenticated or not visitor.is_admin: raise PermissionDenied
if key is None:
del request.session["impersonate"]
else:
......
......@@ -3,7 +3,7 @@ from __future__ import print_function
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from django.conf.urls import patterns, include, url
from django.conf.urls import include, url
from django.views.generic import TemplateView
from backend.mixins import VisitorTemplateView
from django.conf import settings
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment