From 104ac78f5b2f251747bd5190aeb327dd4b4066cb Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Sat, 6 Aug 2011 21:24:48 +0100 Subject: [PATCH] Disable recommendations for people with blacklists --- app/hr/templates/hr/index.html | 2 ++ app/hr/utils.py | 4 ++-- app/hr/views.py | 10 ++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/hr/templates/hr/index.html b/app/hr/templates/hr/index.html index 10a3267..e3b5b32 100644 --- a/app/hr/templates/hr/index.html +++ b/app/hr/templates/hr/index.html @@ -8,11 +8,13 @@

Applications

View your current open applications
Create a application

+{% if can_recommend %}

Recommendations

View your current open recommendations
Add a recommendation

+{% endif %} {% if hrstaff %}

HR Admin

diff --git a/app/hr/utils.py b/app/hr/utils.py index e19ef8c..b514343 100644 --- a/app/hr/utils.py +++ b/app/hr/utils.py @@ -21,13 +21,13 @@ def installed(value): return False -def blacklist_values(user): +def blacklist_values(user, level=BLACKLIST_LEVEL_NOTE): """ Returns a list of blacklist values that apply to the application """ blacklist = [] - bl_items = Blacklist.objects.filter(models.Q(expiry_date__gt=datetime.now()) | models.Q(expiry_date=None)) + bl_items = Blacklist.objects.filter(level__lte=level, models.Q(expiry_date__gt=datetime.now()) | models.Q(expiry_date=None)) # Check Reddit blacklists if installed('reddit'): diff --git a/app/hr/views.py b/app/hr/views.py index 5771086..9cb87ed 100644 --- a/app/hr/views.py +++ b/app/hr/views.py @@ -1,6 +1,6 @@ from datetime import datetime, timedelta from django.utils import simplejson -from django.http import HttpResponseRedirect, HttpResponse +from django.http import HttpResponseRedirect, HttpResponse, Http404 from django.shortcuts import render_to_response, get_object_or_404, redirect from django.core.urlresolvers import reverse from django.contrib import messages @@ -10,7 +10,7 @@ from django.template import RequestContext from django.template.loader import render_to_string from django.conf import settings -from utils import installed +from utils import installed, blacklist_values from eve_api.models import EVEAccount, EVEPlayerCorporation, EVEPlayerCharacter from hr.forms import CreateRecommendationForm, CreateApplicationForm, NoteForm, BlacklistUserForm, AdminNoteForm @@ -64,6 +64,7 @@ def check_permissions(user, application=None): @login_required def index(request): hrstaff = check_permissions(request.user) + can_recommend = len(blacklist_values(request.user, BLACKLIST_LEVEL_ADVISORY)) return render_to_response('hr/index.html', locals(), context_instance=RequestContext(request)) ### Application Management @@ -135,6 +136,11 @@ def view_recommendations(request): @login_required def add_recommendation(request): + """ Add a recommendation to a user's application """ + + # If the person has a blacklist, stop recommendations + if len(blacklist_values(request.user, BLACKLIST_LEVEL_ADVISORY)): + raise Http404 clsform = CreateRecommendationForm(request.user) if request.method == 'POST':