def reject_submission(request): """ This function rejects the submitted task by request. :type request: http request :param request: the request sent for the task :return: redirecting to the page according to http request """ if request.method == 'GET': if request.session.keys(): handle = request.session.get("handle") user_type = request.session.get("user_type") if viewhelper.is_moderator(user_type): task_id = request.GET.get("task_id") user_handle = request.GET.get("handle") if task_id is not None and user_handle is not None: task = models.get_task(task_id) user_task_map = models.get_user_task_map( task_id=task_id, handle=user_handle) if task is not None and task.owner == handle and user_task_map is not None: models.reject_submission(task_id=task_id, handle=user_handle) return redirect('/janta/task-status/?task_id=' + task_id) return redirect("/janta/index/") return redirect("/janta/login/")
def admin_del_task(request): """ This function is used to delete the tasks by admin. :type request: http request :param request: the request sent for the task :return: redirecting to the page according to http request """ if request.method == 'POST': if request.session.keys(): handle = request.session.get("handle") user_type = request.session.get("user_type") if viewhelper.is_admin(user_type): user = models.get_user(handle) message = "Invalid Task Id" fd = request.POST task_id = fd.get("del_task_id") if task_id is not None and viewhelper.is_task_id( task_id=task_id): task = models.get_task(task_id=task_id) message = "Task Id does not exists" if task is not None: models.admin_del_task(task_id=task_id) message = "Task deleted" context = {'user': user, 'message': message} return render(request, 'janta/admin.html', context) return redirect('/janta/index/') return redirect("/janta/login/")
def task_status(request): """ This function keeps track of the status of task by request. :type request: http request :param request: the request sent for the task :return: redirecting to the page according to http request """ if request.method == 'GET': if request.session.keys(): handle = request.session.get("handle") user_type = request.session.get("user_type") if viewhelper.is_moderator(user_type): task_id = request.GET.get("task_id") if task_id is not None: task = models.get_task(task_id) if task is not None and task.owner == handle: user = models.get_user(handle) sub_status = models.get_submission_status( task_id=task_id, moderator=handle) submissions = models.get_not_accepted_submissions( task_id=task_id) context = { 'task': task, 'user': user, 'sub_status': sub_status, 'submissions': submissions } return render(request, 'janta/task-status.html', context) return redirect("/janta/index/") return redirect("/janta/login/")
def validate_delete_task(moderator, form_data): """ This function validate the delete_task details. :param form_data: detail of task :param moderator: moderator details :return: :status: status :message: message """ status = True message = None task_id = form_data.get("task_id") if not is_task_id(task_id): status = False message = "Invalid Task Id" return status, message task = models.get_task(task_id) if task is None: status = False message = "Task Id does not exist" return status, message if task.owner != moderator: status = False message = "You are NOT owner of Task Id:" + task_id return status, message return status, message
def modify_task(request): """ This function modifies the task by request. :type request: http request :param request: the request sent for the task :return: redirecting to the page according to http request """ if request.method == 'GET': if request.session.keys(): handle = request.session.get("handle") user_type = request.session.get("user_type") if viewhelper.is_moderator(user_type): task_id = request.GET.get("task_id") if task_id is not None: task = models.get_task(task_id) task_form = forms.CreateTaskForm( initial={ 'task_id': task_id, 'task_type': task.task_type, 'description': task.description, 'deadline': task.deadline }) # task_form.fields['task_id'].widget.attrs['disabled'] = True task_form.fields['task_id'].widget.attrs['readonly'] = True user = models.get_user(handle) context = {'modify_task_form': task_form, 'user': user} return render(request, 'janta/modify-task.html', context) return redirect("/janta/index/") return redirect("/janta/login/") if request.method == 'POST': if request.session.keys(): handle = request.session.get("handle") user_type = request.session.get("user_type") if viewhelper.is_moderator(user_type): form = forms.CreateTaskForm(request.POST) message = "Invalid Form please fill again" if form.is_valid(): fd = form.cleaned_data status, message = viewhelper.validate_modify_task(fd) if status: models.modify_task(task_id=fd.get("task_id"), owner=handle, description=fd.get("description"), task_type=fd.get("task_type"), deadline=fd.get("deadline")) return redirect('/janta/moderator/') form.fields['task_id'].widget.attrs['readonly'] = True user = models.get_user(handle) context = { 'modify_task_form': form, 'message': message, 'user': user } return render(request, 'janta/modify-task.html', context) return redirect("/janta/login/")
def submit_task(request): """ This function submits the task by request. :type request: http request :param request: the request sent for the task :return: redirecting to the page according to http request """ if request.method == 'POST': if request.session.keys(): handle = request.session.get("handle") user_type = request.session.get("user_type") if viewhelper.is_user(user_type): fd = request.POST task_id = fd.get("task_id") task = models.get_task(task_id=task_id) if task is not None: if viewhelper.is_info(task_type=task.task_type): models.submit_task(task_id=task_id, handle=handle, submission="") return redirect('/janta/submitted-tasks/') elif viewhelper.is_text(task_type=task.task_type): models.submit_task(task_id=task_id, handle=handle, submission=fd.get("input_txt")) return redirect('/janta/submitted-tasks/') elif viewhelper.is_upload(task_type=task.task_type): file = request.FILES.get("input_file") if file is not None and viewhelper.is_file_name( file.name): path = viewhelper.save_file(file=file, handle=handle, task_id=task_id) models.submit_task(task_id=task_id, handle=handle, submission=path) return redirect('/janta/submitted-tasks/') user = models.get_user(handle) message = 'Invalid file name please submit again. file name regex: [a-zA-Z0-9_. ]{1,45}' return render(request, 'janta/error.html', context={ 'message': message, 'user': user }) return redirect("/janta/index/") return redirect("/janta/login/")
def validate_create_task(form_data): """ This function validate the create_task details. :param form_data: task details :return: :status: status :message: message """ message = None status = True # test if task_id already exist task_id = form_data.get("task_id") description = form_data.get("description") task_type = form_data.get("task_type") deadline = form_data.get("deadline") if not is_task_id(task_id): status = False message = "Invalid Task Id" return status, message if not is_description(description): status = False message = "Invalid Task Id" return status, message if not is_task_type(task_type): status = False message = "Invalid task type" return status, message if deadline < date.today(): status = False message = "Invalid past deadline" return status, message if models.get_task(task_id) is not None: status = False message = "Task Id already exists try another" return status, message return status, message