Skip to content

Commit ad3b182

Browse files
committed
Created the view for submitting mirrors
1 parent 5c5a455 commit ad3b182

File tree

5 files changed

+155
-3
lines changed

5 files changed

+155
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local_settings.py
66
archweb.db
77
archweb.db-*
88
database.db
9+
/*.tar.gz
910
tags
1011
collected_static/
1112
testing/

mirrors/urls_mirrorlist.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
urlpatterns = [
55
path('', views.generate_mirrorlist, name='mirrorlist'),
6+
path('submit/', views.submit_mirror, name='mirrorsubmit'),
67
re_path(r'^all/$', views.find_mirrors, {'countries': ['all']}),
78
re_path(r'^all/(?P<protocol>[A-z]+)/$', views.find_mirrors_simple, name='mirrorlist_simple')
89
]

mirrors/views/mirrorlist.py

Lines changed: 118 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,104 @@
22

33
from django import forms
44
from django.db.models import Q
5-
from django.forms.widgets import SelectMultiple, CheckboxSelectMultiple
5+
from django.forms.widgets import (
6+
Select,
7+
SelectMultiple,
8+
CheckboxSelectMultiple,
9+
TextInput,
10+
EmailInput
11+
)
612
from django.shortcuts import get_object_or_404, redirect, render
713
from django.views.decorators.csrf import csrf_exempt
814
from django_countries import countries
915

10-
from ..models import MirrorUrl, MirrorProtocol
16+
from ..models import Mirror, MirrorUrl, MirrorProtocol
1117
from ..utils import get_mirror_statuses
1218

1319
import random
1420

1521

22+
# This is populated later, and re-populated every refresh
23+
# This was the only way to get 3 different examples without
24+
# changing the models.py
25+
url_examples = []
26+
27+
28+
class MirrorRequestForm(forms.ModelForm):
29+
upstream = forms.ModelChoiceField(
30+
queryset=Mirror.objects.filter(tier__gte=0, tier__lte=1),
31+
required=False)
32+
33+
class Meta:
34+
model = Mirror
35+
fields = ('name', 'tier', 'upstream', 'admin_email', 'alternate_email',
36+
'isos', 'rsync_user', 'rsync_password', 'notes')
37+
38+
def __init__(self, *args, **kwargs):
39+
super(MirrorRequestForm, self).__init__(*args, **kwargs)
40+
fields = self.fields
41+
fields['name'].widget.attrs.update({'placeholder': 'Ex: mirror.argentina.co'})
42+
fields['rsync_user'].widget.attrs.update({'placeholder': 'Optional'})
43+
fields['rsync_password'].widget.attrs.update({'placeholder': 'Optional'})
44+
fields['notes'].widget.attrs.update({'placeholder': 'Ex: Hosted by ISP GreatISO.bg'})
45+
46+
def as_div(self):
47+
"Returns this form rendered as HTML <divs>s."
48+
return self._html_output(
49+
normal_row=u'<div%(html_class_attr)s>%(label)s %(field)s%(help_text)s</div>',
50+
error_row=u'%s',
51+
row_ender='</div>',
52+
help_text_html=u' <span class="helptext">%s</span>',
53+
errors_on_separate_row=True)
54+
55+
56+
class MirrorUrlForm(forms.ModelForm):
57+
class Meta:
58+
model = MirrorUrl
59+
fields = ('url', 'country', 'bandwidth', 'active')
60+
61+
def __init__(self, *args, **kwargs):
62+
global url_examples
63+
64+
super(MirrorUrlForm, self).__init__(*args, **kwargs)
65+
fields = self.fields
66+
67+
if len(url_examples) == 0:
68+
url_examples = [
69+
'Ex: http://mirror.argentina.co/archlinux',
70+
'Ex: https://mirror.argentina.co/archlinux',
71+
'Ex: rsync://mirror.argentina.co/archlinux'
72+
]
73+
74+
fields['url'].widget.attrs.update({'placeholder': url_examples.pop()})
75+
76+
def clean_url(self):
77+
# is this a valid-looking URL?
78+
url_parts = urlparse(self.cleaned_data["url"])
79+
if not url_parts.scheme:
80+
raise forms.ValidationError("No URL scheme (protocol) provided.")
81+
if not url_parts.netloc:
82+
raise forms.ValidationError("No URL host provided.")
83+
if url_parts.params or url_parts.query or url_parts.fragment:
84+
raise forms.ValidationError(
85+
"URL parameters, query, and fragment elements are not supported.")
86+
# ensure we always save the URL with a trailing slash
87+
path = url_parts.path
88+
if not path.endswith('/'):
89+
path += '/'
90+
url = urlunsplit((url_parts.scheme, url_parts.netloc, path, '', ''))
91+
return url
92+
93+
def as_div(self):
94+
"Returns this form rendered as HTML <divs>s."
95+
return self._html_output(
96+
normal_row=u'<div%(html_class_attr)s>%(label)s %(field)s%(help_text)s</div>',
97+
error_row=u'%s',
98+
row_ender='</div>',
99+
help_text_html=u' <span class="helptext">%s</span>',
100+
errors_on_separate_row=True)
101+
102+
16103
class MirrorlistForm(forms.Form):
17104
country = forms.MultipleChoiceField(required=False, widget=SelectMultiple(attrs={'size': '12'}))
18105
protocol = forms.MultipleChoiceField(required=False, widget=CheckboxSelectMultiple)
@@ -127,4 +214,33 @@ def find_mirrors_simple(request, protocol):
127214
proto = get_object_or_404(MirrorProtocol, protocol=protocol)
128215
return find_mirrors(request, protocols=[proto])
129216

217+
def submit_mirror(request):
218+
# if request.method == 'POST' or len(request.GET) > 0:
219+
# data = request.POST if request.method == 'POST' else request.GET
220+
# form1 = MirrorUrlForm(data=data)
221+
# if form.is_valid():
222+
# countries = form.cleaned_data['country']
223+
# protocols = form.cleaned_data['protocol']
224+
# use_status = form.cleaned_data['use_mirror_status']
225+
# ipv4 = '4' in form.cleaned_data['ip_version']
226+
# ipv6 = '6' in form.cleaned_data['ip_version']
227+
# return find_mirrors(request, countries, protocols,
228+
# use_status, ipv4, ipv6)
229+
# else:
230+
form1 = MirrorRequestForm()
231+
url1 = MirrorUrlForm()
232+
url2 = MirrorUrlForm()
233+
url3 = MirrorUrlForm()
234+
235+
return render(
236+
request,
237+
'mirrors/mirror_submit.html',
238+
{
239+
'submission_form1': form1,
240+
'url1': url1,
241+
'url2': url2,
242+
'url3': url3
243+
}
244+
)
245+
130246
# vim: set ts=4 sw=4 et:

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-e git+git://github.com/fredj/cssmin.git@master#egg=cssmin
1+
cssmin==0.2.0
22
Django==4.0.1
33
IPy==1.1
44
Markdown==3.3.4
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{% extends "base.html" %}
2+
{% load package_extras %}
3+
{% block title %}Arch Linux - Pacman Mirrorlist Generator{% endblock %}
4+
5+
{% block content %}
6+
<div id="mirrorlist-gen" class="box">
7+
8+
<h2>Mirror Request</h2>
9+
10+
<p>This page is meant as a replacement of the old way of registring as a Tier 1 or Tier 2 mirror. Previously this was done through <a href="https://bugs.archlinux.org/index.php?string=&project=1&search_name=&type%5B%5D=&sev%5B%5D=&pri%5B%5D=&due%5B%5D=&reported%5B%5D=&cat%5B%5D=43&status%5B%5D=open&percent%5B%5D=&opened=&dev=&closed=&duedatefrom=&duedateto=&changedfrom=&changedto=&openedfrom=&openedto=&closedfrom=&closedto=&do=index">https://bugs.archlinux.org</a> and would require manual intervention from the mirror maintainer(s). This process is now semi-automated and various checks against your mirror will be performed when submitting via the below form.</p>
11+
12+
<h3>Available mirrors</h3>
13+
14+
<p>Below are direct links to the two different tiers you will need to be acquainted with.<p>
15+
16+
<ul>
17+
<li><a href="/mirrors/tier/1/">Tier 1 mirrors</a></li>
18+
<li><a href="/mirrors/tier/2/">Tier 2 mirrors</a></li>
19+
</ul>
20+
21+
<h3>Mirror information</h3>
22+
23+
<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>
24+
25+
<form id="list-generator" method="get">
26+
{{ submission_form1.as_div }}
27+
{{ url1.as_div }}
28+
{{ url2.as_div }}
29+
{{ url3.as_div }}
30+
<p><label></label> <input type="submit" value="Submit Request" /></p>
31+
</form>
32+
</div>
33+
{% endblock %}
34+

0 commit comments

Comments
 (0)