diff --git a/OpenBench/views.py b/OpenBench/views.py index 7cf618a..cfd5eda 100644 --- a/OpenBench/views.py +++ b/OpenBench/views.py @@ -17,10 +17,16 @@ from OpenBench.utils import pagingContext import OpenBench.utils, datetime - -# Wrap django.shortcuts.render to add framework settings def render(request, template, data): + + # Always provde the Configuration data.update(FRAMEWORK_DEFAULTS) + + # Send User data when logged in + if request.user.is_authenticated: + data.update({'profile' : Profile.objects.get(user=request.user)}) + + # Final wrap of Django's rendering funtion return djangoRender(request, 'OpenBench/{0}'.format(template), data) def register(request): @@ -81,9 +87,7 @@ def logout(request): @login_required(login_url='/login/') def viewProfile(request): - # Build context dictionary for profile template - profile = Profile.objects.get(user=request.user) - data = {'profile' : profile} + # render() gets the profile data for us return render(request, 'viewProfile.html', data) @login_required(login_url='/login/') @@ -111,10 +115,6 @@ def editProfile(request): def index(request, page=0, pageLength=25, greens=False, username=None, error=''): - # Get information about the logged in user - if not request.user.is_authenticated: profile = None - else: profile = Profile.objects.get(user=request.user) - # Get tests pending approval pending = Test.objects.filter(approved=False) pending = pending.exclude(finished=True) @@ -173,7 +173,6 @@ def index(request, page=0, pageLength=25, greens=False, username=None, error='') # Build context dictionary for index template data = { 'error' : error, - 'profile' : profile, 'pending' : pending, 'active' : active, 'completed' : completed[start:end], @@ -282,8 +281,7 @@ def newTest(request): # User trying to view the new test page if request.method == 'GET': - profile = Profile.objects.get(user=request.user) - return render(request, 'newTest.html', {'profile' : profile}) + return render(request, 'newTest.html', {}) try: # Throw out non-approved / disabled users @@ -311,8 +309,7 @@ def viewTest(request, id): # Build context dictionary for test template test = Test.objects.get(id=id) results = Result.objects.all().filter(test=test) - profile = Profile.objects.get(user=request.user) if request.user.is_authenticated else None - data = {'test' : test, 'results' : results, 'profile' : profile} + data = {'test' : test, 'results' : results} return render(request, 'viewTest.html', data) # Unable to find test diff --git a/Templates/OpenBench/viewTest.html b/Templates/OpenBench/viewTest.html index 4723169..8da86f4 100644 --- a/Templates/OpenBench/viewTest.html +++ b/Templates/OpenBench/viewTest.html @@ -89,7 +89,7 @@

Actions

- {% if not test.approved and profile.approver and profile.user.username is not test.author %} + {% if not test.approved and profile.approver and profile.user.username != test.author %} Approve {% elif not test.approved and request.user.is_superuser %} Approve @@ -100,7 +100,7 @@ {% if test.finished and profile.approver %} Restart - {% elif test.finished and profile.user.username is test.author %} + {% elif test.finished and profile.user.username == test.author %} Restart {% elif test.finished %} Restart @@ -109,14 +109,14 @@ {% if not test.finished and profile.approver %} Stop - {% elif not test.finished and profile.user.username is test.author %} + {% elif not test.finished and profile.user.username == test.author %} Stop {% elif not test.finished %} Stop {% endif %} - {% if profile.approver or profile.user.username is test.author %} + {% if profile.approver or profile.user.username == test.author %} Delete {% else %} Delete @@ -136,7 +136,7 @@

- {% if profile.approver or profile.user.username is test.author %} + {% if profile.approver or profile.user.username == test.author %} {% else %}