Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into clothing
Browse files Browse the repository at this point in the history
  • Loading branch information
jlauinger committed Aug 24, 2016
2 parents 68fa7a9 + f14cc89 commit 4fec25c
Show file tree
Hide file tree
Showing 38 changed files with 746 additions and 81 deletions.
13 changes: 13 additions & 0 deletions ophasebase/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,23 @@ def __str__(self):
return self.get_name()

def get_human_duration(self):
"""Returns the start_date and end_date of the ophase as human readable
e.g. vom 3. April 2014 bis 6. April 2016"""
return _('vom %(begin)s bis %(end)s') % {
'begin': formats.date_format(self.start_date, 'DATE_FORMAT'),
'end': formats.date_format(self.end_date, 'DATE_FORMAT'),}

def get_human_short_duration(self):
"""Returns the start_date and end_date of the ophase as
human readable e.g. 3. - 6. April"""
beginformat = 'j. '
if self.start_date.month != self.end_date.month:
beginformat +='F'
endformat = 'j. F'
return '%(begin)s - %(end)s' % {
'begin': formats.date_format(self.start_date, beginformat),
'end': formats.date_format(self.end_date, endformat),}

def clean(self, *args, **kwargs):
super().clean(*args, **kwargs)
if self.start_date > self.end_date:
Expand Down
4 changes: 2 additions & 2 deletions ophasebase/templates/ophasebase/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
<div class="col-sm-8">
<h1>
<a href="{% url 'website:homepage' %}" class="no-underline hidden-xs">
<img src="{% static 'website/OphasenWesen.png' %}" style="height: 9rem;" />
<img src="{% static 'website/ophasen-wesen.svg' %}" style="height: 9rem;" />
</a>
{% block heading %}{% endblock %}
</h1>
</div>
<div class="col-sm-4 hidden-xs" style="text-align: right;">
<img src="{% static 'website/logo_ohne_rand.png' %}" class="pull-right" style="height: 7rem; margin-top: 3rem;" />
<img src="{% static 'website/logo_ohne_rand.svg' %}" class="pull-right" style="height: 7rem; margin-top: 3rem;" />
</div>
</div>

Expand Down
10 changes: 10 additions & 0 deletions ophasebase/templates/ophasebase/breadcrumbs_adminaction.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "admin/base_site.html" %}{% load staticfiles i18n admin_urls %}

{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
&rsaquo; <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_config.verbose_name }}</a>
&rsaquo; <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>
&rsaquo; {{ title }}
</div>
{% endblock %}
Empty file.
26 changes: 26 additions & 0 deletions ophasebase/templatetags/tex_escape.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import re

from django import template
from django.template.defaultfilters import stringfilter

register = template.Library()

@register.filter
@stringfilter
def tex_escape(value):
"""Escape characters with special meaning in LaTeX.
"""
replacements = {
'&': r'\&',
'%': r'\%',
'$': r'\$',
'#': r'\#',
'_': r'\_',
'{': r'\{',
'}': r'\}',
'~': r'\textasciitilde{}',
'^': r'\^{}',
'\\': r'\textbackslash{}',
}
regex = re.compile('|'.join(re.escape(key) for key in replacements))
return regex.sub(lambda match: replacements[match.group()], value)
1 change: 1 addition & 0 deletions pyophase/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.admindocs',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
Expand Down
1 change: 1 addition & 0 deletions pyophase/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
url(r'^workshops/', include('workshops.urls', namespace='workshops')),
url(r'^dashboard/', include('dashboard.urls', namespace='dashboard')),
url(r'^clothing/', include('clothing.urls', namespace='clothing')),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', admin.site.urls),
url(r'^accounts/login/$', django.contrib.auth.views.login, {'template_name': 'admin/login.html'}, name='login'),
url(r'^accounts/logout/$', django.contrib.auth.views.logout, {'next_page': reverse_lazy('website:homepage')}, name='logout'),
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ coverage==4.2
Django==1.10
django-bootstrap3==7.0.1
django-formtools==1.0
docutils==0.12
mysqlclient==1.3.7
odswriter==0.4.0
Pillow==3.3.1
Expand Down
47 changes: 30 additions & 17 deletions staff/admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@

from staff.models import HelperJob, OrgaJob

from collections import namedtuple

import odswriter


def mail_export(modeladmin, request, queryset):
"""Creates a list of email addresses in "prename lastname <email@example.net>" format.
This should be suitable for mass subscription and similar purposes.
"""
template = loader.get_template("staff/mail_export.html")
context = {'persons' : queryset}
context = {'persons' : queryset,
'opts' : modeladmin.opts,
'title' : _('E-Mail Mass Subscription Export')}
return SimpleTemplateResponse(template, context)

mail_export.short_description = _('E-Mail Mass Subscription Export')
Expand Down Expand Up @@ -104,7 +102,6 @@ def staff_overview_export(modeladmin, request, queryset):

staff_overview_export.short_description = _('Übersicht exportieren')


def job_overview(jobtype, modeladmin, request, queryset):
"""Display a matrix to show persons with associated jobs.
"""
Expand All @@ -113,9 +110,11 @@ def job_overview(jobtype, modeladmin, request, queryset):
if jobtype == 'helper':
persons = queryset.filter(is_helper=True)
jobs = HelperJob.objects.all().annotate(num_person=Count(Case(When(person__is_helper=True, then=1))))
title = ('Helfer-Übersicht')
elif jobtype == 'orga':
persons = queryset.filter(is_orga=True)
jobs = OrgaJob.objects.all().annotate(num_person=Count(Case(When(person__is_orga=True, then=1))))
title = ('Orga-Übersicht')

jobs.order_by('label')

Expand All @@ -133,6 +132,8 @@ def job_overview(jobtype, modeladmin, request, queryset):
'jobtype' : jobtype,
'persons' : persons,
'jobs' : jobs,
'opts' : modeladmin.opts,
'title' : title,
}

return SimpleTemplateResponse(template, context)
Expand Down Expand Up @@ -214,20 +215,32 @@ def __get_fillform_email(register_view_url, person):

def send_fillform_mail(modeladmin, request, queryset):
"""Send fillform informations to the user"""
if request.POST.get('post'):
register_view_url = request.build_absolute_uri(reverse('staff:registration'))

register_view_url = request.build_absolute_uri(reverse('staff:registration'))
mails = tuple(__get_fillform_email(register_view_url, p) for p in queryset)
send_mass_mail(mails)
count = len(mails)

mails = tuple(__get_fillform_email(register_view_url, p) for p in queryset)
data = {'count': count,
'person': str(queryset[0]),}

send_mass_mail(mails)
admin_msg = ungettext(
'Die Fillform E-Mail wurde an {person} verschickt.',
'Die Fillform E-Mails wurden an {count} Personen verschickt.',
count).format(**data)

modeladmin.message_user(request, admin_msg, messages.SUCCESS)
else:
context = {
'queryset': queryset,
'opts' : modeladmin.opts,
'title': _("Fillform E-Mail verschicken"),
'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME,
}
template = loader.get_template("staff/fillform_email_confirm.html")

return TemplateResponse(request, template, context)

count = queryset.count()
admin_msg = ungettext(
'Die Fillform E-Mail wurde an %(count)d Person verschickt.',
'Die Fillform E-Mails wurden an %(count)d Personen verschickt.',
count) % {
'count': count,
}
modeladmin.message_user(request, admin_msg, messages.SUCCESS)

send_fillform_mail.short_description = _('Fillform E-Mail an Person senden')
24 changes: 24 additions & 0 deletions staff/templates/staff/fillform_email_confirm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "ophasebase/breadcrumbs_adminaction.html" %}{% load i18n l10n %}

{% block content %}
<form action="" method="post">{% csrf_token %}
<p>
{% blocktrans count counter=queryset|length %}
Eine Fillform E-Mail wird an folgende Person geschickt:
{% plural %}
Eine Fillform E-Mail wird an folgende {{counter}} Personen geschickt:
{% endblocktrans %}</p>

<ul>{{ queryset|unordered_list }}</ul>

<div>
{% for obj in queryset %}
<input type="hidden" name="{{ action_checkbox_name }}" value="{{ obj.pk|unlocalize }}" />
{% endfor %}
<input type="hidden" name="action" value="send_fillform_mail" />
<input type="hidden" name="post" value="yes" />
<input type="submit" value="{% trans "Fillform E-Mail verschicken" %}" />
<a href=".">Abbrechen</a>
</div>
</form>
{% endblock %}
9 changes: 1 addition & 8 deletions staff/templates/staff/job_matrix.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{% extends "admin/base_site.html" %}{% load staticfiles %}{% load i18n %}

{% block title %}{% if jobtype == "helper" %}{% trans "Helfer-Übersicht" %}{% endif %}
{% if jobtype == "orga" %}{% trans "Orga-Übersicht" %}{% endif %} {{ block.super }}{% endblock %}
{% extends "ophasebase/breadcrumbs_adminaction.html" %}{% load staticfiles i18n %}

{% block content %}

Expand All @@ -25,10 +22,6 @@
}
</style>

<h2>{% if jobtype == "helper" %}{% trans "Helfer-Übersicht" %}{% endif %}
{% if jobtype == "orga" %}{% trans "Orga-Übersicht" %}{% endif %}
</h2>

<table>
<thead>
<tr>
Expand Down
7 changes: 1 addition & 6 deletions staff/templates/staff/mail_export.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{% extends "admin/base_site.html" %}{% load i18n %}

{% block title %}{% trans "E-Mail Mass Subscription Export" %} {{ block.super }}{% endblock %}
{% extends "ophasebase/breadcrumbs_adminaction.html" %}{% load i18n %}

{% block content %}

<h2>{% trans "E-Mail Mass Subscription Export" %}</h2>

<p>
{% blocktrans count counter=persons|length %}
Es wurde eine Person ausgewählt.
Expand Down
11 changes: 10 additions & 1 deletion staff/tests/tests_admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,19 @@ def test_send_fillform_email(self):
self.assertEqual(len(mail.outbox), 0)
recipient = [5, 6, 7]
response = c.post(change_url, {'action': 'send_fillform_mail',
'_selected_action': recipient},)

# If the post work we get to the confirmation page
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'staff/fillform_email_confirm.html')

# Send the post again with confirmation
response = c.post(change_url, {'action': 'send_fillform_mail',
'post': 'yes',
'_selected_action': recipient},
follow=True)

# If the post work we get back to the view via a redirect
# If the post work we get back to the changelist via a redirect
self.assertEqual(response.status_code, 200)
self.assertRedirects(response, change_url)

Expand Down
38 changes: 26 additions & 12 deletions staff/tests/tests_legacy.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
from django.test import TestCase, tag
from django.utils.safestring import SafeText
from unittest import skip
from datetime import date

from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.db import IntegrityError
from django.test import TransactionTestCase, TestCase, tag
from django.utils.safestring import SafeText
from selenium.common.exceptions import NoAlertPresentException
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.firefox.webdriver import WebDriver

from datetime import date

from ophasebase.models import Ophase
from staff.models import Person
from staff.forms import PersonForm
from staff.models import Person

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException

# Create your tests here.

Expand All @@ -40,6 +35,25 @@ def test_person_foreign_key_ophase(self):
'name=Doe&email=doe%40example.net&phone=0123456789'\
'&matriculated_since=2011&degree_course=B.Sc.')


class PersonSaveDuplicate(TransactionTestCase):
"""A Person can register only once per ophase instance"""
def test_person_register_once_per_ophase(self):
o1 = Ophase.objects.create(start_date=date(2014, 4, 7), end_date=date(2014, 4, 11), is_active=True)
d = DressSize.objects.create(name="S", sort_key=0)
p = Person.objects.create(prename="John", name="Doe", email="john@example.net", phone="0123456789", matriculated_since="2011", degree_course="B.Sc.", is_tutor=True, dress_size=d)
with self.assertRaises(IntegrityError):
p2 = Person.objects.create(prename="John", name="Doe", email="john@example.net", phone="0123456789", matriculated_since="2011", degree_course="B.Sc.", is_tutor=True, dress_size=d)

o2 = Ophase.objects.create(start_date=date(2014, 10, 6), end_date=date(2014, 10, 10), is_active=True)
o1 = Ophase.objects.get(pk=o1.pk)
self.assertEqual(o2.is_active, True)
self.assertEqual(o1.is_active, False)

p3 = Person.objects.create(prename="John", name="Doe", email="john@example.net", phone="0123456789", matriculated_since="2011", degree_course="B.Sc.", is_tutor=True, dress_size=d)
self.assertEqual(p3.ophase, o2)


class AppendDescriptionTestCase(TestCase):
"""Test append of a link to a field Label"""

Expand Down
21 changes: 14 additions & 7 deletions staff/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
from django.template import loader
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
from django.http import HttpResponseForbidden

from ophasebase.models import Ophase
from staff.models import Settings, GroupCategory, OrgaJob, HelperJob
from staff.forms import PersonForm


class StaffAdd(CreateView):
form_class = PersonForm
template_name = 'staff/person_form.html'
Expand Down Expand Up @@ -48,6 +51,10 @@ def get_context_data(self, **kwargs):
return context

def form_valid(self, form):
settings = Settings.instance()
if settings is None or not settings.any_registration_enabled():
return HttpResponseForbidden()

try:
super_return = super().form_valid(form)
except IntegrityError:
Expand All @@ -65,7 +72,7 @@ def form_valid(self, form):
for field in form.fields:
label = form[field].label
# remove html from label
label = label.split('<',1)[0].strip()
label = label.split('<', 1)[0].strip()

content = form.cleaned_data[field]
#Remove all fields that are not set
Expand All @@ -88,19 +95,19 @@ def form_valid(self, form):
'email_changedata': 'ophase-leitung@d120.de',
'form_content': form_content,
}

email = EmailMessage()
email.subject = _('{ophasen_title} Registrierung').format(**values)
email.to = ['{user_prename} {user_name} <{user_email}>'.format(**values)]

email.body = _("""Hallo {user_prename},
vielen Dank dass du mithelfen möchtest. Deine Daten wurden erfolgreich
gespeichert. Die Ophasenleitung wird sich in geraumer Zeit bei dir melden,
sobald erste organisatorische Dinge oder Termine anstehen. Dies kann unter
vielen Dank dass du mithelfen möchtest. Deine Daten wurden erfolgreich
gespeichert. Die Ophasenleitung wird sich in geraumer Zeit bei dir melden,
sobald erste organisatorische Dinge oder Termine anstehen. Dies kann unter
Umständen noch ein paar Wochen dauern.
Falls sich in der Zwischenzeit Daten von dir ändern sende uns doch bitte eine
Falls sich in der Zwischenzeit Daten von dir ändern sende uns doch bitte eine
E-Mail an {email_changedata}.
Hier nochmal die von dir eingetragenen Daten:
Expand All @@ -109,7 +116,7 @@ def form_valid(self, form):
Viele Grüße,
Die Ophasen-Leitung""").format(**values)

email.send()

return super_return
Expand Down
Loading

0 comments on commit 4fec25c

Please sign in to comment.