Verified Commit f3d8ae26 authored by Elger Jonker's avatar Elger Jonker

[WIP] support for multiple urls at the same time (needs to be handled), small fixes

parent 4e56c02a
......@@ -13,6 +13,7 @@ from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from django_countries.fields import CountryField
from django_countries.widgets import CountrySelectWidget
from django_select2.forms import Select2TagWidget
from mapwidgets.widgets import GooglePointFieldWidget
from import Contest, OrganizationSubmission, Team, UrlSubmission
......@@ -197,6 +198,10 @@ class OrganisationSubmissionForm(forms.Form):
class UrlSubmissionForm(forms.Form):
field_order = ('country', 'organization_type_name', 'for_organization', 'url',)
Disabled the country filters as it should be obvious from the organization result what type and country the
value is in.
country = CountryField().formfield(
label="🔍 Filter organization by country",
......@@ -211,21 +216,45 @@ class UrlSubmissionForm(forms.Form):
help_text="This only helps finding the correct organization."
for_organization = forms.ModelMultipleChoiceField(
forward=['organization_type_name', 'country']),
help_text="Only approved organization are shown in this list. If your submitted organization is missing, please"
" ask the competition manager to verify your organization."
"<li>If you can't find the organization, try the abbreviated name.</li>"
"<li>You can also search for organization type, and it's name at the same time.</li>"
"<li>A list of all approved organizations is shown <a href='/game/submitted_organizations/'>"
"<li>If your newly added organization is missing, please ask the competition host to verify your "
"<li>Urls entered below will be added to all organizations selected here.</li>"
url = forms.CharField(
# finding this took me two hours :) but it's still faster than developing it yourself.
websites = forms.ModelMultipleChoiceField(
"<li>You can enter multiple sites at once using comma's or spaces as a delimiter. Example: The value "
"<i>,, </i> should by copy-pasting.</li>"
"<li>The url will be added to all organizations selected above, be careful.</li>"
def clean_url(self):
def clean_websites(self):
return ""
def clean_website(self):
url = self.cleaned_data['url']
url = url.replace("https://", "")
......@@ -21,7 +21,7 @@
{% comment "Find out how to re-use a list." %}
{% endcomment %}
<h2>Currently active</h2>
<h2>Currently open</h2>
<table class="table">
......@@ -4,6 +4,15 @@
{% block content %}
tags: true,
tokenSeparators: [',', ' ']
{% if success %}
<div class="alert alert-success" role="alert">
<strong>URL added!</strong> {{ url }} has been added!
......@@ -20,14 +29,12 @@
<h1>Suggest a new url</h1>
It's possible to submit an URL to multiple organizations.
The country and organization type fields can be useful to more easily find the organization you're looking for.
It is possible to submit multiple urls to multiple organizations. Make sure that the added information is correct,
so that you don't bulk-submit a lot of urls for the wrong organization and vice versa.
<form method="POST" class="uniForm">{% csrf_token %}
{{ form | crispy }}
<br />
<button type="submit" class="save btn btn-lg btn-primary">DO THE THING</button>
<button type="submit" class="save btn btn-lg btn-primary">Yes, the information above is correct.</button>
{% endblock %}
......@@ -5,6 +5,7 @@ import pytz
from dal import autocomplete
from django.contrib.auth.decorators import login_required
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Q
from django.db.utils import OperationalError
from django.shortcuts import redirect, render
from django.views.decorators.cache import cache_page
......@@ -354,8 +355,21 @@ class OrganizationAutocomplete(autocomplete.Select2QuerySetView):
if country:
qs = qs.filter(country=country)
if self.q:
qs = qs.filter(name__istartswith=self.q)
Do not search on a single character, it will give too many results. Two characters is a minimum.
if not self.q or len(self.q) < 3:
return qs
You can also search for organization type, which helps if you know the object is of a certain type.
It even supports multiple words, if you have a space, each word will be searched for. Up to three words...
if len(self.q.split(" ")) < 4:
for query in self.q.split(" "):
qs = qs.filter(Q(name__icontains=query) | Q(type__name__icontains=query))
qs = qs.filter(name__icontains=self.q)
return qs
......@@ -373,6 +387,6 @@ class OrganizationTypeAutocomplete(autocomplete.Select2QuerySetView):
# qs = qs.filter(organization__country=country)
if self.q:
qs = qs.filter(name__istartswith=self.q)
qs = qs.filter(name__icontains=self.q)
return qs
......@@ -107,6 +107,7 @@ INSTALLED_APPS = [
# others:
# 'mapwidgets', no gdal available yet, try again later
# 'cachalot', # query cache, is not faster.
......@@ -109,6 +109,7 @@ lxml
django-colorful # game team colors
django-select2 # game, add multiple urls in one go.
# function caching / query caching for slow stats graphs queries
# another way has to be found, but until then
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment