Ejemplo n.º 1
0
def moderator_home(request):
    """
    This function moderates the form 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):
                recent_tasks = models.get_my_tasks(owner=handle, recent=True)
                user = models.get_user(handle)
                assign_task_form = forms.AddUserForm()
                delete_task_form = forms.DeleteTaskForm()
                remove_user_form = forms.RemoveUserForm()
                context = {
                    'recent_tasks': recent_tasks,
                    'user': user,
                    'add_user_form': assign_task_form,
                    'delete_task_form': delete_task_form,
                    'remove_user_form': remove_user_form
                }
                return render(request, 'janta/moderator.html', context)
            return redirect("/janta/index/")
        return redirect("/janta/login/")
Ejemplo n.º 2
0
def delete_task(request):
    """
    This function deletes 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_moderator(user_type):
                delete_task_form = forms.DeleteTaskForm(request.POST)
                recent_tasks = models.get_my_tasks(owner=handle, recent=True)
                user = models.get_user(handle)
                assign_task_form = forms.AddUserForm()
                delete_form_message = "Invalid Form please fill again"
                if delete_task_form.is_valid():
                    fd = delete_task_form.cleaned_data
                    status, delete_form_message = viewhelper.validate_delete_task(
                        moderator=handle, form_data=fd)
                    if status:
                        models.delete_task(task_id=fd.get("task_id"))
                        delete_form_message = "Task Deleted"
                        delete_task_form = forms.DeleteTaskForm()
                        recent_tasks = models.get_my_tasks(owner=handle,
                                                           recent=True)
                context = {
                    'recent_tasks': recent_tasks,
                    'user': user,
                    'add_user_form': assign_task_form,
                    'delete_task_form': delete_task_form,
                    'delete_form_message': delete_form_message
                }
                return render(request, 'janta/moderator.html', context)
            return redirect('/janta/index/')
        return redirect("/janta/login/")
Ejemplo n.º 3
0
def my_tasks(request):
    """
    This function handles the functionality of 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):
                tasks = models.get_my_tasks(owner=handle)
                user = models.get_user(handle)
                context = {'tasks': tasks, 'user': user}
                return render(request, 'janta/my-tasks.html', context)
            return redirect("/janta/index/")
        return redirect("/janta/login/")
    if request.method == 'POST':
        return redirect("/janta/index/")
Ejemplo n.º 4
0
def remove_user(request):
    """
    This function removes the user 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_moderator(user_type):
                add_user_form = forms.AddUserForm()
                delete_task_form = forms.DeleteTaskForm()
                remove_user_form = forms.RemoveUserForm(request.POST)
                remove_user_message = "Invalid Form please fill again"
                if remove_user_form.is_valid():
                    fd = remove_user_form.cleaned_data
                    status, remove_user_message, user_handle = viewhelper.validate_remove_user(
                        form_data=fd, moderator=handle)
                    if status:
                        models.remove_user(user=user_handle, moderator=handle)
                        remove_user_form = forms.RemoveUserForm()
                        remove_user_message = "Handle removed"
                recent_tasks = models.get_my_tasks(owner=handle, recent=True)
                user = models.get_user(handle)
                context = {
                    'add_user_form': add_user_form,
                    'remove_user_message': remove_user_message,
                    'recent_tasks': recent_tasks,
                    'user': user,
                    'delete_task_form': delete_task_form,
                    'remove_user_form': remove_user_form
                }
                return render(request, 'janta/moderator.html', context)
            return redirect("/janta/index/")
        return redirect("/janta/login/")