From e29646a94714d516d52272fc83d9a15bbc21e488 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sat, 27 Dec 2014 13:52:45 +0100 Subject: [PATCH 1/4] initial version --- .gitignore | 2 ++ __init__.py | 0 celeryrouters.py | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 .gitignore create mode 100644 __init__.py create mode 100644 celeryrouters.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3bb2efd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.*.swp +*.pyc diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/celeryrouters.py b/celeryrouters.py new file mode 100644 index 0000000..e468813 --- /dev/null +++ b/celeryrouters.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + + +class LdapRouter(object): + + def route_for_task(self, task, args=None, kwargs=None): + if 'ldap' in task: + return {'exchange': 'ldap', + 'exchange_type': 'direct', + 'queue': 'ldap'} + return None + + +class FileRouter(object): + + def route_for_task(self, task, args=None, kwargs=None): + if 'file' in task: + return {'exchange': 'file', + 'exchange_type': 'direct', + 'queue': 'file'} + return None + + From 546441d49920caf43eb7d33976c2d71ae85f16d5 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Thu, 1 Jan 2015 22:32:37 +0100 Subject: [PATCH 2/4] unify routers, add support for mysql and pgsql tasks - add new celeryrouters.GvaRouter - remove LdapRouter and FileRouter --- .gitignore | 1 + celeryrouters.py | 23 +++++++---------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 3bb2efd..5f1ace6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .*.swp *.pyc +.ropeproject/ diff --git a/celeryrouters.py b/celeryrouters.py index e468813..ec7b122 100644 --- a/celeryrouters.py +++ b/celeryrouters.py @@ -2,23 +2,14 @@ from __future__ import unicode_literals -class LdapRouter(object): +class GvaRouter(object): def route_for_task(self, task, args=None, kwargs=None): - if 'ldap' in task: - return {'exchange': 'ldap', + for route in ['ldap', 'file', 'mysql', 'pgsql']: + if route in task: + return { + 'exchange': route, 'exchange_type': 'direct', - 'queue': 'ldap'} + 'queue': route, + } return None - - -class FileRouter(object): - - def route_for_task(self, task, args=None, kwargs=None): - if 'file' in task: - return {'exchange': 'file', - 'exchange_type': 'direct', - 'queue': 'file'} - return None - - From 3c4d34cce56dfb75e0e4115c3938ce5b2e6efd83 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sat, 24 Jan 2015 15:38:08 +0100 Subject: [PATCH 3/4] implement viewmixins.StaffOrSelfLoginRequiredMixin --- viewmixins.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 viewmixins.py diff --git a/viewmixins.py b/viewmixins.py new file mode 100644 index 0000000..fc7f106 --- /dev/null +++ b/viewmixins.py @@ -0,0 +1,42 @@ +""" +This module defines mixins for gnuviechadmin views. + +""" +from __future__ import unicode_literals + +from django.http import HttpResponseForbidden +from django.utils.translation import ugettext as _ + +from braces.views import LoginRequiredMixin + + +class StaffOrSelfLoginRequiredMixin(LoginRequiredMixin): + """ + Mixin that makes sure that a user is logged in and matches the current + customer or is a staff user. + + """ + + def dispatch(self, request, *args, **kwargs): + if ( + request.user.is_staff or + request.user == self.get_customer_object() + ): + return super(StaffOrSelfLoginRequiredMixin, self).dispatch( + request, *args, **kwargs + ) + return HttpResponseForbidden( + _('You are not allowed to view this page.') + ) + + def get_customer_object(self): + """ + Views based on this mixin have to implement this method to return + the customer that must be an object of the same class as the + django.contrib.auth user type. + + :return: customer + :rtype: settings.AUTH_USER_MODEL + + """ + raise NotImplemented("subclass has to implement get_customer_object") From d31c1d0fbf02bde5d4dc2be24762d872da64935f Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Mon, 26 Jan 2015 15:43:05 +0100 Subject: [PATCH 4/4] add new route 'web' for web server configuration --- celeryrouters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/celeryrouters.py b/celeryrouters.py index ec7b122..44c4b4f 100644 --- a/celeryrouters.py +++ b/celeryrouters.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals class GvaRouter(object): def route_for_task(self, task, args=None, kwargs=None): - for route in ['ldap', 'file', 'mysql', 'pgsql']: + for route in ['ldap', 'file', 'mysql', 'pgsql', 'web']: if route in task: return { 'exchange': route,