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

more bugfixes, quality of life fixes

parent 84e487e5
......@@ -171,6 +171,33 @@ class GroupResource(resources.ModelResource):
model = Group
def generate_game_user():
game_user_number = User.objects.all().filter(username__contains="game_user_").count()
game_user_number += 1
password = ''.join(choice("ACDEFGHKLMNPRSTUVWXZ234567") for i in range(20))
password = "%s-%s-%s-%s-%s" % (password[0:4], password[4:8], password[8:12], password[12:16], password[16:20])
user = User.objects.create_user(username="game_user_%s" % game_user_number,
# can log into other things
is_active=True,
# No access to admin interface needed
is_staff=False,
# No permissions needed anywhere
is_superuser=False,
password=password)
user.save()
# store the password to this account in plain text. It doesn't have any permissions so well...
# in django we trust :)
game_user = GameUser()
game_user.user = user
game_user.password = password
game_user.save()
return user
class UserAdmin(BaseUserAdmin, ImportExportModelAdmin):
resource_class = UserResource
inlines = (VolunteerInline, GameUserInline)
......@@ -181,29 +208,7 @@ class UserAdmin(BaseUserAdmin, ImportExportModelAdmin):
actions = []
def add_game_user(self, request, queryset):
game_user_number = User.objects.all().filter(username__contains="game_user_").count()
game_user_number += 1
password = ''.join(choice("ACDEFGHKLMNPRSTUVWXZ234567") for i in range(20))
password = "%s-%s-%s-%s-%s" % (password[0:4], password[4:8], password[8:12], password[12:16], password[16:20])
user = User.objects.create_user(username="game_user_%s" % game_user_number,
# can log into other things
is_active=True,
# No access to admin interface needed
is_staff=False,
# No permissions needed anywhere
is_superuser=False,
password=password)
user.save()
# store the password to this account in plain text. It doesn't have any permissions so well...
# in django we trust :)
game_user = GameUser()
game_user.user = user
game_user.password = password
game_user.save()
generate_game_user()
self.message_user(request, "Game user added, rename if needed!")
add_game_user.short_description = '💖 Add Game User (select a user first)'
......
import logging
import re
import urllib
from datetime import datetime, timedelta
from random import choice, choices, randint
import pytz
from constance import config
from django.contrib import admin
from django.db import transaction
......@@ -11,6 +13,7 @@ from django.utils.safestring import mark_safe
from import_export.admin import ImportExportModelAdmin
from jet.admin import CompactInline
from failmap.app.admin import generate_game_user
from failmap.app.models import GameUser
from failmap.game.models import Contest, OrganizationSubmission, Team, UrlSubmission
from failmap.organizations.models import Coordinate, Organization, OrganizationType, Url
......@@ -57,29 +60,41 @@ class ContestAdmin(ImportExportModelAdmin, admin.ModelAdmin):
fieldsets = (
(None, {
'fields': ('name', 'from_moment', 'until_moment')
'fields': ('name', 'from_moment', 'until_moment'),
'description': "<span style='color: red'>"
"Don't forget to disable subdomain discovery AND to onboard every 1 minute.</span>"
}),
('Configuration', {
'fields': ('target_country', 'url_organization_discovery_help', 'admin_user', 'logo_filename'),
'fields': ('target_country', 'url_organization_discovery_help', 'admin_user'),
}),
)
actions = []
@transaction.atomic
def add_contest(self, request, queryset):
# create a new contest
contest = Contest()
contest.target_country = "NL"
contest.from_moment = datetime.now(pytz.utc)
contest.until_moment = datetime.now(pytz.utc) + timedelta(days=3)
contest.admin_user = generate_game_user()
contest.name = "new_contest_%s" % datetime.now(pytz.utc).date()
contest.save()
# create a number of team members.
for i in range(12):
generate_team(contest)
self.message_user(request, "Contest user, contest and teams have been created.")
add_contest.short_description = "Add contest (select one)"
actions.append('add_contest')
@transaction.atomic
def add_a_dozen_teams(self, request, queryset):
for contest in queryset:
make_teams = 12
team_counter = 0
while team_counter < make_teams:
team_counter += 1
new_team = Team()
new_team.name = generate_team_name()
new_team.color = generate_pastel_color()
new_team.participating_in_contest = contest
new_team.secret = generate_team_password()
new_team.allowed_to_submit_things = True
new_team.save()
for i in range(12):
generate_team(contest)
self.message_user(request, "Urls have been rejected.")
add_a_dozen_teams.short_description = "Add 12 teams"
......@@ -99,6 +114,16 @@ class ContestAdmin(ImportExportModelAdmin, admin.ModelAdmin):
inlines = [TeamInline]
def generate_team(contest):
new_team = Team()
new_team.name = generate_team_name()
new_team.color = generate_pastel_color()
new_team.participating_in_contest = contest
new_team.secret = generate_team_password()
new_team.allowed_to_submit_things = True
new_team.save()
def create_printout(contest):
login_url = "%s/game/" % config.PROJECT_WEBSITE
game_url = "%s/game/scores/" % config.PROJECT_WEBSITE
......@@ -374,7 +399,8 @@ class UrlSubmissionAdmin(ImportExportModelAdmin, admin.ModelAdmin):
@admin.register(OrganizationSubmission)
class OrganizationSubmissionAdmin(ImportExportModelAdmin, admin.ModelAdmin):
list_display = ('added_by_team', 'organization_name', 'has_been_accepted', 'has_been_rejected', 'added_on')
list_display = ('added_by_team', 'organization_name', 'organization_type_name',
'has_been_accepted', 'has_been_rejected', 'added_on')
search_fields = ('added_by_team__name', 'organization_name', 'organization_type_name')
list_filter = ('added_by_team__name', 'has_been_accepted', 'has_been_rejected',
......@@ -382,8 +408,8 @@ class OrganizationSubmissionAdmin(ImportExportModelAdmin, admin.ModelAdmin):
fields = ('added_by_team', 'organization_country', 'organization_type_name', 'organization_name',
'organization_address', 'organization_address_geocoded', 'organization_wikipedia',
'organization_wikidata_code', 'has_been_accepted',
'has_been_rejected', 'organization_in_system', 'added_on',)
'organization_wikidata_code', 'suggested_urls',
'has_been_accepted', 'has_been_rejected', 'organization_in_system', 'added_on',)
actions = []
......
......@@ -166,6 +166,14 @@ class OrganisationSubmissionForm(forms.Form):
help_text=""
)
suggested_urls = forms.CharField(
widget=Select2TagWidget,
label="Comma separated list of urls that you want to add to this organization when the organization has been"
" accepted.",
required=False,
help_text=""
)
# todo: clean the geolocated address to fit the rest of the system.
def clean(self):
......@@ -217,6 +225,7 @@ class OrganisationSubmissionForm(forms.Form):
organization_wikidata = self.cleaned_data.get('organization_wikidata', None)
organization_type_name = self.cleaned_data.get('organization_type_name', None)
organization_evidence = self.cleaned_data.get('organization_evidence', None)
organization_suggested_urls = self.cleaned_data.get('suggested_urls', None)
submission = OrganizationSubmission(
added_by_team=Team.objects.get(pk=team),
......@@ -228,6 +237,7 @@ class OrganisationSubmissionForm(forms.Form):
organization_wikidata_code=organization_wikidata,
organization_address_geocoded=[lng, lat],
organization_country=organization_country,
suggested_urls=organization_suggested_urls,
added_on=timezone.now(),
has_been_accepted=False,
has_been_rejected=False
......@@ -265,8 +275,9 @@ class UrlSubmissionForm(forms.Form):
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>The format displayed is: name / layer (creation date)</li>
<li>It's possible to search by layer, to see all organizations on this layer.</li>
<li>If you can't find the organization, try The Abbreviated Name (TAN).</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
......
{% extends 'game/base.html' %}
{% load crispy_forms_tags %} {% load my_tags %}
{% block content %}
<script>
// tabs are not supported: https://github.com/select2/select2/issues/3359
$(".js-example-tokenizer").select2({
tags: true,
tokenSeparators: [',', ' ', ';']
});
</script>
<style>
.searchResults {
padding: 20px 0 50px;
......
......@@ -549,7 +549,7 @@ def contest_map_data(request):
has_been_accepted=False,
has_been_rejected=False,
added_by_team__participating_in_contest=contest.pk
))
).distinct())
for bare_organization in bare_organizations:
features.append(get_bare_organization_feature(bare_organization))
......@@ -569,7 +569,7 @@ def contest_map_data(request):
organization_in_system__u_many_o_upgrade__urlgenericscan__isnull=True,
organization_in_system__u_many_o_upgrade__endpoint__endpointgenericscan__isnull=True,
added_by_team__participating_in_contest=contest.pk
))
).distinct())
# todo: this can have the real ID, real mapping information.
for bare_organization in bare_organizations:
......
......@@ -678,6 +678,7 @@ th.active .arrow {
/* Markers with CSS only, no (slow) images, and easy to change color. */
.leaflet-marker-red
{
background-color: rgba(255,0,0,0.6);
......@@ -720,8 +721,8 @@ th.active .arrow {
.leaflet-marker-gray
{
background-color: rgba(255, 248, 241, 0.6);
border: 2px solid rgba(178, 179, 178, 0.5);
background-color: rgba(0, 88, 255, 0.6);
border: 2px solid rgba(0, 68, 179, 0.5);
font-weight: bold;
text-align: center;
border-radius: 50%;
......
.marker-cluster-unknown {
background-color: rgba(226, 225, 213, 0.6);
background-color: rgba(115, 157, 226, 0.6);
}
.marker-cluster-unknown div {
background-color: rgba(200, 204, 197, 0.6);
background-color: rgba(56, 99, 204, 0.6);
}
.marker-cluster-green {
......
......@@ -108,11 +108,21 @@ class Organization(models.Model):
verbose_name_plural = _('organizations')
# todo: find a smarter way to get the organization type name, instead of a related query... cached enums?
# this list resets per restart. So if you do complex changes in these layers / types...
organization_name_cache = {}
def __str__(self):
if self.type_id not in self.organization_name_cache:
log.debug("caching...")
self.organization_name_cache[self.type_id] = self.type.name
type_label = self.organization_name_cache[self.type_id]
if self.is_dead:
return "✝ %s, %s/%s (%s)" % (self.name, self.country, self.type_id, self.created_on.strftime("%b %Y"))
return "✝ %s, %s/%s (%s)" % (self.name, self.country, type_label, self.created_on.strftime("%b %Y"))
else:
return "%s, %s/%s (%s)" % (self.name, self.country, self.type_id, self.created_on.strftime("%b %Y"))
return "%s, %s/%s (%s)" % (self.name, self.country, type_label, self.created_on.strftime("%b %Y"))
GEOJSON_TYPES = (
......
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