You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.6 KiB

# This file is part of dnmgmt, a number resource management system
# Licensed under GNU General Public License v3 or later
# Written by Sebastian Lohff (
7 years ago
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.views.generic import FormView
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.decorators import login_required
from django.db.models import Q
7 years ago
from django.utils import timezone
from .models import Request, RequestMessage
from .forms import RequestForm, ResponseForm, ProviderResponseForm
def listRequests(request):
mnts = request.user.maintainer_set.all()
requestedFromMe = Request.objects.filter(applicant__in=mnts)
requestedToMe = Request.objects.filter(provider__in=mnts)
requests = (requestedFromMe | requestedToMe).order_by("-lastAction")
7 years ago
return render(request, "rrequests/list.html", {"mnts": mnts, "requests": requests, "requestedFromMe": requestedFromMe, "requestedToMe": requestedToMe})
7 years ago
class RrequestCreate(LoginRequiredMixin, FormView):
template_name = "rrequests/request_create.html"
form_class = RequestForm
7 years ago
def get_form_kwargs(self, *args, **kwargs):
kwargs = super(RrequestCreate, self).get_form_kwargs(*args, **kwargs)
kwargs['user'] = self.request.user
7 years ago
return kwargs
7 years ago
def form_valid(self, form):
formData = form.cleaned_data
request = Request(
7 years ago
requestMsg = RequestMessage(
7 years ago
7 years ago
return HttpResponseRedirect(request.get_absolute_url())
7 years ago
def rrequestDetail(request, pk):
mnts = request.user.maintainer_set.all()
reqObj = get_object_or_404(Request.objects.filter(Q(provider__in=mnts) | Q(applicant__in=mnts)), pk=pk)
mnts = request.user.maintainer_set.all()
formClass = None
provider = None
initialFormData = {}
if reqObj.provider in mnts:
provider = True
formClass = ProviderResponseForm
initialFormData["createdResources"] = reqObj.grantedResources
provider = False
formClass = ResponseForm
if request.method == "POST":
form = formClass(request=reqObj, user=request.user, data=request.POST)
if form.is_valid():
# create message object
msg = RequestMessage(
creator=reqObj.provider if provider else reqObj.applicant,
if form.cleaned_data['new_status'] != "KEEP":
msg.statusChanged = form.cleaned_data['new_status']
reqObj.status = msg.statusChanged
if "createdResources" in form.cleaned_data and \
form.cleaned_data['createdResources'].strip() != "":
reqObj.grantedResources = form.cleaned_data["createdResources"].strip()
reqObj.lastAction =
return HttpResponseRedirect(reverse("rrequests:show", args=(pk,)))
form = formClass(request=reqObj, user=request.user, initial=initialFormData)
return render(request, "rrequests/request_detail.html", {"request": reqObj, "form": form})
7 years ago