mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-09 03:54:08 +00:00
Make it possible for a contributor to edit his/her own data
Only for users that are already listed under /community/contributors/, make it possible to edit this data, so we don't have to track it manually. For obvious reasons, we don't allow editing of the "contributor level" field... This also changes the contributors model to send a notification to the slaves list whenever a contributor record is changed, so we can do post-moderation if necessary.
This commit is contained in:
@ -4,6 +4,7 @@ import re
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from pgweb.core.models import UserProfile
|
||||
from pgweb.contributors.models import Contributor
|
||||
|
||||
class SignupForm(forms.Form):
|
||||
username = forms.CharField(max_length=30)
|
||||
@ -57,3 +58,8 @@ class UserForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('first_name', 'last_name', )
|
||||
|
||||
class ContributorForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Contributor
|
||||
exclude = ('ctype', 'lastname', 'firstname', 'email', 'user', )
|
||||
|
@ -1,6 +1,6 @@
|
||||
from django.contrib.auth.models import User
|
||||
import django.contrib.auth.views as authviews
|
||||
from django.http import HttpResponseRedirect, HttpResponse, Http404
|
||||
from django.http import HttpResponseRedirect, Http404
|
||||
from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.utils.http import int_to_base36
|
||||
@ -10,7 +10,6 @@ from django.conf import settings
|
||||
|
||||
import base64
|
||||
import urllib
|
||||
import re
|
||||
from Crypto.Cipher import AES
|
||||
from Crypto import Random
|
||||
import time
|
||||
@ -18,16 +17,17 @@ import time
|
||||
from pgweb.util.decorators import ssl_required
|
||||
from pgweb.util.contexts import NavContext
|
||||
from pgweb.util.misc import send_template_mail
|
||||
from pgweb.util.helpers import HttpServerError, simple_form
|
||||
from pgweb.util.helpers import HttpServerError
|
||||
|
||||
from pgweb.news.models import NewsArticle
|
||||
from pgweb.events.models import Event
|
||||
from pgweb.core.models import Organisation, UserProfile
|
||||
from pgweb.contributors.models import Contributor
|
||||
from pgweb.downloads.models import Product
|
||||
from pgweb.profserv.models import ProfessionalService
|
||||
|
||||
from models import CommunityAuthSite
|
||||
from forms import SignupForm, UserForm, UserProfileForm
|
||||
from forms import SignupForm, UserForm, UserProfileForm, ContributorForm
|
||||
|
||||
@ssl_required
|
||||
@login_required
|
||||
@ -77,23 +77,39 @@ def profile(request):
|
||||
# models on a single form.
|
||||
(profile, created) = UserProfile.objects.get_or_create(pk=request.user.pk)
|
||||
|
||||
# We may have a contributor record - and we only show that part of the
|
||||
# form if we have it for this user.
|
||||
try:
|
||||
contrib = Contributor.objects.get(user=request.user.pk)
|
||||
except Contributor.DoesNotExist:
|
||||
contrib = None
|
||||
|
||||
contribform = None
|
||||
|
||||
if request.method == 'POST':
|
||||
# Process this form
|
||||
userform = UserForm(data=request.POST, instance=request.user)
|
||||
profileform = UserProfileForm(data=request.POST, instance=profile)
|
||||
if contrib:
|
||||
contribform = ContributorForm(data=request.POST, instance=contrib)
|
||||
|
||||
if userform.is_valid() and profileform.is_valid():
|
||||
if userform.is_valid() and profileform.is_valid() and (not contrib or contribform.is_valid()):
|
||||
userform.save()
|
||||
profileform.save()
|
||||
if contrib:
|
||||
contribform.save()
|
||||
return HttpResponseRedirect("/account/")
|
||||
else:
|
||||
# Generate form
|
||||
userform = UserForm(instance=request.user)
|
||||
profileform = UserProfileForm(instance=profile)
|
||||
if contrib:
|
||||
contribform = ContributorForm(instance=contrib)
|
||||
|
||||
return render_to_response('account/userprofileform.html', {
|
||||
'userform': userform,
|
||||
'profileform': profileform,
|
||||
'contribform': contribform,
|
||||
}, NavContext(request, "account"))
|
||||
|
||||
@ssl_required
|
||||
|
@ -23,11 +23,12 @@ class Contributor(PgModel, models.Model):
|
||||
firstname = models.CharField(max_length=100, null=False, blank=False)
|
||||
email = models.EmailField(null=False, blank=False)
|
||||
company = models.CharField(max_length=100, null=True, blank=True)
|
||||
companyurl = models.URLField(max_length=100, null=True, blank=True)
|
||||
companyurl = models.URLField(max_length=100, null=True, blank=True, verbose_name='Company URL')
|
||||
location = models.CharField(max_length=100, null=True, blank=True)
|
||||
contribution = models.TextField(null=True, blank=True)
|
||||
user = models.ForeignKey(User, null=True, blank=True)
|
||||
|
||||
send_notification=True
|
||||
purge_urls = ('/community/contributors/', )
|
||||
|
||||
def __unicode__(self):
|
||||
|
@ -5,7 +5,7 @@
|
||||
<form method="post" action=".">{% csrf_token %}
|
||||
|
||||
<table class="pgGenericFormTable">
|
||||
{%if form.errors%}
|
||||
{%if userform.errors or profileform.errors or contribform.errors %}
|
||||
<tr class="errorheader">
|
||||
<td colspan="2">Please correct the errors below, and re-submit the form.</td>
|
||||
</tr>
|
||||
@ -35,6 +35,30 @@
|
||||
</tr>
|
||||
{%endfor%}
|
||||
</table>
|
||||
|
||||
{%if contribform%}
|
||||
<h2>Edit contributor information</h2>
|
||||
<p>
|
||||
You can edit the information that's shown on the
|
||||
<a href="/community/contributors/">contributors</a> page. Please be
|
||||
careful as your changes will take effect immediately.
|
||||
</p>
|
||||
<table class="pgGenericFormTable">
|
||||
{%for field in contribform%}
|
||||
{%if field.errors %}
|
||||
<tr class="error">
|
||||
<td colspan="2">{{field.errors.as_ul}}</td>
|
||||
</tr>
|
||||
{%endif%}
|
||||
<tr {%if field.errors%}class="errorinfo"{%endif%}>
|
||||
<th>{{field.label_tag}}{%if field.help_text %}<br/>
|
||||
<span class="formfieldhelp">{{field.help_text}}</span>{%endif%}</th>
|
||||
<td>{{field}}</td>
|
||||
</tr>
|
||||
{%endfor%}
|
||||
</table>
|
||||
{%endif%}
|
||||
|
||||
<input type="submit" value="Save" />
|
||||
</form>
|
||||
{%endblock%}
|
||||
|
Reference in New Issue
Block a user