No Description
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.

forms.py 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # This file is part of dnmgmt, a number resource management system
  2. # Licensed under GNU General Public License v3 or later
  3. # Written by Sebastian Lohff (seba@someserver.de)
  4. from django import forms
  5. from django.db.models import Q
  6. from .models import Request
  7. from whoisdb.models import Maintainer
  8. class RequestForm(forms.Form):
  9. RESOURCES = map(lambda _x: (_x, _x), [
  10. "AS Number (16bit)", "IPv4 /27", "IPv4 > /27", "IPv6", "other"
  11. ])
  12. applicant = forms.ModelChoiceField(Maintainer.objects.none(), label="Applicant (you)", help_text="Maintainer you want to request resources for")
  13. provider = forms.ModelChoiceField(Maintainer.objects.none(), label="Provider", help_text="LIR/RIR you want to request resources from")
  14. subject = forms.CharField(label="Subject")
  15. resources = forms.CheckboxSelectMultiple(choices=RESOURCES)
  16. message = forms.CharField(widget=forms.Textarea, help_text="Describe shortly what resources you need and what you need them for")
  17. def __init__(self, user, *args, **kwargs):
  18. super(RequestForm, self).__init__(*args, **kwargs)
  19. self._user = user
  20. self.fields['applicant'].queryset = self._user.maintainer_set.all()
  21. self.fields['provider'].queryset = Maintainer.objects.filter(Q(rir=True) | Q(lir=True))
  22. def clean(self):
  23. cleaned_data = super(RequestForm, self).clean()
  24. if not self.errors:
  25. mnts = self._user.maintainer_set.all()
  26. if cleaned_data['applicant'] in mnts and cleaned_data['provider'] in mnts:
  27. raise forms.ValidationError("You could request resources from yourself, but this would actually not make that much sense.")
  28. class ResponseForm(forms.Form):
  29. new_status = forms.ChoiceField(choices=[("KEEP", "----", )] + list(Request.STATES), initial="KEEP", help_text="Only set this if you want to change the status of this request")
  30. message = forms.CharField(widget=forms.Textarea)
  31. def __init__(self, request, user, *args, **kwargs):
  32. super(ResponseForm, self).__init__(*args, **kwargs)
  33. self._request = request
  34. self._user = user
  35. def clean(self):
  36. cleaned_data = super(ResponseForm, self).clean()
  37. if not self.errors:
  38. if cleaned_data['new_status'] == self._request.status:
  39. raise forms.ValidationError("Status changed to same as ticket")
  40. if self._request.status in (Request.STATE_RESOLVED, Request.STATE_REJECTED) and \
  41. cleaned_data['new_status'] not in (Request.STATE_OPEN,):
  42. raise forms.ValidationError("Please put this ticket in an open state before adding messages")
  43. class ProviderResponseForm(ResponseForm):
  44. createdResources = forms.CharField(label="Created resources", help_text="If you have created resources for this request, please enter their handles here", required=False)