|
19 | 19 |
|
20 | 20 | import random
|
21 | 21 |
|
22 |
| - |
23 | 22 | # This is populated later, and re-populated every refresh
|
24 | 23 | # This was the only way to get 3 different examples without
|
25 | 24 | # changing the models.py
|
@@ -234,41 +233,64 @@ def find_mirrors_simple(request, protocol):
|
234 | 233 | proto = get_object_or_404(MirrorProtocol, protocol=protocol)
|
235 | 234 | return find_mirrors(request, protocols=[proto])
|
236 | 235 |
|
| 236 | + |
237 | 237 | def submit_mirror(request):
|
238 | 238 | if request.method == 'POST' or len(request.GET) > 0:
|
239 | 239 | data = request.POST if request.method == 'POST' else request.GET
|
240 |
| - |
241 |
| - form1 = MirrorRequestForm(data=data) |
242 |
| - url1 = MirrorUrlForm(data=data) |
243 |
| - url2 = MirrorUrlForm(data=data) |
244 |
| - url3 = MirrorUrlForm(data=data) |
245 |
| - rsync = MirrorRsyncForm(data=data) |
246 |
| - |
247 |
| - if form1.is_valid() and url1.is_valid() and url2.is_valid() and url3.is_valid() and rsync.is_valid(): |
248 |
| - print("Successful") |
249 |
| - # countries = form.cleaned_data['country'] |
250 |
| - # protocols = form.cleaned_data['protocol'] |
251 |
| - # use_status = form.cleaned_data['use_mirror_status'] |
252 |
| - # ipv4 = '4' in form.cleaned_data['ip_version'] |
253 |
| - # ipv6 = '6' in form.cleaned_data['ip_version'] |
254 |
| - # return find_mirrors(request, countries, protocols, |
255 |
| - # use_status, ipv4, ipv6) |
| 240 | + |
| 241 | + mirror_form = MirrorRequestForm(data=data) |
| 242 | + mirror_url1_form = MirrorUrlForm(data={ |
| 243 | + "url": data.get("url1-url", None), |
| 244 | + "country": data.get("url1-country", None), |
| 245 | + "bandwidth": data.get("url1-bandwidth", None), |
| 246 | + "active": data.get("url1-active", None)}) |
| 247 | + mirror_url2_form = MirrorUrlForm(data={ |
| 248 | + "url": data.get("url2-url", None), |
| 249 | + "country": data.get("url2-country", None), |
| 250 | + "bandwidth": data.get("url2-bandwidth", None), |
| 251 | + "active": data.get("url2-active", None)}) |
| 252 | + mirror_url3_form = MirrorUrlForm(data={ |
| 253 | + "url": data.get("url3-url", None), |
| 254 | + "country": data.get("url3-country", None), |
| 255 | + "bandwidth": data.get("url3-bandwidth", None), |
| 256 | + "active": data.get("url3-active", None)}) |
| 257 | + rsync_form = MirrorRsyncForm(data=data) |
| 258 | + |
| 259 | + if mirror_form.is_valid() \ |
| 260 | + and mirror_url1_form.is_valid() \ |
| 261 | + and mirror_url2_form.is_valid() \ |
| 262 | + and mirror_url3_form.is_valid() \ |
| 263 | + and rsync_form.is_valid(): |
| 264 | + # TODO make this in a transaction |
| 265 | + mirror = mirror_form.save() |
| 266 | + mirror_url1 = mirror_url1_form.save(commit=False) |
| 267 | + mirror_url2 = mirror_url2_form.save(commit=False) |
| 268 | + mirror_url3 = mirror_url3_form.save(commit=False) |
| 269 | + rsync = rsync_form.save(commit=False) |
| 270 | + mirror_url1.mirror = mirror |
| 271 | + mirror_url1.save() |
| 272 | + mirror_url2.mirror = mirror |
| 273 | + mirror_url2.save() |
| 274 | + mirror_url3.mirror = mirror |
| 275 | + mirror_url3.save() |
| 276 | + rsync.mirror = mirror |
| 277 | + rsync.save() |
256 | 278 | else:
|
257 |
| - form1 = MirrorRequestForm() |
258 |
| - url1 = MirrorUrlForm() |
259 |
| - url2 = MirrorUrlForm() |
260 |
| - url3 = MirrorUrlForm() |
261 |
| - rsync = MirrorRsyncForm() |
| 279 | + mirror_form = MirrorRequestForm() |
| 280 | + mirror_url1_form = MirrorUrlForm(prefix="url1") |
| 281 | + mirror_url2_form = MirrorUrlForm(prefix="url2") |
| 282 | + mirror_url3_form = MirrorUrlForm(prefix="url3") |
| 283 | + rsync_form = MirrorRsyncForm() |
262 | 284 |
|
263 | 285 | return render(
|
264 | 286 | request,
|
265 | 287 | 'mirrors/mirror_submit.html',
|
266 | 288 | {
|
267 |
| - 'submission_form1': form1, |
268 |
| - 'url1': url1, |
269 |
| - 'url2': url2, |
270 |
| - 'url3': url3, |
271 |
| - 'rsync' : rsync |
| 289 | + 'submission_form1': mirror_form, |
| 290 | + 'url1': mirror_url1_form, |
| 291 | + 'url2': mirror_url2_form, |
| 292 | + 'url3': mirror_url3_form, |
| 293 | + 'rsync': rsync_form |
272 | 294 | }
|
273 | 295 | )
|
274 | 296 |
|
|
0 commit comments