Add tools, first interface, no functionality yet

This commit is contained in:
Oliver Falk
2018-07-02 14:26:09 +02:00
parent 991a0f33f9
commit 2f980479a5
6 changed files with 127 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ INSTALLED_APPS.extend([
'anymail',
'ivatar',
'ivatar.ivataraccount',
'ivatar.tools',
])
from ivatar.settings import MIDDLEWARE # noqa

64
ivatar/tools/forms.py Normal file
View File

@@ -0,0 +1,64 @@
'''
Classes for our ivatar.tools.forms
'''
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.core.exceptions import ValidationError
class CheckDomainForm(forms.Form):
'''
Form handling domain check
'''
can_distribute = forms.TextInput(
attrs={
'label': _('Domain'),
'required': True,
'error_messages': {
'required':
_('Cannot check without a domain name.')
}
}
)
class CheckForm(forms.Form):
'''
Form handling check
'''
mail = forms.EmailField(
label=_('E-Mail'),
required=False,
error_messages={
'required':
_('Cannot check without a domain name.')
})
openid = forms.CharField(
label=_('OpenID'),
required=False,
error_messages={
'required':
_('Cannot check without an openid name.')
})
size = forms.IntegerField(
label=_('Size'),
initial=80,
min_value=10,
max_value=160,
required=True,
)
default_url = forms.URLField(
label=_('Default URL'),
required=False,
)
def clean(self):
self.cleaned_data = super().clean()
mail = self.cleaned_data.get('mail')
openid = self.cleaned_data.get('openid')
if not mail and not openid:
raise ValidationError(_('Either OpenID or mail must be specified'))
return self.cleaned_data

View File

@@ -0,0 +1,21 @@
{% extends 'base.html' %}
{% load i18n %}
{% load bootstrap4 %}
{% block title %}{% trans 'Check e-mail or openid' %}{% endblock title %}
{% block content %}
<h1>{% trans 'Check e-mail or openid' %}</h1>
<div style="width:600px;">
<form method="post" name="check">{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">{% trans 'Check' %}</button>
<button type="cancel" class="btn btn-danger">{% trans 'Cancel' %}</button>
{% endbuttons %}
</form>
</div>
{% endblock content %}

11
ivatar/tools/urls.py Normal file
View File

@@ -0,0 +1,11 @@
'''
ivatar/tools URL configuration
'''
from django.conf.urls import url
from . views import CheckView, CheckDomainView
urlpatterns = [ # pylint: disable=invalid-name
url('check/', CheckView.as_view(), name='tools_check'),
url('check_domain/', CheckDomainView.as_view(), name='tools_check_domain'),
]

29
ivatar/tools/views.py Normal file
View File

@@ -0,0 +1,29 @@
'''
View classes for ivatar/tools/
'''
from django.views.generic.edit import FormView
from django.urls import reverse_lazy as reverse
from django.shortcuts import render
from .forms import CheckDomainForm, CheckForm
class CheckDomainView(FormView):
'''
View class for checking a domain
'''
template_name = 'check_domain.html'
form_class = CheckDomainForm
class CheckView(FormView):
'''
View class for checking an e-mail or openid address
'''
template_name = 'check.html'
form_class = CheckForm
success_url = reverse('tools_check')
def form_valid(self, form):
super().form_valid(form)
return render(self.request, self.template_name, {'form': form})

View File

@@ -13,6 +13,7 @@ urlpatterns = [ # pylint: disable=invalid-name
path('admin/', admin.site.urls),
url('openid/', include('django_openid_auth.urls')),
url('accounts/', include('ivatar.ivataraccount.urls')),
url('tools/', include('ivatar.tools.urls')),
url(
r'avatar/(?P<digest>\w{64})',
AvatarImageView.as_view(), name='avatar_view'),