from django.core.exceptions import ObjectDoesNotExist
from django.utils.translation import ugettext_lazy as _
import django.db.models
+from django.forms import ModelForm
class Revision(ModelCore):
class Meta(MetaCore):
db_table = 'profiles'
-
+
+class UserProfileForm(ModelForm):
+ class Meta:
+ model = UserProfile
--- /dev/null
+{% extends "telemeta_default/profile_edit.html" %}
{% load i18n %}
{% load telemeta_utils %}
-{% block head_title %}{% trans "User Profile" %} : {{ user.username }}{% endblock %}
+{% block head_title %}{% trans "User Profile" %} : {{ usr.username }}{% endblock %}
{% block submenu %}
<div>
{% block tools %}
{% if user.is_authenticated %}
- {% trans "Edit" %}
+ <a href="{% url telemeta-profile-edit usr.username %}" class="component_icon button icon_edit">{% trans "Edit" %}</a>
{% endif %}
{% endblock tools %}
</div>
{% endblock %}
{% block content %}
- <h3>{% trans "User profile" %} : {{ user.username }}</h3>
- <div style="padding-top: 1em;">
+ <h3>{% trans "User profile" %} : {{ usr.username }}</h3>
+ <div class="infos" style="padding-top: 1em;">
<dl class="listing">
<dt>{% trans "First Name" %}</dt><dd>{{ usr.first_name }}</dd>
<dt>{% trans "Last Name" %}</dt><dd>{{ usr.last_name }}</dd>
--- /dev/null
+{% extends "telemeta/profile_detail.html" %}
+{% load i18n %}
+{% load telemeta_utils %}
+
+{% block tools %}
+ <a href="{% url telemeta-profile-detail usr.username %}" class="component_icon button icon_cancel">{% trans "Cancel" %}</a>
+{% endblock %}
+
+{% block content %}
+ <h3>{% trans "User profile" %} : {{ usr.username }}</h3>
+ <div class="infos" style="padding-top: 1em;">
+ <form method="POST" id="_editUserProfileForm" action="">{% csrf_token %}
+ <table>
+ {% for field in form %}
+ {% if field.html_name != "user" %}
+ <tr>
+ <tr><td class="error">{{ field.errors }}</td></tr>
+ <td>{{ field.label_tag }}:</td><td> {{ field }}</td>
+ </tr>
+ {% else %}
+ <tr style="display:none;">
+ <td>{{ field.label_tag }}:</td><td> {{ field }}</td>
+ </tr>
+ {% endif %}
+ {% endfor %}
+ </table>
+ <div align="center">
+ <a href="{% url telemeta-profile-detail usr.username %}" class="component_icon button icon_cancel">{% trans "Cancel" %}</a>
+ <a href="#" class="component_icon button icon_save"
+ onclick="document.getElementById('_editUserProfileForm').submit(); return false;">{% trans "Save" %}</a>
+ </div>
+ </form>
+ </div>
+{% endblock %}
# Profile
url(r'^accounts/(?P<username>[A-Za-z0-9._-]+)/profile/$', web_view.profile_detail, name="telemeta-profile-detail"),
+ url(r'^accounts/(?P<username>[A-Za-z0-9._-]+)/profile/edit/$', web_view.profile_edit, name="telemeta-profile-edit"),
# JSON RPC
url(r'^json/browse/', 'jsonrpc.views.browse', name="jsonrpc_browser"), # for the graphical browser/web console only, omissible
def not_allowed(self, request, public_id = None):
mess = ugettext('Access not allowed')
title = public_id + ' : ' + mess
- description = 'Please login or contact the website administator to get private access.'
+ description = 'Please login or contact the website administator to get admin or private access.'
messages.error(request, title)
return render(request, 'telemeta/messages.html', {'description' : description})
except:
profile = None
return render(request, template, {'profile' : profile, 'usr': user})
+
+ def profile_edit(self, request, username, template='telemeta/profile_edit.html'):
+ user = User.objects.get(username=username)
+ if user != request.user and not request.user.is_staff:
+ return HttpResponseRedirect('/accounts/'+username+'/not_allowed/')
+
+ try:
+ profile = user.get_profile()
+ except:
+ profile = UserProfile(user=user)
+# profile.save()
+
+ if request.method == 'POST':
+ form = UserProfileForm(data=request.POST, instance=profile)
+ if form.is_valid():
+ form.save()
+ return HttpResponseRedirect('/accounts/'+username+'/profile/')
+ else:
+ form = UserProfileForm(instance=profile)
+ return render(request, template, {"form": form, 'usr': user})
+