Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
add authorization to tasks views in exp_portal
  • Loading branch information
dtraviglia committed Oct 13, 2015
1 parent 111bd6a commit 731b0a5105f6588beed3d19f8d1b6a8bb4d61836
Showing 2 changed files with 53 additions and 44 deletions.
@@ -3,64 +3,71 @@
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User

def user_authorized(request):
user = request.user
return user.is_staff

def view_tasks(request):
tasks = OpTask.objects.all()
datasets = Dataset.objects.all()
return render(request, 'tasks.html', {'tasks': tasks, 'datasets':datasets})
if user_authorized(request):
tasks = OpTask.objects.all()
datasets = Dataset.objects.all()
return render(request, 'tasks.html', {'tasks': tasks, 'datasets':datasets})

def view_completed(request):
completed_tasks = TaskListItem.objects.all().filter(task_complete=True).order_by('-date_complete')
return render(request, 'completed.html', {'completed_tasks': completed_tasks})
if user_authorized(request):
completed_tasks = TaskListItem.objects.all().filter(task_complete=True).order_by('-date_complete')
return render(request, 'completed.html', {'completed_tasks': completed_tasks})

def view_incomplete(request):
incomplete_tasks = TaskListItem.objects.all().filter(task_complete=False)
return render(request, 'incomplete.html', {'incomplete_tasks': incomplete_tasks})
if user_authorized(request):
incomplete_tasks = TaskListItem.objects.all().filter(task_complete=False)
return render(request, 'incomplete.html', {'incomplete_tasks': incomplete_tasks})

def add_task(request):
datasets = Dataset.objects.all()
return render(request, 'add_task.html', {'datasets': datasets})
if user_authorized(request):
datasets = Dataset.objects.all()
return render(request, 'add_task.html', {'datasets': datasets})

def new_task(request):
dataset = Dataset.objects.get(name=request.POST['task_dataset'])
task = OpTask()
task.dataset = dataset
task.survey_url = request.POST['task_url']
task.name = request.POST['task_name']
task.instructions = request.POST['task_instructions']
task.exit_url = request.POST['task_exit_url']

task.save()
return redirect('exp_portal:view_tasks')
if user_authorized(request):
dataset = Dataset.objects.get(name=request.POST['task_dataset'])
task = OpTask()
task.dataset = dataset
task.survey_url = request.POST['task_url']
task.name = request.POST['task_name']
task.instructions = request.POST['task_instructions']
task.exit_url = request.POST['task_exit_url']
task.save()
return redirect('exp_portal:view_tasks')

def manage_tasks(request):
return view_tasks(request)
if user_authorized(request):
return view_tasks(request)

def view_task_details(request, taskname):
task = OpTask.objects.all().filter(name=taskname)[0]
datasets = Dataset.objects.all()
print task.dataset.name
for dataset in datasets:
print dataset.name
return render(request, 'task_details.html', {'task': task, 'datasets': datasets})
if user_authorized(request):
task = OpTask.objects.all().filter(name=taskname)[0]
datasets = Dataset.objects.all()
print task.dataset.name
for dataset in datasets:
print dataset.name
return render(request, 'task_details.html', {'task': task, 'datasets': datasets})

def edit_task(request, taskpk):
task = OpTask.objects.get(id=taskpk)
task.name = request.POST['task_name']
task.survey_url = request.POST['task_url']
task.exit_url = request.POST['task_exit_url']
task.instructions =request.POST['task_instructions']

dataset = Dataset.objects.get(name=request.POST['task_dataset'])
task.dataset = dataset

task.is_active = request.POST.get('task_active', False)

task.save()

return redirect('exp_portal:view_tasks')
if user_authorized(request):
task = OpTask.objects.get(id=taskpk)
task.name = request.POST['task_name']
task.survey_url = request.POST['task_url']
task.exit_url = request.POST['task_exit_url']
task.instructions =request.POST['task_instructions']
dataset = Dataset.objects.get(name=request.POST['task_dataset'])
task.dataset = dataset
task.is_active = request.POST.get('task_active', False)
task.save()
return redirect('exp_portal:view_tasks')

def delete_task(request, taskpk):
task = OpTask.objects.get(id=taskpk)
task.delete()

return redirect('exp_portal:view_tasks')
if user_authorized(request):
task = OpTask.objects.get(id=taskpk)
task.delete()
return redirect('exp_portal:view_tasks')
@@ -26,6 +26,8 @@

TEMPLATE_DEBUG = True

ADMINS = ADMIN_EMAILS

ALLOWED_HOSTS = ['*']

SITE_ROOT = os.path.realpath(os.path.dirname(__file__))

0 comments on commit 731b0a5

Please sign in to comment.