Commit 74d1812e authored by Elger Jonker's avatar Elger Jonker

bugfixes, showing scans with new urls


Former-commit-id: 84e487e5
parent 4b1ed1a2
......@@ -51,6 +51,7 @@ class TeamForm(forms.Form):
def __init__(self, *args, **kwargs):
self.contest = kwargs.pop('contest', 0)
self.user = kwargs.pop('user', None)
super(TeamForm, self).__init__(*args, **kwargs)
self.fields['team'] = forms.ModelChoiceField(
widget=forms.RadioSelect,
......@@ -75,8 +76,16 @@ class TeamForm(forms.Form):
# it's possible NOT to select a team, in that case, don't try and validate secret.
if team:
try:
team = Team.objects.all().get(id=team.id, secret=secret,
allowed_to_submit_things=True, participating_in_contest=self.contest)
if has_permission('skip_team_secret', self.user):
return
team = Team.objects.all().get(
id=team.id,
secret=secret,
allowed_to_submit_things=True,
participating_in_contest=self.contest
)
except Team.DoesNotExist:
raise ValidationError(
_('Incorrect secret or team. Try again!'),
......@@ -84,6 +93,15 @@ class TeamForm(forms.Form):
)
def has_permission(permission_code, user):
if not user:
return False
if user.is_superuser and permission_code in ['skip_team_secret']:
return True
class OrganisationSubmissionForm(forms.Form):
contest = None
......@@ -306,7 +324,7 @@ class UrlSubmissionForm(forms.Form):
<ul>
<li>The following is all the same url (google.com):
https://google.com, https://www.google.com, http://nonsense.google.com, bla.nonsense.google.com,
google.com
GOOGLE.COM, www.google.com, google.com
</li>
<li>Subdomains and protocols are removed: the system will discover these.</li>
<li>Each address will be resolved to see if it exists. This can take a while.</li>
......@@ -350,6 +368,7 @@ class UrlSubmissionForm(forms.Form):
valid = []
for url in sites:
url = url.lower()
url = url.replace("https://", "")
url = url.replace("http://", "")
......
# Generated by Django 2.1.3 on 2018-12-06 10:39
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('game', '0017_contest_url_organization_discovery_help'),
]
operations = [
migrations.RemoveField(
model_name='contest',
name='logo_filename',
),
migrations.RemoveField(
model_name='contest',
name='website',
),
migrations.AddField(
model_name='organizationsubmission',
name='suggested_urls',
field=models.TextField(
blank=True, help_text='A set of or urls, comma separated that can be added when the organization was approved.', null=True),
),
migrations.AlterField(
model_name='contest',
name='name',
field=models.CharField(
help_text="Name of the contest, might be abbreviated, don't use long words.", max_length=42, verbose_name='Contest name'),
),
migrations.AlterField(
model_name='contest',
name='url_organization_discovery_help',
field=models.TextField(
blank=True, default='', help_text='HTML: information where contestants can find good sources of urls / organizations. Displayed on both the URL and Organization adding forms.', max_length=1024, null=True),
),
]
......@@ -17,17 +17,7 @@ class Contest(models.Model):
name = models.CharField(
verbose_name=_("Contest name"),
max_length=42,
help_text="Whatever name the team wants. Must be at least PEGI 88."
)
logo_filename = models.CharField(
max_length=255,
help_text="A nice filename for contest logos."
)
website = models.CharField(
max_length=255,
help_text="Whatever name the team wants. Must be at least PEGI 88."
help_text="Name of the contest, might be abbreviated, don't use long words."
)
from_moment = models.DateTimeField(
......@@ -50,7 +40,9 @@ class Contest(models.Model):
max_length=1024,
default="",
help_text="HTML: information where contestants can find good sources of urls / organizations. Displayed on"
" both the URL and Organization adding forms."
" both the URL and Organization adding forms.",
blank=True,
null=True,
)
admin_user = models.ForeignKey(
......@@ -197,6 +189,12 @@ class OrganizationSubmission(models.Model):
help_text="Automatically filled when creating a new submission."
)
suggested_urls = models.TextField(
help_text="A set of or urls, comma separated that can be added when the organization was approved.",
null=True,
blank=True,
)
def __str__(self):
if self.has_been_accepted:
return "OK: %s" % self.organization_name
......
{% load humanize %}
<table class="table table-sm table-striped table-bordered table-hover">
<thead>
<tr>
<th width="10%"></th>
<th width="30%">Name</th>
<th width="5%">Teams</th>
<th width="5%">Urls</th>
<th width="10%">Info</th>
<th width="20%">From</th>
<th width="20%">Until</th>
</tr>
</thead>
<tbody>
{% for a_contest in contests %}
<tr style="{% if a_contest.name == contest.name %} font-weight: bold; background-color: #ddffdd {% endif %}">
<td style="text-align: center;"><form method="POST">{% csrf_token %}<input type="hidden" name="id" value="{{ a_contest.id }}">
<input type="submit" value="join" class="btn btn-primary btn-lg"></form></td>
<td><img class="country-select-flag" id="{{ a_contest.target_country }}" style="margin: 6px 4px 0" src="/static/flags/{{ a_contest.target_country }}.gif">
{{ a_contest.name }}</td>
<td>{{ a_contest.teams }}</td>
<td>{{ a_contest.urls }}</td>
<td><a href="/game/scores/?contest={{ a_contest.id }}">view scores</a></td>
<td><span title="{{ a_contest.from_moment }}">{{ a_contest.from_moment|naturaltime }}</span></td>
<td><span title="{{ a_contest.until_moment }}">{{ a_contest.until_moment|naturaltime }}</span></td>
</tr>
{% empty %}
<tr><td colspan="7">No currently open contests.</td></tr>
{% endfor %}
</tbody>
</table>
\ No newline at end of file
{% extends 'game/base.html' %}
{% load crispy_forms_tags %}
{% load humanize %}
{% block content %}
......@@ -20,99 +19,14 @@
{% endif %}
<h2>Currently open</h2>
<table class="table table-sm table-striped table-bordered table-hover">
<thead>
<tr>
<th width="10%"></th>
<th width="30%">Name</th>
<th width="5%">Teams</th>
<th width="5%">Urls</th>
<th width="10%">Info</th>
<th width="20%">From</th>
<th width="20%">Until</th>
</tr>
</thead>
<tbody>
{% for a_contest in active_contests %}
<tr style="{% if a_contest.name == contest.name %} font-weight: bold; background-color: #ddffdd {% endif %}">
<td style="text-align: center;"><form method="POST">{% csrf_token %}<input type="hidden" name="id" value="{{ a_contest.id }}">
<input type="submit" value="join" class="btn btn-primary btn-lg"></form></td>
<td><img class="country-select-flag" id="{{ a_contest.target_country }}" style="margin: 6px 4px 0" src="/static/flags/{{ a_contest.target_country }}.gif">
{{ a_contest.name }}</td>
<td>{{ a_contest.teams }}</td>
<td>{{ a_contest.urls }}</td>
<td><a href="/game/scores/?contest={{ a_contest.id }}">view scores</a></td>
<td><span title="{{ a_contest.from_moment }}">{{ a_contest.from_moment|naturaltime }}</span></td>
<td><span title="{{ a_contest.until_moment }}">{{ a_contest.until_moment|naturaltime }}</span></td>
</tr>
{% empty %}
<tr><td colspan="7">No currently open contests.</td></tr>
{% endfor %}
</tbody>
</table>
{% include "game/contest_list.html" with contests=active_contests %}
<h2>Upcoming</h2>
<table class="table table-sm table-striped table-bordered table-hover">
<thead>
<tr>
<th width="10%"></th>
<th width="30%">Name</th>
<th width="5%">Teams</th>
<th width="5%">Urls</th>
<th width="10%">Info</th>
<th width="20%">From</th>
<th width="20%">Until</th>
</tr>
</thead>
<tbody>
{% for a_contest in future_contests %}
<tr style="{% if a_contest.name == contest.name %} font-weight: bold; background-color: #ddffdd {% endif %}">
<td style="text-align: center;"><form method="POST">{% csrf_token %}<input type="hidden" name="id" value="{{ a_contest.id }}">
<input type="submit" value="join" class="btn btn-primary btn-lg"></form></td>
<td><img class="country-select-flag" id="{{ a_contest.target_country }}" style="margin: 6px 4px 0" src="/static/flags/{{ a_contest.target_country }}.gif">
{{ a_contest.name }}</td>
<td>{{ a_contest.teams }}</td>
<td>{{ a_contest.urls }}</td>
<td><a href="/game/scores/?contest={{ a_contest.id }}">view scores</a></td>
<td><span title="{{ a_contest.from_moment }}">{{ a_contest.from_moment|naturaltime }}</span></td>
<td><span title="{{ a_contest.until_moment }}">{{ a_contest.until_moment|naturaltime }}</span></td>
</tr>
{% empty %}
<tr><td colspan="7">No upcoming contests.</td></tr>
{% endfor %}
</tbody>
</table>
{% include "game/contest_list.html" with contests=future_contests %}
<h2>Expired</h2>
<table class="table table-sm table-striped table-bordered table-hover">
<thead>
<tr>
<th width="10%"></th>
<th width="30%">Name</th>
<th width="5%">Teams</th>
<th width="5%">Urls</th>
<th width="10%">Info</th>
<th width="20%">From</th>
<th width="20%">Until</th>
</tr>
</thead>
<tbody>
{% for a_contest in expired_contests %}
<tr style="{% if a_contest.name == contest.name %} font-weight: bold; background-color: #ddffdd {% endif %}">
<td style="text-align: center;"><form method="POST">{% csrf_token %}<input type="hidden" name="id" value="{{ a_contest.id }}">
<input type="submit" value="join" class="btn btn-primary btn-lg"></form></td>
<td><img class="country-select-flag" id="{{ a_contest.target_country }}" style="margin: 6px 4px 0" src="/static/flags/{{ a_contest.target_country }}.gif">
{{ a_contest.name }}</td>
<td>{{ a_contest.teams }}</td>
<td>{{ a_contest.urls }}</td>
<td><a href="/game/scores/?contest={{ a_contest.id }}">view scores</a></td>
<td>{{ a_contest.from_moment }}</td>
<td>{{ a_contest.until_moment }}</td>
</tr>
{% empty %}
<tr><td colspan="7">No expired contests.</td></tr>
{% endfor %}
</tbody>
</table>
{% include "game/contest_list.html" with contests=expired_contests %}
{% endblock %}
......@@ -47,81 +47,9 @@
<h1>{{ contest.name }}</h1>
<br><br>
<h2>Submitted organizations</h2>
<p>This is a list of submitted organizations during this contest. Below it also shows the urls that already exist.
This information can help you to quickly determine if an organization is already being investigated and if some
information is still missing.</p>
{% for organization in submitted_organizations %}
{% ifchanged organization.organization_type_name %}
</tbody></table><h3>Layer: {{ organization.organization_type_name }}</h3><table class="table table-sm table-striped table-bordered table-hover">
<thead>
<tr>
<th width="20%">Organization</th>
<th width="30%">Address</th>
<th width="5%">Acceptation</th>
<th width="10%">Added on</th>
<th width="15%">Search</th>
</tr>
</thead><tbody>
{% endifchanged %}
<tr style="background-color: {{ organization.added_by_team.color }}33;" title="Added by {{ organization.added_by_team.name }}">
<td>{{ organization.organization_name }}</td>
<td>{{ organization.organization_address }}</td>
{% if organization.has_been_accepted %}
<td style="color: green;">accepted</td>
{% elif organization.has_been_rejected %}
<td style="color: red;">rejected</td>
{% else %}
<td style="color: gray;">pending</td>
{% endif %}
<td>{{ organization.added_on|naturaltime }}</td>
<td>
<a href="https://www.duckduckgo.com/?q={{ organization.organization_name }}" target="_blank">duckduckgo</a>,
<a href="https://www.google.com/search?q={{ organization.organization_name }}" target="_blank">google</a>
{% if contest.target_country == "NL" %}
<a href="https://www.kvk.nl/zoeken/?source=all&q={{ organization.organization_name }}" target="_blank">kvk</a>
{% endif %}
</td>
</tr>
{% empty %}
<tr><td colspan="7">-</td></tr>
{% endfor %}
</tbody>
</table>
{% include "game/submitted_organizations_list.html" %}
<br><br>
<h2>Submitted urls</h2>
{% for url in submitted_urls %}
{% ifchanged url.for_organization %}
</table><h3>{{ url.for_organization }}</h3><table class="table table-sm table-striped table-bordered table-hover">
<tr>
<th width="50%">Url</th>
<th width="10%">Acceptation</th>
<th width="30%">Added when</th>
<th width="10%">Onboarding</th>
</tr>
{% endifchanged %}
<tr style="background-color: {{ url.added_by_team.color }}33;" title="Added by {{ url.added_by_team.name }}">
<td>{{ url.url }} (try: <a href="http://{{ url.url }}" target="_blank">http</a>,
<a href="https://{{ url.url }}" target="_blank">https</a>)</td>
{% if url.has_been_accepted %}
<td style="color: green;">accepted</td>
{% elif url.has_been_rejected %}
<td style="color: red;">rejected</td>
{% else %}
<td style="color: gray;">pending</td>
{% endif %}
<td>{{ url.added_on|naturaltime }}</td>
<td>{{ url.onboarding_stage }}</td>
</tr>
{% empty %}
<tr><td colspan="7">-</td></tr>
{% endfor %}
</tbody>
</table>
{% include "game/submitted_urls_list.html" %}
{% endblock %}
......
{% extends 'game/base.html' %}
{% extends 'game/base.html' %}{% load humanize %}
{% block content %}
{% comment for="What is the origin of -?" %}{% endcomment %}
{% if team and team.name != "-" %}
<div class="alert alert-success" role="alert">
<p style="width: 100%; text-align: center;"><i>You are part of team: <span style="background-color: {{ team.color }}">{{ team.name | truncatechars:24 }}</span>,
<p style="width: 100%; text-align: center;"><i>You are part of team: <span style="background-color: {{ team.color }}">{{ team.name }}</span>,
{% for score in scores %} {% if team.name == score.team %} currently placed at <a href="#{{ forloop.counter }}">#{{ forloop.counter }}</a>. {% endif %} {% endfor %}</i>
<br>
<br>
......@@ -13,9 +13,9 @@
</div>
{% endif %}
<p style="width: 100%; text-align: center; font-size: 10vw;">{{ contest.name | truncatechars:16 }}</p>
<p style="width: 100%; text-align: center; font-size: 10vw;">{{ contest.name }}</p>
<p style="width: 100%; text-align: center; font-size: 2em;">Starts at {{ contest.from_moment }}. Deadline: {{ contest.until_moment }}.</p>
<p style="width: 100%; text-align: center; font-size: 2em;">Starts <abbr title="{{ contest.from_moment }}">{{ contest.from_moment | naturaltime }}</abbr>. Deadline: <abbr title="{{ contest.until_moment }}">{{ contest.until_moment | naturaltime }}</abbr>.</p>
{% for score in scores %}
<table class="table table-sm table-striped table-bordered table-hover"
......@@ -41,7 +41,7 @@
{% endif %}
">
<a name="{{ forloop.counter }}"></a># {{ forloop.counter }}</td></tr>
<tr><td colspan="3" style="font-size: 3em; text-align: center; background-color: {{ score.team_color }}; height: 160px; vertical-align: middle;">{{ score.team | truncatechars:24 }}</td></tr>
<tr><td colspan="3" style="font-size: 3em; text-align: center; background-color: {{ score.team_color }}; height: 160px; vertical-align: middle;">{{ score.team }}</td></tr>
<tr><td>Total score</td> <td colspan="2" style="text-align: center; font-size: 2em;">{{ score.total_score }}</td></tr>
<tr><td>Organizations</td> <td>{{ score.added_organizations }}</td><td><small>* {{ score.added_organizations_multiplier }} = {{ score.added_organizations_score }}</small></td></tr>
<tr><td><small>Rejected</small></td> <td><small>{{ score.rejected_organizations }}</small></td><td><small>* -{{ score.rejected_organizations_multiplier }} = -{{ score.rejected_organizations_score }}</small></td></tr>
......
......@@ -8,49 +8,7 @@
Current Contest: {{ contest.name }}
</p>
<h2>Submitted organizations</h2>
<p>This is a list of submitted organizations during this contest. Below it also shows the urls that already exist.
This information can help you to quickly determine if an organization is already being investigated and if some
information is still missing.</p>
{% for organization in submitted_organizations %}
{% ifchanged organization.organization_type_name %}
</tbody></table><h3>Layer: {{ organization.organization_type_name }}</h3><table class="table table-sm table-striped table-bordered table-hover">
<thead>
<tr>
<th width="20%">Organization</th>
<th width="30%">Address</th>
<th width="5%">Acceptation</th>
<th width="10%">Added on</th>
<th width="15%">Search</th>
</tr>
</thead><tbody>
{% endifchanged %}
<tr style="background-color: {{ organization.added_by_team.color }}33;" title="Added by {{ organization.added_by_team.name }}">
<td>{{ organization.organization_name }}</td>
<td>{{ organization.organization_address }}</td>
{% if organization.has_been_accepted %}
<td style="color: green;">accepted</td>
{% elif organization.has_been_rejected %}
<td style="color: red;">rejected</td>
{% else %}
<td style="color: gray;">pending</td>
{% endif %}
<td>{{ organization.added_on|naturaltime }}</td>
<td>
<a href="https://www.duckduckgo.com/?q={{ organization.organization_name }}" target="_blank">duckduckgo</a>,
<a href="https://www.google.com/search?q={{ organization.organization_name }}" target="_blank">google</a>
{% if contest.target_country == "NL" %}
<a href="https://www.kvk.nl/zoeken/?source=all&q={{ organization.organization_name }}" target="_blank">kvk</a>
{% endif %}
</td>
</tr>
{% empty %}
<tr><td colspan="7">-</td></tr>
{% endfor %}
</tbody>
</table>
{% include "game/submitted_organizations_list.html" %}
<h2>Already known organizations</h2>
<p>These organizations where already in the database before the contest started.</p>
......
{% load humanize %}
<h2>Submitted organizations</h2>
<p>This is a list of submitted organizations during this contest. Below it also shows the urls that already exist.
This information can help you to quickly determine if an organization is already being investigated and if some
information is still missing.</p>
{% for organization in submitted_organizations %}
{% ifchanged organization.organization_type_name %}
</tbody></table><h3>Layer: {{ organization.organization_type_name }}</h3><table class="table table-sm table-striped table-bordered table-hover">
<thead>
<tr>
<th width="20%">Organization (urls)</th>
<th width="30%">Address</th>
<th width="5%">Acceptation</th>
<th width="10%">Added on</th>
<th width="15%">Search</th>
</tr>
</thead><tbody>
{% endifchanged %}
<tr style="background-color: {{ organization.added_by_team.color }}33;" title="Added by {{ organization.added_by_team.name }}">
<td>{{ organization.organization_name }} {% if organization.has_been_accepted %}({{ organization.num_urls }}) {% else %} <span style="color: red">!!!</span>{% endif %}</td>
<td>{{ organization.organization_address }}</td>
{% if organization.has_been_accepted %}
<td style="color: green;">accepted</td>
{% elif organization.has_been_rejected %}
<td style="color: red;">rejected</td>
{% else %}
<td style="color: gray;">pending</td>
{% endif %}
<td>{{ organization.added_on|naturaltime }}</td>
<td>
<a href="https://www.duckduckgo.com/?q={{ organization.organization_name }}" target="_blank">duckduckgo</a>,
<a href="https://www.google.com/search?q={{ organization.organization_name }}" target="_blank">google</a>
{% if contest.target_country == "NL" %}
<a href="https://www.kvk.nl/zoeken/?source=all&q={{ organization.organization_name }}" target="_blank">kvk</a>
{% endif %}
</td>
</tr>
{% empty %}
<tr><td colspan="7">-</td></tr>
{% endfor %}
</tbody>
</table>
......@@ -12,36 +12,8 @@
Current Contest: {{ contest.name }}
</p>
<h2>Submitted urls</h2>
{% for url in submitted_urls %}
{% ifchanged url.for_organization %}
</table><h3>{{ url.for_organization }}</h3><table class="table table-sm table-striped table-bordered table-hover">
<tr>
<th width="50%">Url</th>
<th width="10%">Acceptation</th>
<th width="30%">Added when</th>
<th width="10%">Onboarding</th>
</tr>
{% endifchanged %}
{% include "game/submitted_urls_list.html" %}
<tr style="background-color: {{ url.added_by_team.color }}33;" title="Added by {{ url.added_by_team.name }}">
<td>{{ url.url }} (try: <a href="http://{{ url.url }}" target="_blank">http</a>,
<a href="https://{{ url.url }}" target="_blank">https</a>)</td>
{% if url.has_been_accepted %}
<td style="color: green;">accepted</td>
{% elif url.has_been_rejected %}
<td style="color: red;">rejected</td>
{% else %}
<td style="color: gray;">pending</td>
{% endif %}
<td>{{ url.added_on|naturaltime }}</td>
<td>{{ url.onboarding_stage }}</td>
</tr>
{% empty %}
<tr><td colspan="7">-</td></tr>
{% endfor %}
</tbody>
</table>
<br><br>
<h2>Accepted and Existing addresses</h2>
......@@ -50,6 +22,7 @@
<tr>
<th>Url</th>
<th>Organization</th>
<th>Links</th>
<th>Added</th>
<th>Onboarding</th>
</tr>
......@@ -57,12 +30,14 @@
<tbody>
{% for url in already_known_urls %}
<tr>
<td>{{ url.url }} (try: <a href="http://{{ url.url }}" target="_blank">http</a>,
<a href="https://{{ url.url }}" target="_blank">https</a>)</td>
<td>{{ url.url }}</td>
<td><a href="http://{{ url.url }}" target="_blank">http</a>, <a href="https://{{ url.url }}" target="_blank">https</a></td>
<td>{{ url.organization__name }} </td>
<td>{{ url.created_on|naturaltime }}</td>
<td>{{ url.onboarding_stage }}</td>
</tr>
{% empty %}
<tr><td colspan="7">-</td></tr>
{% endfor %}
......
{% load humanize %}{% load i18n %}
<h2>Submitted urls</h2>
{% for submitted_url in submitted_urls %}
{% ifchanged submitted_url.url.for_organization %}
</table><h3>{{ submitted_url.url.for_organization }}</h3><table class="table table-sm table-striped table-bordered table-hover">
<tr>
<th width="40%">Url</th>
<th width="10%">Try</th>
<th width="10%">Acceptation</th>
<th width="30%">Added when</th>
<th width="10%">Onboarding</th>
</tr>
{% endifchanged %}
<tr style="background-color: {{ submitted_url.url.added_by_team.color }}33;" title="Added by {{ submitted_url.url.added_by_team.name }}">
<td>{{ submitted_url.url.url }}</td>
<td><a href="http://{{ submitted_url.url.url }}" target="_blank">http</a>, <a href="https://{{ submitted_url.url.url }}" target="_blank">https</a></td>
{% if submitted_url.url.has_been_accepted %}
<td style="color: green;">accepted</td>
{% elif submitted_url.url.has_been_rejected %}
<td style="color: red;">rejected</td>
{% else %}
<td style="color: gray;">pending</td>
{% endif %}
<td>{{ submitted_url.url.added_on|naturaltime }}</td>
<td>{{ submitted_url.url.onboarding_stage }} {{ submitted_url.url.endpointscans }}</td>
</tr>
{% if submitted_url.url_scans or submitted_url.endpoint_scans %}
<tr style="font-size: 0.6em;"><td colspan="7"><div style="column-count: 3; -webkit-column-count: 3; -moz-column-count: 3;">
{% for scan in submitted_url.endpoint_scans %}
<div>{% trans scan.type %}: {{ scan.rating }}</div>
{% endfor %}
{% for scan in submitted_url.url_scans %}
<div>{% trans scan.type %}: {{ scan.rating }}</div>
{% endfor %}
</div></td></tr>
{% endif %}
{% empty %}
<tr><td colspan="7">-</td></tr>
{% endfor %}
</tbody>
</table>
\ No newline at end of file
......@@ -15,6 +15,7 @@ from django.db.utils import OperationalError
from django.http import JsonResponse
from django.shortcuts import redirect, render
from django.utils.text import slugify
from django.views.decorators.cache import cache_page
from failmap.app.common import JSEncoder
from failmap.game.forms import ContestForm, OrganisationSubmissionForm, TeamForm, UrlSubmissionForm
......@@ -122,6 +123,7 @@ def submit_organisation(request):
'contest': contest})
@cache_page(one_minute)
def scores(request):
# todo: this param handling code is absolutely disgusting, it should be more beautiful.
......@@ -270,6 +272,7 @@ def scores(request):
'menu_selected': 'scores'})
@cache_page(one_minute)
def contests(request):
if request.POST:
......@@ -329,11 +332,14 @@ def contests(request):
# todo: validate organizatio type name...
@cache_page(one_minute)
def submitted_organizations(request):
contest = get_default_contest(request)
submitted_organizations = OrganizationSubmission.objects.all().filter(
added_by_team__participating_in_contest=contest
).annotate(
num_urls=Count('organization_in_system__u_many_o_upgrade')
).order_by('organization_type_name', 'organization_name')
# not excluding the organizations submitted in this contest, as that IN filter will become too large.
......@@ -346,7 +352,7 @@ def submitted_organizations(request):
'contest': get_default_contest(request)})
# todo: contest required!
@cache_page(one_minute)
def submitted_urls(request):
"""
todo: overhaul to vue
......@@ -355,9 +361,7 @@ def submitted_urls(request):
"""
contest = get_default_contest(request)
submitted_urls = UrlSubmission.objects.all().filter(
added_by_team__participating_in_contest=contest).order_by(
'for_organization', '-added_on', 'url').select_related('added_by_team', 'for_organization', 'url_in_system')
submitted_urls = get_submitted_urls(contest)
# sqlite, when there is a NULL in the IN query, the set is NULL and you'll get nothing back.
# subdomains are irrellevant given contestants cannot add them.
......@@ -381,30 +385,107 @@ def rules_help(request):
return render(request, 'game/rules_help.html')
@login_required(login_url='/authentication/login/')
@cache_page(one_minute)
def map(request):
contest = get_default_contest(request)
# also enrich with submitted urls and orgnaizations
submitted_organizations = OrganizationSubmission.objects.all().filter(
added_by_team__participating_in_contest=contest
).annotate(
num_urls=Count('organization_in_system__u_many_o_upgrade')
).order_by('organization_type_name', 'organization_name')
submitted_urls = UrlSubmission.objects.all().filter(
added_by_team__participating_in_contest=contest).order_by(
'for_organization', '-added_on', 'url'
).select_related('added_by_team', 'for_organization', 'url_in_system')
return render(request, 'game/map.html', {
'contest': contest,
'team': get_team_info(request),
'submitted_urls': submitted_urls,
'submitted_organizations': submitted_organizations
'submitted_urls': get_submitted_urls(contest),
'submitted_organizations': submitted_organizations,
})
@login_required(login_url='/authentication/login/')
def get_submitted_urls(contest):
# Don't use to_attr or prefetch related, as it is not maintainable code and i could not get it to work at all for
# hours. which was such a waste.
submitted_urls = UrlSubmission.objects.all().filter(
added_by_team__participating_in_contest=contest).order_by(
'for_organization', '-added_on', 'url'
).select_related(
'added_by_team', 'for_organization', 'url_in_system',
)
# here are some example attempts:
# .prefetch_related(
# Prefetch(
# 'url_in_system__url__urlgenericscan',
# queryset=UrlGenericScan.objects.filter(
# rating_determined_on__lte=contest.until_moment),
# to_attr='urlscans'
# ),
# https://stackoverflow.com/questions/27116770/prefetch-related-for-multiple-levels
# Prefetch(
# 'url_in_system__endpoint_set',
# queryset=Endpoint.objects.prefetch_related(
# Prefetch(