From 7dc2168f7d12ab600d84eb3f4fda43287af90bd3 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 17 Feb 2023 20:59:08 +0100 Subject: [PATCH] Added POST --- mirrors/views/mirrorlist.py | 69 ++++++++++++++++++++-------- templates/mirrors/mirror_submit.html | 7 +++ 2 files changed, 56 insertions(+), 20 deletions(-) diff --git a/mirrors/views/mirrorlist.py b/mirrors/views/mirrorlist.py index a6a17856..87e82893 100644 --- a/mirrors/views/mirrorlist.py +++ b/mirrors/views/mirrorlist.py @@ -1,4 +1,5 @@ from operator import attrgetter, itemgetter +from urllib.parse import urlparse, urlunsplit from django import forms from django.db.models import Q @@ -13,7 +14,7 @@ from django.views.decorators.csrf import csrf_exempt from django_countries import countries -from ..models import Mirror, MirrorUrl, MirrorProtocol +from ..models import Mirror, MirrorUrl, MirrorProtocol, MirrorRsync from ..utils import get_mirror_statuses import random @@ -27,8 +28,12 @@ class MirrorRequestForm(forms.ModelForm): upstream = forms.ModelChoiceField( - queryset=Mirror.objects.filter(tier__gte=0, tier__lte=1), - required=False) + queryset=Mirror.objects.filter( + tier__gte=0, + tier__lte=1 + ), + required=False + ) class Meta: model = Mirror @@ -100,6 +105,21 @@ def as_div(self): errors_on_separate_row=True) +class MirrorRsyncForm(forms.ModelForm): + class Meta: + model = MirrorRsync + fields = ('ip',) + + def as_div(self): + "Returns this form rendered as HTML s." + return self._html_output( + normal_row=u'%(label)s %(field)s%(help_text)s', + error_row=u'%s', + row_ender='', + help_text_html=u' %s', + errors_on_separate_row=True) + + class MirrorlistForm(forms.Form): country = forms.MultipleChoiceField(required=False, widget=SelectMultiple(attrs={'size': '12'})) protocol = forms.MultipleChoiceField(required=False, widget=CheckboxSelectMultiple) @@ -215,22 +235,30 @@ def find_mirrors_simple(request, protocol): return find_mirrors(request, protocols=[proto]) def submit_mirror(request): - # if request.method == 'POST' or len(request.GET) > 0: - # data = request.POST if request.method == 'POST' else request.GET - # form1 = MirrorUrlForm(data=data) - # if form.is_valid(): - # countries = form.cleaned_data['country'] - # protocols = form.cleaned_data['protocol'] - # use_status = form.cleaned_data['use_mirror_status'] - # ipv4 = '4' in form.cleaned_data['ip_version'] - # ipv6 = '6' in form.cleaned_data['ip_version'] - # return find_mirrors(request, countries, protocols, - # use_status, ipv4, ipv6) - # else: - form1 = MirrorRequestForm() - url1 = MirrorUrlForm() - url2 = MirrorUrlForm() - url3 = MirrorUrlForm() + if request.method == 'POST' or len(request.GET) > 0: + data = request.POST if request.method == 'POST' else request.GET + + form1 = MirrorRequestForm(data=data) + url1 = MirrorUrlForm(data=data) + url2 = MirrorUrlForm(data=data) + url3 = MirrorUrlForm(data=data) + rsync = MirrorRsyncForm(data=data) + + if form1.is_valid() and url1.is_valid() and url2.is_valid() and url3.is_valid() and rsync.is_valid(): + print("Successful") + # countries = form.cleaned_data['country'] + # protocols = form.cleaned_data['protocol'] + # use_status = form.cleaned_data['use_mirror_status'] + # ipv4 = '4' in form.cleaned_data['ip_version'] + # ipv6 = '6' in form.cleaned_data['ip_version'] + # return find_mirrors(request, countries, protocols, + # use_status, ipv4, ipv6) + else: + form1 = MirrorRequestForm() + url1 = MirrorUrlForm() + url2 = MirrorUrlForm() + url3 = MirrorUrlForm() + rsync = MirrorRsyncForm() return render( request, @@ -239,7 +267,8 @@ def submit_mirror(request): 'submission_form1': form1, 'url1': url1, 'url2': url2, - 'url3': url3 + 'url3': url3, + 'rsync' : rsync } ) diff --git a/templates/mirrors/mirror_submit.html b/templates/mirrors/mirror_submit.html index 614eeca1..4e537e6f 100644 --- a/templates/mirrors/mirror_submit.html +++ b/templates/mirrors/mirror_submit.html @@ -20,6 +20,7 @@

Available mirrors

Mirror information

+ {% if not submission_form1.is_valid %}

Before you can submit a Tier 1 request the mirror in question must first be a registered Tier 2 for a certain amount of time with proven reliablity. Once the submitted information is verified the mirror will be visible under the appropriate tier list above. This process usually takes 5 minutes.

@@ -27,8 +28,14 @@

Mirror information

{{ url1.as_div }} {{ url2.as_div }} {{ url3.as_div }} + {{ rsync.as_div }}

+ {% else %} + + Your request have successfully been submitted and should be visible within 5 minutes in the mirrorlist. + + {% endif %} {% endblock %}