20 Commits

Author SHA1 Message Date
01f7dad37c Translated Model fields - primarily for backend. 2020-10-11 21:56:14 +02:00
2bfdf5c172 Translated place deletion question with blrocktrans in a more natural way. 2020-10-11 21:55:38 +02:00
15f6a30cd6 Streamlined translations ... again :P 2020-10-11 21:27:27 +02:00
812c921a42 Merge commit 'dafe7eee3489e3a7c17b6560fc2aa09648773ecd' into feature/localization 2020-10-11 17:20:53 +02:00
dafe7eee34 Deleted mishap. 2020-10-11 09:47:34 +02:00
7943537276 Translated an additional bunch of messages. 2020-10-11 07:50:15 +02:00
62c1c84bb2 Minor code styling issue. 2020-10-11 07:49:50 +02:00
df36fd8ed0 Fixed the fixes' translation ;-) 2020-10-11 07:15:33 +02:00
8713ed587d Small indentation fix. 2020-10-11 07:13:16 +02:00
7271ea2cd9 Merge branch 'feature/localization' into develop 2020-10-11 07:09:59 +02:00
dff2e67991 Ops. Forgot one file. 2020-10-11 07:05:17 +02:00
65880d1472 Renamed migration file with typo. 2020-10-11 07:04:32 +02:00
561c70668d Merge remote-tracking branch 'origin/develop' into develop 2020-10-11 02:46:16 +02:00
86fbee4116 Merge from master 2020-10-04 22:12:53 +02:00
ab3ecae54b Voucher is_valid property 2020-10-04 22:12:44 +02:00
ae915681ac Testing is_expired 2020-10-04 22:12:24 +02:00
cfbe54a4e5 Making expireable a abstract model 2020-10-04 22:11:37 +02:00
76b514e1e6 #40 Hotfix Error when signing up 2020-10-04 15:42:06 +02:00
e32b3f6595 Merge branch 'develop' of mowoe.com:reverend/lostplaces-backend into develop 2020-09-29 21:28:53 +02:00
12f60bcfdf Added can_modify_place_asset template tag. 2020-09-29 20:40:46 +02:00
24 changed files with 372 additions and 73 deletions

View File

@@ -17,7 +17,7 @@ class ExplorerCreationForm(UserCreationForm):
voucher = forms.CharField( voucher = forms.CharField(
max_length=30, max_length=30,
help_text=_('The Voucher you got from an administrator') help_text=_('The Voucher you got from an administrator')
) )
def is_valid(self): def is_valid(self):
super().is_valid() super().is_valid()
@@ -28,7 +28,7 @@ class ExplorerCreationForm(UserCreationForm):
self.add_error('voucher', _('Invalid voucher')) self.add_error('voucher', _('Invalid voucher'))
return False return False
if not submitted_voucher.valid: if not fetched_voucher.valid:
self.add_error('voucher', _('Expired voucher')) self.add_error('voucher', _('Expired voucher'))
return False return False

View File

@@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-10-11 02:14+0200\n" "POT-Creation-Date: 2020-10-11 21:53+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Commander1024 <commander@commander1024.de>\n" "Last-Translator: Commander1024 <commander@commander1024.de>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -30,26 +30,42 @@ msgstr "Ungültiger Voucher"
msgid "Expired voucher" msgid "Expired voucher"
msgstr "Abgelaufener Voucher" msgstr "Abgelaufener Voucher"
#: models/abstract_models.py:28 #: models/abstract_models.py:29
msgid "Name" msgid "Name"
msgstr "Name" msgstr "Name"
#: models/abstract_models.py:35 #: models/abstract_models.py:36
msgid "Latitude" msgid "Latitude"
msgstr "Breitengrad" msgstr "Breitengrad"
#: models/abstract_models.py:36 #: models/abstract_models.py:37
msgid "Latitude in decimal format: e. g. 41.40338" msgid "Latitude in decimal format: e. g. 41.40338"
msgstr "Breitengrad in dezimaler Form: z. B. 51.95021" msgstr "Breitengrad in dezimaler Form: z. B. 51.95021"
#: models/abstract_models.py:43 #: models/abstract_models.py:44
msgid "Longitude" msgid "Longitude"
msgstr "Längengrad" msgstr "Längengrad"
#: models/abstract_models.py:44 #: models/abstract_models.py:45
msgid "Longitude in decimal format: e. g. 2.17403" msgid "Longitude in decimal format: e. g. 2.17403"
msgstr "Breitengrad in dezimaler Form: z. B. 7.4840155" msgstr "Breitengrad in dezimaler Form: z. B. 7.4840155"
#: models/abstract_models.py:59
msgid "Submission date"
msgstr "Einreichungsdatum"
#: models/abstract_models.py:67
msgid "Submitter"
msgstr "Einreicher"
#: models/abstract_models.py:79
msgid "Creation date"
msgstr "Erstellungsdatum"
#: models/abstract_models.py:82
msgid "Expiration date"
msgstr "Ablaufdatum"
#: models/external_links.py:13 #: models/external_links.py:13
msgid "URL" msgid "URL"
msgstr "Adresse (URL)" msgstr "Adresse (URL)"
@@ -96,7 +112,7 @@ msgstr "Zurück"
#: templates/global.html:32 #: templates/global.html:32
msgid "Logout" msgid "Logout"
msgstr "Abmelden" msgstr "Ausloggen"
#: templates/global.html:34 #: templates/global.html:34
msgid "Admin" msgid "Admin"
@@ -108,8 +124,8 @@ msgid "Login"
msgstr "Anmelden" msgstr "Anmelden"
#: templates/global.html:40 templates/registration/login.html:29 #: templates/global.html:40 templates/registration/login.html:29
#: templates/signup.html:12 templates/signup.html:41 #: templates/signup.html:6 templates/signup.html:12 templates/signup.html:41
msgid "Sign Up" msgid "Sign up"
msgstr "Registrieren" msgstr "Registrieren"
#: templates/global.html:50 templates/home.html:10 #: templates/global.html:50 templates/home.html:10
@@ -122,11 +138,11 @@ msgstr "UrBex Codex"
#: templates/global.html:56 templates/place/place_create.html:5 #: templates/global.html:56 templates/place/place_create.html:5
#: templates/place/place_create.html:10 #: templates/place/place_create.html:10
msgid "Create Place" msgid "Create place"
msgstr "Place erstellen" msgstr "Place erstellen"
#: templates/global.html:57 #: templates/global.html:57
msgid "All Places" msgid "All places"
msgstr "Alle Places" msgstr "Alle Places"
#: templates/home.html:20 templates/home_unauth.html:20 #: templates/home.html:20 templates/home_unauth.html:20
@@ -247,7 +263,8 @@ msgid "Submit a photo album"
msgstr "Fotoalbum hinzufügen" msgstr "Fotoalbum hinzufügen"
#: templates/photo_album/photo_album_create.html:8 #: templates/photo_album/photo_album_create.html:8
#: templates/place/place_detail.html:18 #: templates/place/place_detail.html:18 templates/place/place_update.html:5
#: templates/place/place_update.html:10
msgid "Edit place" msgid "Edit place"
msgstr "Place bearbeiten" msgstr "Place bearbeiten"
@@ -265,12 +282,13 @@ msgid "Create"
msgstr "Erstellen" msgstr "Erstellen"
#: templates/place/place_delete.html:5 #: templates/place/place_delete.html:5
msgid "Lost Place Deletion" msgid "Delete lost place"
msgstr "Lost Place löschen" msgstr "Lost Place löschen"
#: templates/place/place_delete.html:15 #: templates/place/place_delete.html:15
msgid "Are you sure you want to delete" #, python-format
msgstr "Willst Du den Ort wirklich löschen: " msgid "Are you sure you want to delete %(place_name)s?"
msgstr "Bist Du sicher, dass Du %(place_name)s löschen möchtest?"
#: templates/place/place_delete.html:19 #: templates/place/place_delete.html:19
msgid "Delete" msgid "Delete"
@@ -293,17 +311,13 @@ msgid "Images"
msgstr "Bilder" msgstr "Bilder"
#: templates/place/place_list.html:10 #: templates/place/place_list.html:10
msgid "Lost Places" msgid "All Places"
msgstr "Alle Places" msgstr "Alle Places"
#: templates/place/place_list.html:16 #: templates/place/place_list.html:16
msgid "Listing our places" msgid "Our lost places"
msgstr "Unsere Lost Places" msgstr "Unsere Lost Places"
#: templates/place/place_update.html:5 templates/place/place_update.html:10
msgid "Update place"
msgstr "Place bearbeiten"
#: templates/place/place_update.html:42 #: templates/place/place_update.html:42
msgid "Update" msgid "Update"
msgstr "Aktualisieren" msgstr "Aktualisieren"
@@ -313,13 +327,61 @@ msgid "Submit images to a place"
msgstr "Bilder zu einem Place hinzufügen" msgstr "Bilder zu einem Place hinzufügen"
#: templates/registration/login.html:29 #: templates/registration/login.html:29
msgid "Have No Account Yet?" msgid "No account, yet?"
msgstr "Noch kein Konto?" msgstr "Noch kein Konto?"
#: templates/signup.html:6
msgid "Sign up"
msgstr "Registrieren"
#: views/base_views.py:25 #: views/base_views.py:25
msgid "Please login to proceed" msgid "Please login to proceed"
msgstr "Bitte log Dich ein um fortzufahren." msgstr "Bitte log Dich ein um fortzufahren"
#: views/place_image_views.py:26
msgid "Image(s) submitted successfully"
msgstr "Bild(er) erfolgreich hinzugefügt"
#: views/place_image_views.py:41
msgid "Image deleted successfully"
msgstr "Bild erfolgreich gelöscht"
#: views/place_image_views.py:42
msgid "You are not allowed to delete this image"
msgstr "Du darfst dieses Bild nicht löschen"
#: views/place_views.py:62
msgid "Successfully updated place"
msgstr "Place erfolgreich aktualisiert"
#: views/place_views.py:63
msgid "You are not allowed to edit this place"
msgstr "Du darfst diesen Place nicht bearbeiten"
#: views/place_views.py:97
msgid "Successfully created place"
msgstr "Place erfolgreich erstellt"
#: views/place_views.py:105
msgid "Please fill in all required fields."
msgstr "Bitte füll alle benötigten Felder aus."
#: views/place_views.py:112
msgid "Successfully deleted place"
msgstr "Place erfolgreich gelöscht"
#: views/place_views.py:114
msgid "You are not allowed to delete this place"
msgstr "Du darfst diesen Place nicht löschen"
#: views/views.py:29
msgid "User created"
msgstr "Benutzer erstellt"
#: views/views.py:54
msgid "Photo album link submitted"
msgstr "Fotoalbum-Link hinzugefügt"
#: views/views.py:59
msgid "Photo album link deleted"
msgstr "Fotoalbum-Link gelöscht"
#: views/views.py:60
msgid "You are not allowed to edit this photo album link"
msgstr "Du darfst diesen Fotoalbum-Link nicht bearbeiten"

View File

@@ -0,0 +1,22 @@
# Generated by Django 3.1.1 on 2020-10-04 19:37
# Edited by reverend
import datetime
from django.db import migrations, models
import django.utils.timezone
from django.utils.timezone import utc
class Migration(migrations.Migration):
dependencies = [
('lostplaces', '0001_initial'),
]
operations = [
migrations.DeleteModel(
name='Voucher'
),
migrations.DeleteModel(
name='Expireable'
)
]

View File

@@ -0,0 +1,25 @@
# Generated by Django 3.1.1 on 2020-10-04 19:52
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('lostplaces', '0002_remove_vouchers'),
]
operations = [
migrations.CreateModel(
name='Voucher',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_when', models.DateTimeField(auto_now_add=True)),
('expires_when', models.DateTimeField()),
('code', models.CharField(max_length=30, unique=True)),
],
options={
'abstract': False,
},
),
]

View File

@@ -1,4 +1,5 @@
from django.utils import timezone
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.core.validators import MaxValueValidator, MinValueValidator from django.core.validators import MaxValueValidator, MinValueValidator
@@ -52,18 +53,35 @@ class Submittable(models.Model):
class Meta: class Meta:
abstract = True abstract = True
submitted_when = models.DateTimeField(auto_now_add=True, null=True) submitted_when = models.DateTimeField(
auto_now_add=True,
null=True,
verbose_name=_('Submission date')
)
submitted_by = models.ForeignKey( submitted_by = models.ForeignKey(
'Explorer', 'Explorer',
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
null=True, null=True,
blank=True, blank=True,
related_name='%(class)ss' related_name='%(class)ss',
verbose_name=_('Submitter')
) )
class Expireable(models.Model): class Expireable(models.Model):
""" """
Base class for things that can expire, i.e. VouchersAv Base class for things that can expire, i.e. Vouchers
""" """
created_when = models.DateTimeField(auto_now_add=True) class Meta:
expires_when = models.DateTimeField() abstract = True
created_when = models.DateTimeField(
auto_now_add=True,
verbose_name=_('Creation date')
)
expires_when = models.DateTimeField(
verbose_name=_('Expiration date')
)
@property
def is_expired(self):
return timezone.now() > self.expires_when

View File

@@ -50,6 +50,10 @@ class Voucher(Expireable):
code = models.CharField(unique=True, max_length=30) code = models.CharField(unique=True, max_length=30)
@property
def valid(self):
return not self.is_expired
def __str__(self): def __str__(self):
return "Voucher " + str(self.code) return "Voucher " + str(self.code)

View File

@@ -37,7 +37,7 @@
{% else %} {% else %}
You are not logged in. You are not logged in.
<a class="LP-Link" href="{% url 'login' %}"><span class="LP-Link__Text">{% trans 'Login' %}</span></a> | <a class="LP-Link" href="{% url 'login' %}"><span class="LP-Link__Text">{% trans 'Login' %}</span></a> |
<a class="LP-Link" href="{% url 'signup' %}"><span class="LP-Link__Text">{% trans 'Sign Up' %}</span></a> <a class="LP-Link" href="{% url 'signup' %}"><span class="LP-Link__Text">{% trans 'Sign up' %}</span></a>
{% endif %} {% endif %}
</span> </span>
</div> </div>
@@ -53,8 +53,8 @@
{% block additional_menu_items %} {% block additional_menu_items %}
{% endblock additional_menu_items %} {% endblock additional_menu_items %}
<li class="LP-Menu__Item LP-Menu__Item--additional"><a href="{% url 'place_create'%}" class="LP-Link"><span class="LP-Link__Text">{% trans 'Create Place' %}</span></a></li> <li class="LP-Menu__Item LP-Menu__Item--additional"><a href="{% url 'place_create'%}" class="LP-Link"><span class="LP-Link__Text">{% trans 'Create place' %}</span></a></li>
<li class="LP-Menu__Item LP-Menu__Item--additional"><a href="{% url 'place_list'%}" class="LP-Link"><span class="LP-Link__Text">{% trans 'All Places' %}</span></a></li> <li class="LP-Menu__Item LP-Menu__Item--additional"><a href="{% url 'place_list'%}" class="LP-Link"><span class="LP-Link__Text">{% trans 'All places' %}</span></a></li>
</ul> </ul>
</nav> </nav>
</aside> </aside>

View File

@@ -2,12 +2,12 @@
{% load static %} {% load static %}
{% load i18n %} {% load i18n %}
# {% block title %}{% trans 'Create Place' %}{% endblock %} # {% block title %}{% trans 'Create place' %}{% endblock %}
{% block maincontent %} {% block maincontent %}
<form class="LP-Form" method="POST" enctype="multipart/form-data"> <form class="LP-Form" method="POST" enctype="multipart/form-data">
<fieldset class="LP-Form__Fieldset"> <fieldset class="LP-Form__Fieldset">
<legend class="LP-Form__Legend">{% trans 'Create Place' %}</legend> <legend class="LP-Form__Legend">{% trans 'Create place' %}</legend>
{% csrf_token %} {% csrf_token %}
<div class="LP-Form__Composition LP-Form__Composition--breakable"> <div class="LP-Form__Composition LP-Form__Composition--breakable">
<div class="LP-Form__Field"> <div class="LP-Form__Field">

View File

@@ -2,7 +2,7 @@
{% load static %} {% load static %}
{% load i18n %} {% load i18n %}
{% block title %}{% trans 'Lost Place Deletion' %}{% endblock %} {% block title %}{% trans 'Delete lost place' %}{% endblock %}
{% block maincontent %} {% block maincontent %}
@@ -12,7 +12,7 @@
{% csrf_token %} {% csrf_token %}
<div class="LP-Form__Composition"> <div class="LP-Form__Composition">
<div class="LP-Form__Field LP-Form__InfoText"> <div class="LP-Form__Field LP-Form__InfoText">
<p class="LP-Paragraph">{% trans 'Are you sure you want to delete' %} "{{place.name}}"?</p> <p class="LP-Paragraph">{% blocktrans with place_name=place.name%}Are you sure you want to delete {{place_name}}?{% endblocktrans %}</p>
</div> </div>
</div> </div>

View File

@@ -63,7 +63,7 @@
<a target="_blank" href="{{photo_album.url}}" class="LP-Link"> <a target="_blank" href="{{photo_album.url}}" class="LP-Link">
<span class="LP-Text">{{photo_album.label}}</span> <span class="LP-Text">{{photo_album.label}}</span>
</a> </a>
{% if user.explorer == photo_album.submitted_by or user.explorer == place.submitted_by %} {% if user.explorer == photo_album.submitted_by or user.explorer == place.submitted_by %}
<a href="{% url 'photo_album_delete' pk=photo_album.pk%}" class="LP-Link LP-LinkList__ItemHover" title="Delete Photo Album"> <a href="{% url 'photo_album_delete' pk=photo_album.pk%}" class="LP-Link LP-LinkList__ItemHover" title="Delete Photo Album">
<div class="RV-Iconized__Container RV-Iconized__Container--small"> <div class="RV-Iconized__Container RV-Iconized__Container--small">
{% icon 'trash' className="RV-Iconized__Icon" %} {% icon 'trash' className="RV-Iconized__Icon" %}

View File

@@ -7,13 +7,13 @@
<script src="{% static 'maps/ol.js' %}"></script> <script src="{% static 'maps/ol.js' %}"></script>
{% endblock additional_head %} {% endblock additional_head %}
{% block title %}{% trans 'Lost Places' %}{% endblock %} {% block title %}{% trans 'All Places' %}{% endblock %}
{% block maincontent %} {% block maincontent %}
{% include 'partials/osm_map.html' with config=mapping_config %} {% include 'partials/osm_map.html' with config=mapping_config %}
<div class="LP-PlaceList"> <div class="LP-PlaceList">
<h1 class="LP-Headline">{% trans 'Listing our places' %}</h1> <h1 class="LP-Headline">{% trans 'Our lost places' %}</h1>
<ul class="LP-PlaceList__List"> <ul class="LP-PlaceList__List">
{% for place in place_list %} {% for place in place_list %}
<li class="LP-PlaceList__Item"> <li class="LP-PlaceList__Item">

View File

@@ -2,12 +2,12 @@
{% load static %} {% load static %}
{% load i18n %} {% load i18n %}
# {% block title %}{% trans 'Update place' %}{% endblock %} # {% block title %}{% trans 'Edit place' %}{% endblock %}
{% block maincontent %} {% block maincontent %}
<form class="LP-Form" method="POST" enctype="multipart/form-data"> <form class="LP-Form" method="POST" enctype="multipart/form-data">
<fieldset class="LP-Form__Fieldset"> <fieldset class="LP-Form__Fieldset">
<legend class="LP-Form__Legend">{% trans 'Update place' %}</legend> <legend class="LP-Form__Legend">{% trans 'Edit place' %}</legend>
{% csrf_token %} {% csrf_token %}
<div class="LP-Form__Composition LP-Form__Composition--breakable"> <div class="LP-Form__Composition LP-Form__Composition--breakable">
<div class="LP-Form__Field"> <div class="LP-Form__Field">

View File

@@ -26,6 +26,6 @@
</fieldset> </fieldset>
</form> </form>
<p class="LP-Headline">{% trans 'Have No Account Yet?' %} <a class="LP-Link" href="{% url 'signup' %}"><span class="LP-Link__Text">{% trans 'Sign Up' %}</span></a></p> <p class="LP-Headline">{% trans 'No account, yet?' %} <a class="LP-Link" href="{% url 'signup' %}"><span class="LP-Link__Text">{% trans 'Sign up' %}</span></a></p>
{% endblock maincontent %} {% endblock maincontent %}

View File

@@ -9,7 +9,7 @@
<form class="LP-Form" method="POST"> <form class="LP-Form" method="POST">
<fieldset class="LP-Form__Fieldset"> <fieldset class="LP-Form__Fieldset">
<legend class="LP-Form__Legend">{% trans 'Sign Up' %}</legend> <legend class="LP-Form__Legend">{% trans 'Sign up' %}</legend>
{% csrf_token %} {% csrf_token %}
<div class="LP-Form__Composition LP-Form__Composition--breakable"> <div class="LP-Form__Composition LP-Form__Composition--breakable">
<div class="LP-Form__Field"> <div class="LP-Form__Field">
@@ -38,7 +38,7 @@
<div class="LP-Form__Composition LP-Form__Composition--buttons"> <div class="LP-Form__Composition LP-Form__Composition--buttons">
<div class="LP-Form__Field LP-Form__Button LP-Input"> <div class="LP-Form__Field LP-Form__Button LP-Input">
<button class="LP-Button">{% trans 'Sign Up' %}</button> <button class="LP-Button">{% trans 'Sign up' %}</button>
</div> </div>
</div> </div>
</fieldset> </fieldset>

View File

@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django import template from django import template
from django.http import request
register = template.Library() register = template.Library()

View File

@@ -0,0 +1,76 @@
from django.test import TestCase
from django.core.exceptions import FieldDoesNotExist
class FormTestCase(TestCase):
'''
Base class for FormTests.
Parameters:
- form : Form to test
'''
form = None
def assertField(self, field_name, field_class, must_have={}, must_not_have={}):
'''
Tests if a field exists under the given name and
if the field is of the right type.
Also checks if the field has the given must_have attributes
and does not have any of the must_not_have attributes. If you
dont care about the value of the attribute you can just set it to
something that fullfills value == False (i.e. '' or 0)
'''
try:
field = self.form.base_fields[field_name]
except FieldDoesNotExist:
self.fail(
'Expecting %s to have a field named \'%s\'' % (
self.form.__name__,
field_name
)
)
self.assertEqual(
type(field), field_class,
msg='Expecting type of %s to be %s' % (
str(field),
field_class.__name__
)
)
for key, value in must_have.items():
if value:
self.assertEqual(
getattr(field, key), value,
msg='Expeting the value of %s %s to be \'%s\'' % (
str(field),
key,
value
)
)
else:
self.assertTrue(
hasattr(field, key),
msg='Expeting %s to have \'%s\'' % (
str(field),
key
)
)
for key, value in must_not_have.items():
if value:
self.assertTrue(
getattr(field, key) != value,
msg='Expeting the value of %s %s to not be \'%s\'' % (
str(field),
key,
value
)
)
else:
self.assertFalse(
hasattr(field, value),
msg='Expeting %s to not have \'%s\'' % (
str(field),
key
)
)
return field

View File

@@ -0,0 +1,59 @@
import datetime
from django import forms
from django.utils import timezone
from lostplaces.tests.forms import FormTestCase
from lostplaces.forms import ExplorerCreationForm
from lostplaces.models.models import Voucher
class ExplorerCreationFormTestCase(FormTestCase):
"""
This test case only tests for the voucher since all other aspects don't realy matter
to this project and are already tested by django
"""
form = ExplorerCreationForm
@classmethod
def setUpTestData(cls):
Voucher.objects.create(
code='Imacode123',
expires_when=timezone.now() + datetime.timedelta(minutes=1)
)
def setUp(self):
self.post_data = {
'voucher': 'Imacode123',
'username': 'testpeter',
'email': 'testpeter@example.org',
'password1': 'Develop123',
'password2': 'Develop123'
}
def test_voucher_field(self):
self.assertField(
field_name='voucher',
field_class=forms.CharField
)
def test_validation_valid(self):
form = ExplorerCreationForm(self.post_data)
self.assertTrue(
form.is_valid(),
msg='Expecting the %s to validate' % (
self.form.__name__
)
)
def test_validation_invalid(self):
self.post_data = {
'voucher': 'Imanotacode123'
}
form = ExplorerCreationForm(self.post_data)
self.assertFalse(
form.is_valid(),
msg='Expecting the %s to not validate' % (
self.form.__name__
)
)

View File

@@ -2,11 +2,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.db import models from django.db import models
from django.contrib.auth.models import User
from django.core.exceptions import FieldDoesNotExist from django.core.exceptions import FieldDoesNotExist
from django.test import TestCase from django.test import TestCase
# Creating a test user
class ModelTestCase(TestCase): class ModelTestCase(TestCase):
''' '''

View File

@@ -1,6 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import datetime
from django.utils import timezone
from django.test import TestCase from django.test import TestCase
from django.db import models from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
@@ -10,7 +13,8 @@ from lostplaces.models import (
Mapable, Mapable,
Submittable, Submittable,
PlaceAsset, PlaceAsset,
Expireable Expireable,
Voucher
) )
from lostplaces.tests.models import ModelTestCase from lostplaces.tests.models import ModelTestCase
@@ -113,3 +117,33 @@ class PlaceAssetTestCase(ModelTestCase):
class ExpireableTestCase(ModelTestCase): class ExpireableTestCase(ModelTestCase):
model = Expireable model = Expireable
def test_fields(self):
self.assertField(
field_name='created_when',
field_class=models.DateTimeField,
must_have={'auto_now_add': True}
)
self.assertField(
field_name='expires_when',
field_class=models.DateTimeField
)
def test_is_expired(self):
valid_voucher = Voucher.objects.create(
code='Test123',
expires_when=timezone.now() + datetime.timedelta(minutes=2)
)
self.assertFalse(
valid_voucher.is_expired,
msg='Expecing the expirable object to not be expired'
)
invalid_voucher = Voucher.objects.create(
code='Test1234',
expires_when=timezone.now() - datetime.timedelta(minutes=2)
)
self.assertTrue(
invalid_voucher.is_expired,
msg='Expecing the expirable object to be expired'
)

View File

@@ -1,5 +1,6 @@
from django.views import View from django.views import View
from django.shortcuts import get_object_or_404, redirect from django.shortcuts import get_object_or_404, redirect
from django.utils.translation import ugettext_lazy as _
from lostplaces.views.base_views import PlaceAssetCreateView, PlaceAssetDeleteView from lostplaces.views.base_views import PlaceAssetCreateView, PlaceAssetDeleteView
from lostplaces.models import PlaceImage, Place from lostplaces.models import PlaceImage, Place
@@ -22,7 +23,7 @@ class PlaceImageCreateView(MultiplePlaceImageUploadMixin, PlaceAssetCreateView):
model = PlaceImage model = PlaceImage
form_class = PlaceImageForm form_class = PlaceImageForm
template_name = 'place_image/place_image_create.html' template_name = 'place_image/place_image_create.html'
success_message = 'Place Images submitted' success_message = _('Image(s) submitted successfully')
commit = False commit = False
def post(self, request, place_id, *args, **kwargs): def post(self, request, place_id, *args, **kwargs):
@@ -37,7 +38,5 @@ class PlaceImageCreateView(MultiplePlaceImageUploadMixin, PlaceAssetCreateView):
class PlaceImageDeleteView(PlaceAssetDeleteView): class PlaceImageDeleteView(PlaceAssetDeleteView):
model = PlaceImage model = PlaceImage
success_message = 'Images deleted successfully' success_message = _('Image deleted successfully')
permission_denied_message = 'You\'r not allowed to delete this image' permission_denied_message = _('You are not allowed to delete this image')

View File

@@ -10,6 +10,7 @@ from django.views.generic import ListView
from django.contrib import messages from django.contrib import messages
from django.contrib.messages.views import SuccessMessageMixin from django.contrib.messages.views import SuccessMessageMixin
from django.utils.translation import ugettext_lazy as _
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
from django.urls import reverse_lazy from django.urls import reverse_lazy
@@ -58,8 +59,8 @@ class PlaceUpdateView(IsAuthenticatedMixin, IsPlaceSubmitterMixin, SuccessMessag
template_name = 'place/place_update.html' template_name = 'place/place_update.html'
model = Place model = Place
form_class = PlaceForm form_class = PlaceForm
success_message = 'Successfully updated place.' success_message = _('Successfully updated place')
place_submitter_error_message = 'You do no have permissions to alter this place' place_submitter_error_message = _('You are not allowed to edit this place')
def get_success_url(self): def get_success_url(self):
return reverse_lazy('place_detail', kwargs={'pk':self.get_object().pk}) return reverse_lazy('place_detail', kwargs={'pk':self.get_object().pk})
@@ -93,7 +94,7 @@ class PlaceCreateView(MultiplePlaceImageUploadMixin, IsAuthenticatedMixin, View)
messages.success( messages.success(
self.request, self.request,
'Successfully created place.' _('Successfully created place')
) )
return redirect(reverse_lazy('place_detail', kwargs={'pk': place.pk})) return redirect(reverse_lazy('place_detail', kwargs={'pk': place.pk}))
@@ -101,17 +102,16 @@ class PlaceCreateView(MultiplePlaceImageUploadMixin, IsAuthenticatedMixin, View)
# Usually the browser should have checked the form before sending. # Usually the browser should have checked the form before sending.
messages.error( messages.error(
self.request, self.request,
'Please fill in all required fields.' _('Please fill in all required fields.')
) )
return render(request, 'place/place_create.html', context={'form': place_form}) return render(request, 'place/place_create.html', context={'form': place_form})
class PlaceDeleteView(IsAuthenticatedMixin, IsPlaceSubmitterMixin, DeleteView): class PlaceDeleteView(IsAuthenticatedMixin, IsPlaceSubmitterMixin, DeleteView):
template_name = 'place/place_delete.html' template_name = 'place/place_delete.html'
model = Place model = Place
success_message = 'Successfully deleted place.' success_message = _('Successfully deleted place')
success_url = reverse_lazy('place_list') success_url = reverse_lazy('place_list')
success_message = 'Place deleted' place_submitter_error_message = _('You are not allowed to delete this place')
place_submitter_error_message = 'You do no have permission to delete this place'
def delete(self, request, *args, **kwargs): def delete(self, request, *args, **kwargs):
messages.success(self.request, self.success_message) messages.success(self.request, self.success_message)

View File

@@ -9,6 +9,7 @@ from django.contrib import messages
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
from django.http import HttpResponseForbidden from django.http import HttpResponseForbidden
from django.utils.translation import ugettext_lazy as _
from lostplaces.forms import ExplorerCreationForm, TagSubmitForm from lostplaces.forms import ExplorerCreationForm, TagSubmitForm
from lostplaces.models import Place, PhotoAlbum from lostplaces.models import Place, PhotoAlbum
@@ -25,7 +26,7 @@ class SignUpView(SuccessMessageMixin, CreateView):
form_class = ExplorerCreationForm form_class = ExplorerCreationForm
success_url = reverse_lazy('login') success_url = reverse_lazy('login')
template_name = 'signup.html' template_name = 'signup.html'
success_message = 'User created.' success_message = _('User created')
class HomeView(IsAuthenticatedMixin, View): class HomeView(IsAuthenticatedMixin, View):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
@@ -50,13 +51,13 @@ class PhotoAlbumCreateView(PlaceAssetCreateView):
model = PhotoAlbum model = PhotoAlbum
fields = ['url', 'label'] fields = ['url', 'label']
template_name = 'photo_album/photo_album_create.html' template_name = 'photo_album/photo_album_create.html'
success_message = 'Photo Album submitted' success_message = _('Photo album link submitted')
class PhotoAlbumDeleteView(PlaceAssetDeleteView): class PhotoAlbumDeleteView(PlaceAssetDeleteView):
model = PhotoAlbum model = PhotoAlbum
pk_url_kwarg = 'pk' pk_url_kwarg = 'pk'
success_message = 'Photo Album deleted' success_message = _('Photo album link deleted')
permission_denied_messsage = 'You do not have permissions to alter this photo album' permission_denied_messsage = _('You are not allowed to edit this photo album link')
class PlaceTagSubmitView(IsAuthenticatedMixin, View): class PlaceTagSubmitView(IsAuthenticatedMixin, View):
def post(self, request, tagged_id, *args, **kwargs): def post(self, request, tagged_id, *args, **kwargs):

View File

@@ -8,7 +8,7 @@ with open('Readme.md') as f:
setup( setup(
name='django-lostplaces', name='django-lostplaces',
version='0.1.a5', version='0.1.2 HotFix',
description='A django app to manage lost places', description='A django app to manage lost places',
author='Reverend', author='Reverend',
author_email='reverend@reverend2048.de', author_email='reverend@reverend2048.de',