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 failmap.game.models 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",
required=False,
......@@ -211,21 +216,45 @@ class UrlSubmissionForm(forms.Form):
required=False,
help_text="This only helps finding the correct organization."
)
"""
for_organization = forms.ModelMultipleChoiceField(
label="Organizations",
queryset=Organization.objects.all(),
widget=autocomplete.ModelSelect2Multiple(
url='/game/autocomplete/organization-autocomplete/',
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."
help_text="Hints:"
"<ul>"
"<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/'>"
"here</a></li>"
"<li>If your newly added organization is missing, please ask the competition host to verify your "
"organization.</li>"
"<li>Urls entered below will be added to all organizations selected here.</li>"
"</ul>"
)
url = forms.CharField(
help_text=""
# https://github.com/applegrew/django-select2/issues/33
# finding this took me two hours :) but it's still faster than developing it yourself.
websites = forms.ModelMultipleChoiceField(
queryset=Url.objects.all(),
widget=Select2TagWidget,
label="Websites",
help_text="Hints:"
"<ul>"
"<li>You can enter multiple sites at once using comma's or spaces as a delimiter. Example: The value "
"<i>failmap.org, microsoft.com, apple.com </i> should by copy-pasting.</li>"
"<li>The url will be added to all organizations selected above, be careful.</li>"
"</ul>"
)
def clean_url(self):
def clean_websites(self):
log.debug(self.cleaned_data['websites'])
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">
<thead>
<tr>
......
......@@ -4,6 +4,15 @@
{% block content %}
<script>
$(".js-example-tokenizer").select2({
tags: true,
tokenSeparators: [',', ' ']
})
</script>
{% 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>
<p>
It's possible to submit an URL to multiple organizations.
</p>
<p>
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.
</p>
<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>
</form>
{% 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))
else:
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 = [
'mapwidgets',
'colorful',
'django_select2',
# others:
# 'mapwidgets', no gdal available yet, try again later
# 'cachalot', # query cache, is not faster.
......
......@@ -109,6 +109,7 @@ lxml
six
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
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment