diff --git a/src/accounts/forms.py b/src/accounts/forms.py index 15e24d2..8286102 100644 --- a/src/accounts/forms.py +++ b/src/accounts/forms.py @@ -2,7 +2,6 @@ from django import forms from django.contrib.auth import get_user_model -from django.contrib.auth.forms import UserCreationForm as UserCreationForm_ from django.utils.translation import ugettext_lazy as _ from super_archives.models import MailingList diff --git a/src/accounts/templates/accounts/signup-form.html b/src/accounts/templates/accounts/signup-form.html deleted file mode 100644 index 72ffae1..0000000 --- a/src/accounts/templates/accounts/signup-form.html +++ /dev/null @@ -1,76 +0,0 @@ -{% extends "base.html" %} -{% load form_field %} -{% load i18n %} -{% block main-content %} - -

{% trans "Sign up" %}

- -
- {% if form.errors %} -
- {% trans "Please correct the errors below and try again" %} -
- {% endif %} - -
- {% for field in form %} - {% if field.errors %} - {{ field.label }} - {% endif %} - {% endfor %} -
-
- - -

- -

- -
- {% csrf_token %} - -
- -
- {% for legend, fields in fieldsets %} -
-
-
- {{ legend }} - {% for field in fields %} -
- - {% if field.name == 'username' %} - - {% elif field.name == 'lists' %} - {% for choice in field %} -
- {{ choice }} -
- {% endfor %} - {% else %} - {{ field }} - {% endif %} - {{ field.errors }} -
- - {% endfor %} -
-
-
- {% endfor %} - -
-
- -
-
- -
-
- -
- -{% endblock %} diff --git a/src/accounts/templates/accounts/user-profile.html b/src/accounts/templates/accounts/user-profile.html deleted file mode 100644 index c25620f..0000000 --- a/src/accounts/templates/accounts/user-profile.html +++ /dev/null @@ -1,101 +0,0 @@ -{% extends "base.html" %} -{% load i18n form_field gravatar %} - -{% block head_js %} - {% include "pizza-chart.html" with chart_div="collabs" chart_height=300 %} - {% include "pizza-chart.html" with chart_div="collabs2" chart_height=300 %} -{% endblock %} - -{% block main-content %} - -
-
-
- {% gravatar user_.email 200 %} -
- -

- {{ user_.get_full_name }} - {{ user_.username }} -

- - {% ifequal request.user user_ %} -   {% trans "update your profile"|title %} - {% endifequal %} - -
- - -
- -
-
-
-

{% trans "Contributions by Area" %}

-
-
-
-
-
-
- - -
-
-
-

{% trans "Mailing list Participation" %}

-
-
-
-
-
-
- -
-
-
-

{% trans "Latest posted" %}

- -
- -
-

{% trans "Community inside participations" %}

- -
- -
- -{% endblock %} diff --git a/src/accounts/templates/accounts/user_create_form.html b/src/accounts/templates/accounts/user_create_form.html new file mode 100644 index 0000000..72d0e29 --- /dev/null +++ b/src/accounts/templates/accounts/user_create_form.html @@ -0,0 +1,67 @@ +{% extends "base.html" %} +{% load form_field %} +{% load i18n %} +{% block main-content %} + +

{% trans "Sign up" %}

+ +
+ {% if form.errors %} +
+ {% trans "Please correct the errors below and try again" %} +
+ {% endif %} +
+ + +

+ +

+ +
+ {% csrf_token %} + +
+ +
+
+
+
+ {% trans 'Personal Information' %} + {% for field in user_form %} +
+ + {{ field }} + {{ field.errors }} +
+ {% endfor %} +
+
+
+ +
+
+
+ {% trans 'Subscribe to mail lists' %} + {% for choice in lists_form.lists %} +
{{ choice }}
+ {% endfor %} + {{ lists_form.errors }} +
+
+
+ +
+
+ +
+
+ +
+
+ +
+ +{% endblock %} diff --git a/src/accounts/templates/accounts/user_detail.html b/src/accounts/templates/accounts/user_detail.html new file mode 100644 index 0000000..3e7fc19 --- /dev/null +++ b/src/accounts/templates/accounts/user_detail.html @@ -0,0 +1,101 @@ +{% extends "base.html" %} +{% load i18n gravatar %} + +{% block head_js %} + {% include "pizza-chart.html" with chart_div="collabs" chart_height=300 %} + {% include "pizza-chart.html" with chart_div="collabs2" chart_height=300 %} +{% endblock %} + +{% block main-content %} + +
+
+
+ {% gravatar user_.email 200 %} +
+ +

+ {{ user_.get_full_name }} + {{ user_.username }} +

+ + {% ifequal request.user user_ %} +   {% trans "update your profile"|title %} + {% endifequal %} + +
+ + +
+ +
+
+
+

{% trans "Contributions by Area" %}

+
+
+
+
+
+
+ + +
+
+
+

{% trans "Mailing list Participation" %}

+
+
+
+
+
+
+ +
+
+
+

{% trans "Latest posted" %}

+ +
+ +
+

{% trans "Community inside participations" %}

+ +
+ +
+ +{% endblock %} diff --git a/src/accounts/urls.py b/src/accounts/urls.py index aff2db9..360c08f 100644 --- a/src/accounts/urls.py +++ b/src/accounts/urls.py @@ -1,7 +1,7 @@ from django.conf.urls import patterns, include, url -from .views import UserProfileDetailView +from .views import UserProfileDetailView, UserProfileUpdateView urlpatterns = patterns('', @@ -12,6 +12,6 @@ urlpatterns = patterns('', url(r'^(?P[\w@+.-]+)/?$', UserProfileDetailView.as_view(), name='user_profile'), - #url(r'^user/(?P[\w@+.-]+)/edit/?$', - # 'colab.deprecated.views.userprofile.update', name='user_profile_update'), + url(r'^(?P[\w@+.-]+)/edit/?$', + UserProfileUpdateView.as_view(), name='user_profile_update'), ) diff --git a/src/accounts/views.py b/src/accounts/views.py index f0d7a86..ecc6116 100644 --- a/src/accounts/views.py +++ b/src/accounts/views.py @@ -4,7 +4,7 @@ from django.contrib import messages from django.contrib.auth import get_user_model -from django.views.generic import DetailView +from django.views.generic import DetailView, UpdateView from django.utils.translation import ugettext as _ from django.shortcuts import render, redirect @@ -15,12 +15,36 @@ from super_archives.models import EmailAddress, Message from .forms import NewUserForm, ListsForm -class UserProfileDetailView(DetailView): +class UserProfileBaseMixin(object): model = get_user_model() slug_field = 'username' slug_url_kwarg = 'username' context_object_name = 'user_' - template_name = 'accounts/user-profile.html' + + +class UserProfileUpdateView(UserProfileBaseMixin, UpdateView): + template_name = 'accounts/user_form.html' + #form_class = UserUpdateForm + + def get_success_url(self): + return reverse('user_profile', kwargs={'username': self.object.username}) + + def get_initial(self): + return { + 'first_name': self.object.first_name, + 'last_name': self.object.last_name, + 'email': self.object.email, + 'institution': self.object.profile.institution, + 'role': self.object.profile.role, + 'twitter': self.object.profile.twitter, + 'facebook': self.object.profile.facebook, + 'google_talk': self.object.profile.google_talk, + 'webpage': self.object.profile.webpage, + } + + +class UserProfileDetailView(UserProfileBaseMixin, DetailView): + template_name = 'accounts/user_detail.html' def get_context_data(self, **kwargs): user = self.object @@ -50,14 +74,14 @@ def signup(request): if request.method == 'GET': user_form = NewUserForm() lists_form = ListsForm() - return render(request, 'registration/registration_form.html', + return render(request, 'accounts/user_create_form.html', {'user_form': user_form, 'lists_form': lists_form}) user_form = NewUserForm(request.POST) lists_form = ListsForm(request.POST) if not user_form.is_valid() or not lists_form.is_valid(): - return render(request, 'registration/registration_form.html', + return render(request, 'accounts/user_create_form.html', {'user_form': user_form, 'lists_form': lists_form}) user = user_form.save() @@ -80,4 +104,3 @@ def signup(request): 'Profiles not validated are deleted in 24h.')) return redirect('user_profile', username=user.username) - diff --git a/src/super_archives/templatetags/form_field.py b/src/super_archives/templatetags/form_field.py deleted file mode 100644 index 82f7f2e..0000000 --- a/src/super_archives/templatetags/form_field.py +++ /dev/null @@ -1,64 +0,0 @@ -from django import template -from django import forms - -def render_form_field(parser, token): - variables = token.split_contents() - - if len(variables) == 2: - tag_name, form_field = variables - default_value = 'None' - elif len(variables) == 3: - tag_name, form_field, default_value = variables - else: - raise template.TemplateSyntaxError - - return RenderFormField(form_field, default_value) - - -class RenderFormField(template.Node): - - def __init__(self, form_field, default_value): - self.form_field_nocontext = template.Variable(form_field) - self.default_value_nocontext = template.Variable(default_value) - - def render(self, context): - editable = context.get('editable', True) - - class_ = u'' - errors = u'' - form_field_tag = u'' - try: - form_field = self.form_field_nocontext.resolve(context) - except template.VariableDoesNotExist: - return u'' - - if form_field.errors: - class_ += u'error' - if form_field.field.required: - class_ += u' required' - if form_field.errors: - errors = u'
' + form_field.errors.as_text() - - try: - default_value = self.default_value_nocontext.resolve(context) - except template.VariableDoesNotExist: - default_value = u'' - - if editable: - form_field_tag = u'
' + unicode(form_field) - elif isinstance(form_field.field, forms.URLField): - form_field_tag = u"""%s""" % ( - default_value, default_value) - else: - form_field_tag = default_value - - return u"""

%s %s %s

""" % ( - class_, - form_field.label_tag(), - form_field_tag, - errors - ) - - -register = template.Library() -register.tag('render_form_field', render_form_field) diff --git a/src/super_archives/validators.py b/src/super_archives/validators.py deleted file mode 100644 index 09049dc..0000000 --- a/src/super_archives/validators.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- - -from django.core.exceptions import ValidationError - -class UniqueValidator(object): - - def __init__(self, model, field_name): - self.model = model - self.field_name = field_name - - def __call__(self, value): - result = self.model.objects.filter(**{self.field_name: value}) - if result: - msg = u'Já existente. Escolha outro.' - raise ValidationError(msg) -- libgit2 0.21.2