Commit 1dce94a1 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Add frontend profile edit form

parent 548fac2a
from __future__ import unicode_literals
import unicodedata
from django.forms import ModelForm
from .models import Member
from django.contrib.auth.hashers import (
UNUSABLE_PASSWORD_PREFIX, identify_hasher,
)
from django.utils.translation import ugettext, ugettext_lazy as _
class MemberForm(ModelForm):
class Meta:
fields = ['address_street', 'address_street2',
'address_postal_code', 'address_city', 'phone_number',
'emergency_contact', 'emergency_contact_phone_number',
'birthday', 'show_birthday', 'website',
'profile_description', 'nickname',
'display_name_preference', 'photo', 'language',
'receive_optin', 'receive_newsletter']
model = Member
......@@ -3,7 +3,7 @@
{% load static %}
{% load i18n %}
{% block title %}{% trans "Members" %} - {{ block.super }}{% endblock %}
{% block title %}{% trans "members"|capfirst %} - {{ block.super }}{% endblock %}
{% block body %}
<h1>{% trans 'Account' %}</h1>
......
{% extends "base.html" %}
{% load static i18n fieldtype %}
{% block title %}{% trans "edit profile"|capfirst %} - {% trans "members"|capfirst %} - {{ block.super }}{% endblock %}
{% block body %}
<h1>{% trans "edit profile"|capfirst %}</h1>
<form method="post" class="form-horizontal span8 offset2">
{% csrf_token %}
{% for field in form %}
<div class="control-group row {% if field.errors %}error{% endif %}">
<label class="control-label" for="{{ field.name }}">{{ field.label_tag }}</label>
<div class="controls">
{{ field }}
{% for error in field.errors %}
<span class="help-block">{{ error|escape }}</span>
{% endfor %}
{% if field.help_text and field|fieldtype != 'CheckboxInput' %}
<span class="help-block">{{ field.help_text|safe }}</span>
{% endif %}
</div>
</div>
{% endfor %}
<input type="submit" value="{% trans 'save'|capfirst %}" class="btn btn-style1 pull-right login" />
</form>
{% endblock %}
\ No newline at end of file
......@@ -3,10 +3,10 @@
{% load static %}
{% load i18n %}
{% block title %}{% trans "Members" %} - {{ block.super }}{% endblock %}
{% block title %}{% trans "members"|capfirst %} - {{ block.super }}{% endblock %}
{% block body %}
<h1>{% trans "Members" %}</h1>
<h1>{% trans "members"|capfirst %}</h1>
<p class="text-center">
{% blocktrans trimmed %}
......
......@@ -3,7 +3,7 @@
{% load static %}
{% load i18n %}
{% block title %}{% trans "Profile" %} - {% trans "Members" %} - {{ block.super }}{% endblock %}
{% block title %}{% trans "profile"|capfirst %} - {% trans "members"|capfirst %} - {{ block.super }}{% endblock %}
{% block body %}
<h1>
......
from django import template
register = template.Library()
@register.filter(name='fieldtype')
def fieldtype(field):
return field.field.widget.__class__.__name__
......@@ -7,7 +7,7 @@ urlpatterns = [
url('^become-a-member-document/(?P<pk>[0-9]*)', views.get_become_a_member_document, name='become-a-member-document'),
url('^profile/(?P<pk>[0-9]*)$', views.profile, name='profile'),
url('^profile$', views.profile, name='profile'),
url('^profile/edit$', views.edit_profile, name='edit-profile'),
url('^profile/edit/$', views.edit_profile, name='edit-profile'),
url('^account$', views.account, name='account'),
url('^$', views.index, name='index'),
]
......@@ -9,6 +9,7 @@ from sendfile import sendfile
from .models import BecomeAMemberDocument
from .models import Member
from .forms import MemberForm
def index(request):
......@@ -31,7 +32,7 @@ def index(request):
if query_filter and query_filter.isdigit() and not (
query_filter == 'ex' or
query_filter == 'honor' or
query_filter == 'old'):
query_filter == 'old'):
members = [obj for obj in members if
obj.current_membership and
obj.current_membership.since.year == int(query_filter)]
......@@ -125,13 +126,25 @@ def profile(request, pk=None):
return render(request, 'members/profile.html',
{'member': member, 'achievements': achievements.values()})
@login_required
def account(request):
return render(request, 'members/account.html')
@login_required
def edit_profile(request):
return render(request, 'members/account.html')
member = get_object_or_404(Member, user=request.user)
if request.POST:
form = MemberForm(request.POST)
if form.is_valid():
member = form.save()
else:
form = MemberForm(instance=member)
return render(request, 'members/edit_profile.html',
{'form': form})
def become_a_member(request):
......
Supports Markdown
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