clean templates

This commit is contained in:
Guilhem Saurel 2016-06-25 18:58:19 +02:00
parent b8cfaea5e1
commit 06ae3897fc
12 changed files with 37 additions and 64 deletions

View File

@ -4,6 +4,7 @@
{% block profiletab %} class="active"{% endblock %}
{% block content %}
<div class="page-header">
@ -15,17 +16,10 @@
<h3>Update profile</h3>
</div>
<div class="panel-body">
<form method="post" class="form-horizontal" role="form">
{% csrf_token %}
{% for form in forms %}
{% bootstrap_form form layout="horizontal" %}
{% endfor %}
{% buttons layout="horizontal" %}
<button type="submit" class="btn btn-primary">Update</button>
<a href="{% url 'password_change' %}" class="btn btn-warning">Change password</a>
{% endbuttons %}
</form>
{% include "_form.html" %}
</div>
</div>
{% endblock %}
<a href="{% url 'password_change' %}" class="btn btn-warning">Change password</a>

View File

@ -2,7 +2,7 @@
{% load bootstrap3 %}
{% block admintab %}active{% endblock %}
{% block admintab %} active{% endblock %}
{% block content %}

View File

@ -13,7 +13,7 @@
</div>
<div class="row">
<div class="col-md-offset-4 col-md-4">
<div class="col-md-offset-3 col-md-6">
<div class="well">
<form action="" method="post" role="form">
{% bootstrap_form form %}

View File

@ -11,16 +11,9 @@
</div>
<div class="row">
<div class="col-md-offset-4 col-md-4">
<div class="col-md-offset-3 col-md-6">
<div class="well">
<form action="" method="post" role="form">
{% bootstrap_form form %}
{% csrf_token %}
<div class="form-group text-center">
<button type="submit" class="btn btn-primary">Submit</button>
<a href="{% if request.GET.prev %}{{ request.GET.prev }}{% else %}{% url 'profile' %}{% endif %}" class="btn btn-default">Cancel</a>
</div>
</form>
{% include "_form.html" %}
</div>
</div>
</div>

View File

@ -13,14 +13,7 @@
<div class="row">
<div class="col-md-offset-4 col-md-4">
<div class="well">
<form action="" method="post" role="form">
{% bootstrap_form form %}
{% csrf_token %}
<div class="form-group text-center">
<button type="submit" class="btn btn-primary">Submit</button>
<a href="{% if request.GET.prev %}{{ request.GET.prev }}{% else %}{% url 'home' %}{% endif %}" class="btn btn-default">Cancel</a>
</div>
</form>
{% include "_form.html" %}
</div>
</div>
</div>

View File

@ -13,25 +13,11 @@
</div>
<div class="row">
<div class="col-md-offset-4 col-md-4">
<div class="col-md-offset-3 col-md-6">
<div class="well">
<form action="" method="post" role="form">
{% bootstrap_form form %}
{% csrf_token %}
<div class="form-group text-center">
<button type="submit" class="btn btn-primary">Submit</button>
<a href="{% url 'password_reset' %}" class="btn btn-warning">Reset your password</a>
<a href="{% if request.GET.prev %}{{ request.GET.prev }}{% else %}{% url 'home' %}{% endif %}" class="btn btn-default">Cancel</a>
</div>
</form>
{% include '_form.html' %}
</div>
</div>
</div>
<div class="row">
<div class="col-md-offset-4 col-md-4">
You do not have an account? Please <a href="{% url 'registration_register' %}">register</a>.
</div>
</div>
{% endblock %}

View File

@ -5,8 +5,10 @@ from django.contrib.auth import views as auth_views
from . import views
urlpatterns = [
url(r'^register/$', views.Registration.as_view(), name='register'),
url(r'^profile/$', views.profile, name='profile'),
url(r'^profile/(?P<username>[\w.@+-]+)$', views.edit, name='edit-profile'),
url(r'^login/$', auth_views.login, {'extra_context': {'buttons': [views.RESET_PASSWORD_BUTTON]}}, name='login'),
url(r'^logout/$', auth_views.logout, {'next_page': settings.LOGOUT_REDIRECT_URL}, name='logout'),
url(r'^admin/participants/$', views.participants, name='participants'),
url(r'^admin/participant/(?P<username>[\w.@+-]+)$', views.participant, name='show-participation'),

View File

@ -3,18 +3,27 @@ from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied
from django.shortcuts import get_object_or_404, render
from registration.backends.default.views import RegistrationView
from .forms import ParticipationForm, ProfileForm, ProfileOrgaForm, UserForm
from .models import Participation, Profile
from .utils import can_edit_profile
RESET_PASSWORD_BUTTON = ('password_reset', 'warning', 'Reset your password')
CHANGE_PASSWORD_BUTTON = ('password_change', 'warning', 'Change password')
class Registration(RegistrationView):
def get_context_data(self, **kwargs):
return super().get_context_data(buttons=[RESET_PASSWORD_BUTTON], **kwargs)
@login_required
def profile(request):
forms = [UserForm(request.POST or None, instance=request.user),
ProfileForm(request.POST or None, instance=request.user.profile),
ParticipationForm(request.POST or None, instance=Participation.on_site.get(user=request.user)),
]
ParticipationForm(request.POST or None, instance=Participation.on_site.get(user=request.user))]
if request.method == 'POST':
if all(form.is_valid() for form in forms):
@ -24,7 +33,7 @@ def profile(request):
else:
messages.error(request, 'Please correct those errors.')
return render(request, 'accounts/profile.html', {'forms': forms})
return render(request, 'accounts/profile.html', {'forms': forms, 'buttons': [CHANGE_PASSWORD_BUTTON]})
@login_required

View File

@ -1,9 +1,17 @@
{% load bootstrap3 %}
<form action="" method="post" class="form-horizontal">
{% csrf_token %}
{% if form %}
{% bootstrap_form form layout="horizontal" %}
{% endif %}
{% for form in forms %}
{% bootstrap_form form layout="horizontal" %}
{% endfor %}
{% buttons layout="horizontal" %}
<button type="submit" class="btn btn-primary">Submit</button>
{% for url, class, text in buttons %}
<a href="{% url url %}" class="btn btn-{{ class }}">{{ text }}</a>
{% endfor %}
<a href="{% if request.META.HTTP_REFERER %}{{ request.META.HTTP_REFERER }}{% else %}{% url 'home' %}{% endif %}" class="btn btn-default">Cancel</a>
{% endbuttons %}
</form>

View File

@ -73,7 +73,7 @@
<li{% block profiletab %}{% endblock %}><a href="{% url 'profile' %}" data-toggle="tooltip" data-placement="bottom" title="Profile"><span class="glyphicon glyphicon-user"></span>&nbsp;{{ request.user.username }}</a></li>
<li><a href="{% url 'logout' %}" data-toggle="tooltip" data-placement="bottom" title="Logout"><span class="glyphicon glyphicon-log-out"></span></a></li>
{% else %}
<li{% block registrationtab %}{% endblock %}><a href="{% url 'registration_register' %}"><span class="glyphicon glyphicon-edit"></span>&nbsp;Register</a></li>
<li{% block registrationtab %}{% endblock %}><a href="{% url 'register' %}"><span class="glyphicon glyphicon-edit"></span>&nbsp;Register</a></li>
<li{% block logintab %}{% endblock %}><a href="{% url 'login' %}?next={{ request.path }}"><span class="glyphicon glyphicon-log-in"></span>&nbsp;Login</a></li>
{% endif %}
</ul>

View File

@ -8,12 +8,6 @@
<h1>Propose a talk</h1>
<form method="POST" role="form">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">Submit</button>
{% endbuttons %}
</form>
{% include "_form.html" %}
{% endblock %}

View File

@ -8,12 +8,6 @@
<h1>Propose a Topic</h1>
<form method="POST" role="form">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">Submit</button>
{% endbuttons %}
</form>
{% include "_form.html" %}
{% endblock %}