Skip to content

Commit

Permalink
Added POST
Browse files Browse the repository at this point in the history
  • Loading branch information
Torxed committed Feb 17, 2023
1 parent 642b77d commit 7dc2168
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 20 deletions.
69 changes: 49 additions & 20 deletions mirrors/views/mirrorlist.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 <divs>s."
return self._html_output(
normal_row=u'<div%(html_class_attr)s>%(label)s %(field)s%(help_text)s</div>',
error_row=u'%s',
row_ender='</div>',
help_text_html=u' <span class="helptext">%s</span>',
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)
Expand Down Expand Up @@ -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,
Expand All @@ -239,7 +267,8 @@ def submit_mirror(request):
'submission_form1': form1,
'url1': url1,
'url2': url2,
'url3': url3
'url3': url3,
'rsync' : rsync
}
)

Expand Down
7 changes: 7 additions & 0 deletions templates/mirrors/mirror_submit.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@ <h3>Available mirrors</h3>

<h3>Mirror information</h3>

{% if not submission_form1.is_valid %}
<p>Before you can submit a <b>Tier 1</b> request the mirror in question must first be a registered <b>Tier 2</b> 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.</p>

<form id="list-generator" method="get">
{{ submission_form1.as_div }}
{{ url1.as_div }}
{{ url2.as_div }}
{{ url3.as_div }}
{{ rsync.as_div }}
<p><label></label> <input type="submit" value="Submit Request" /></p>
</form>
{% else %}
<code>
Your request have successfully been submitted and should be visible within 5 minutes in the mirrorlist.
</code>
{% endif %}
</div>
{% endblock %}

0 comments on commit 7dc2168

Please sign in to comment.