def login(self, request, usertype=None, **kwargs): # """ # Displays the login form for the given HttpRequest. # """ from django.contrib.auth.models import User, Group # Provide some extra variables for the admin login template # Show a list of all the open and recently closed allocation rounds from datetime import datetime, timedelta from ivecallocation.allocation.models import AllocationRound from django.db.models import Q from operator import attrgetter today = datetime.today() delta = timedelta(182) allocation_rounds = AllocationRound.objects.filter( Q(start_date__lte=today,end_date__gte=today) | Q(end_date__gte=(today - delta))) allocation_rounds = sorted(allocation_rounds, key=attrgetter('end_date'), reverse=True) extra_context = {'allocation_rounds': allocation_rounds, 'usertype': usertype or ''} response = super(IvecAdminSite, self).login(request, extra_context) if request.user and request.user.is_active and request.user.is_staff: # if applications are open we redirect to application page # otherwise main admin site if settings.APPLICATIONS_OPEN: unprivileged = Group.objects.get(name='unprivileged') # is user in group 'unprivileged'? if unprivileged in user.groups.all(): # yes. Does this user have an application form try: users_app_count = Application.objects.filter(created_by=user).count() if users_app_count: # goto changelist return http.HttpResponseRedirect(url("/admin/allocation/application/")) else: # go to add application form return http.HttpResponseRedirect(url("/admin/allocation/application/add/")) except Application.DoesNotExist: return http.HttpResponseRedirect(url("/admin/allocation/application/add/")) else: # standard login location return http.HttpResponseRedirect(request.get_full_path()) else: return http.HttpResponseRedirect(request.get_full_path()) else: return response
SITE_ID = 1 # https if SCRIPT_NAME: SSL_ENABLED = True else: SSL_ENABLED = False # Locale TIME_ZONE = 'Australia/Perth' LANGUAGE_CODE = 'en-us' USE_I18N = True TEMPLATE_DEBUG = DEBUG LOGIN_URL = url('/accounts/login/') LOGOUT_URL = url('/accounts/logout/') ## ## Django Core stuff ## TEMPLATE_LOADERS = [ 'ccg.template.loaders.makoloader.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ] MIDDLEWARE_CLASSES = [ 'django.middleware.common.CommonMiddleware', 'django.middleware.transaction.TransactionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',