Ejemplo n.º 1
0
def requests(request):
    if not request.user.is_authenticated():
        return redirect('basics:actofgoods_startpage')
    if not request.user.is_active:
        return render(request, 'basics/verification.html', {'active':False})
    if not request.user.is_superuser and not request.user.is_staff:
        return redirect('basics:home')
    requests = ContactUs.objects.all().filter(works_on=None).order_by('create_date')
    works_on = ContactUs.objects.filter(works_on=request.user).order_by('create_date')
    if request.method == 'POST':
        form = SearchUserForm(request.POST)
        if form.is_valid():
            email = request.POST.get('email')
            if 'filter_in_progress_requests' in form.data:
                if {'email':email} in works_on.values('email'):
                    filter_in_progress = works_on.filter(email=email)
                    return render(request, 'administration/requests.html', {'requests': requests, 'filter_in_progress':filter_in_progress})
                else:
                    messages.add_message(request, messages.INFO, 'wrong_email_filter_in_progress')
            elif 'filter_new_requests' in form.data:
                if {'email':email} in requests.values('email'):
                    filter_new = requests.filter(email=email)
                    return render(request, 'administration/requests.html', {'works_on': works_on, 'filter_new':filter_new})
                else:
                    messages.add_message(request, messages.INFO, 'wrong_email_filter_new')
        form = RequestForm(request.POST)
        if form.is_valid():
            key = request.POST.get('key')
            if key:
                req = ContactUs.objects.get(pk=key)
                email = req.email
                if 'done_requests_with_filter' in form.data:
                    req.delete()
                    filter_in_progress = ContactUs.objects.filter(works_on=request.user).order_by('create_date').filter(email=email)
                    return render(request, 'administration/requests.html', {'requests': requests, 'filter_in_progress':filter_in_progress})
                elif 'done_requests_without_filter' in form.data:
                    req.delete()
                    works_on = ContactUs.objects.filter(works_on=request.user).order_by('create_date')
                elif 'works_on_requests_with_filter' in form.data:
                    if req.works_on == None:
                        req.works_on = request.user
                        req.save()
                    else:
                        messages.add_message(request, messages.INFO, 'other_admin_is_working_on_this_request')
                    filter_new = ContactUs.objects.all().filter(works_on=None).order_by('create_date').filter(email=email)
                    works_on = ContactUs.objects.filter(works_on=request.user).order_by('create_date')
                    return render(request, 'administration/requests.html', {'filter_new': filter_new, 'works_on':works_on})
                elif 'works_on_requests_without_filter' in form.data:
                    if req.works_on == None:
                        req.works_on = request.user
                        req.save()
                    else:
                        messages.add_message(request, messages.INFO, 'other_admin_is_working_on_this_request')
                    requests = ContactUs.objects.all().filter(works_on=None).order_by('create_date')
                    works_on = ContactUs.objects.filter(works_on=request.user).order_by('create_date')
    return render(request, 'administration/requests.html', {'requests': requests, 'works_on':works_on})
Ejemplo n.º 2
0
def users(request):
    if not request.user.is_authenticated():
        return redirect('basics:actofgoods_startpage')
    if not request.user.is_active:
        return render(request, 'basics/verification.html', {'active':False})
    if not request.user.is_superuser and not request.user.is_staff:
        return redirect('basics:home')
    users = sorted(get_list_or_404(User), key=lambda User: User.email)
    if request.method == "POST":
        form = SearchUserForm(request.POST)
        if form.is_valid():
            email = request.POST.get('email')
            if {'email': email} in User.objects.values('email'):
                usr = User.objects.get(email=email)
                return render(request, 'administration/users.html', {'usr':usr})
            else:
                messages.add_message(request, messages.INFO, 'wrong_email')
    return render(request, 'administration/users.html', {'users': users})