mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-18 16:36:15 +00:00
Added detailed user profile
This commit is contained in:
@@ -12,7 +12,7 @@ from registration import signals
|
||||
#from registration.forms import RegistrationForm
|
||||
from seaserv import ccnet_threaded_rpc, unset_repo_passwd, is_passwd_set
|
||||
|
||||
from seahub.profile.models import Profile
|
||||
from seahub.profile.models import Profile, DetailedProfile
|
||||
|
||||
|
||||
UNUSABLE_PASSWORD = '!' # This will never be a valid hash
|
||||
@@ -295,9 +295,19 @@ class RegistrationBackend(object):
|
||||
password, site,
|
||||
send_email=settings.REGISTRATION_SEND_MAIL)
|
||||
|
||||
userid = kwargs['userid']
|
||||
if userid:
|
||||
ccnet_threaded_rpc.add_binding(new_user.username, userid)
|
||||
# userid = kwargs['userid']
|
||||
# if userid:
|
||||
# ccnet_threaded_rpc.add_binding(new_user.username, userid)
|
||||
|
||||
if settings.REQUIRE_DETAIL_ON_REGISTRATION:
|
||||
name = kwargs['name']
|
||||
department = kwargs['department']
|
||||
telephone = kwargs['telephone']
|
||||
note = kwargs['note']
|
||||
Profile.objects.add_profile(new_user.username, name, note)
|
||||
DetailedProfile.objects.add_detailed_profile(new_user.username,
|
||||
department,
|
||||
telephone)
|
||||
|
||||
signals.user_registered.send(sender=self.__class__,
|
||||
user=new_user,
|
||||
@@ -416,3 +426,14 @@ class RegistrationForm(forms.Form):
|
||||
raise forms.ValidationError(_("The two password fields didn't match."))
|
||||
return self.cleaned_data
|
||||
|
||||
class DetailedRegistrationForm(RegistrationForm):
|
||||
attrs_dict = { 'class': 'required' }
|
||||
|
||||
name = forms.CharField(widget=forms.TextInput(
|
||||
attrs=dict(attrs_dict, maxlength=64)), label=_("name"))
|
||||
department = forms.CharField(widget=forms.TextInput(
|
||||
attrs=dict(attrs_dict, maxlength=512)), label=_("department"))
|
||||
telephone = forms.CharField(widget=forms.TextInput(
|
||||
attrs=dict(attrs_dict, maxlength=100)), label=_("telephone"))
|
||||
note = forms.CharField(widget=forms.TextInput(
|
||||
attrs=dict(attrs_dict, maxlength=100)), label=_("note"))
|
||||
|
@@ -6,11 +6,13 @@ from django.conf import settings
|
||||
from registration.views import activate
|
||||
from registration.views import register
|
||||
|
||||
from seahub.base.accounts import RegistrationForm
|
||||
from seahub.base.accounts import RegistrationForm, DetailedRegistrationForm
|
||||
from seahub.base.generic import DirectTemplateView
|
||||
|
||||
form_class = DetailedRegistrationForm if settings.REQUIRE_DETAIL_ON_REGISTRATION \
|
||||
else RegistrationForm
|
||||
reg_dict = { 'backend': 'seahub.base.accounts.RegistrationBackend',
|
||||
'form_class': RegistrationForm,
|
||||
'form_class': form_class,
|
||||
}
|
||||
|
||||
if settings.ACTIVATE_AFTER_REGISTRATION == True:
|
||||
|
@@ -2,7 +2,25 @@
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from seahub.profile.models import Profile, DetailedProfile
|
||||
|
||||
class ProfileForm(forms.Form):
|
||||
nickname = forms.CharField(max_length=64, required=False)
|
||||
intro = forms.CharField(max_length=256, required=False)
|
||||
|
||||
def save(self, username):
|
||||
nickname = self.cleaned_data['nickname']
|
||||
intro = self.cleaned_data['intro']
|
||||
Profile.objects.add_or_update(username, nickname, intro)
|
||||
|
||||
|
||||
class DetailedProfileForm(ProfileForm):
|
||||
department = forms.CharField(max_length=512)
|
||||
telephone = forms.CharField(max_length=100)
|
||||
|
||||
def save(self, username):
|
||||
super(DetailedProfileForm, self).save(username)
|
||||
department = self.cleaned_data['department']
|
||||
telephone = self.cleaned_data['telephone']
|
||||
DetailedProfile.objects.add_or_update(username, department, telephone)
|
||||
|
||||
|
@@ -2,10 +2,28 @@ from django.db import models
|
||||
from django.core.cache import cache
|
||||
from django.dispatch import receiver
|
||||
|
||||
from settings import EMAIL_ID_CACHE_PREFIX, EMAIL_ID_CACHE_TIMEOUT
|
||||
from seahub.base.fields import LowerCaseCharField
|
||||
from seahub.profile.settings import EMAIL_ID_CACHE_PREFIX, EMAIL_ID_CACHE_TIMEOUT
|
||||
from registration.signals import user_registered
|
||||
|
||||
class ProfileManager(models.Manager):
|
||||
def add_profile(self, username, nickname, intro):
|
||||
"""
|
||||
"""
|
||||
profile = self.model(user=username, nickname=nickname, intro=intro)
|
||||
profile.save(using=self._db)
|
||||
return profile
|
||||
|
||||
def add_or_update(self, username, nickname, intro):
|
||||
try:
|
||||
profile = self.get(user=username)
|
||||
profile.nickname = nickname
|
||||
profile.intro = intro
|
||||
except Profile.DoesNotExist:
|
||||
profile = self.model(user=username, nickname=nickname, intro=intro)
|
||||
profile.save(using=self._db)
|
||||
return profile
|
||||
|
||||
def get_profile_by_user(self, username):
|
||||
"""Get a user's profile.
|
||||
"""
|
||||
@@ -20,6 +38,39 @@ class Profile(models.Model):
|
||||
intro = models.TextField(max_length=256, blank=True)
|
||||
objects = ProfileManager()
|
||||
|
||||
class DetailedProfileManager(models.Manager):
|
||||
def add_detailed_profile(self, username, department, telephone):
|
||||
d_profile = self.model(user=username, department=department,
|
||||
telephone=telephone)
|
||||
d_profile.save(using=self._db)
|
||||
return d_profile
|
||||
|
||||
def add_or_update(self, username, department, telephone):
|
||||
try:
|
||||
d_profile = self.get(user=username)
|
||||
d_profile.department = department
|
||||
d_profile.telephone = telephone
|
||||
except DetailedProfile.DoesNotExist:
|
||||
d_profile = self.model(user=username, department=department,
|
||||
telephone=telephone)
|
||||
d_profile.save(using=self._db)
|
||||
return d_profile
|
||||
|
||||
def get_detailed_profile_by_user(self, username):
|
||||
"""Get a user's profile.
|
||||
"""
|
||||
try:
|
||||
return super(DetailedProfileManager, self).get(user=username)
|
||||
except DetailedProfile.DoesNotExist:
|
||||
return None
|
||||
|
||||
class DetailedProfile(models.Model):
|
||||
user = LowerCaseCharField(max_length=255)
|
||||
department = models.CharField(max_length=512)
|
||||
telephone = models.CharField(max_length=100)
|
||||
objects = DetailedProfileManager()
|
||||
|
||||
########## signal handler
|
||||
@receiver(user_registered)
|
||||
def clean_email_id_cache(sender, **kwargs):
|
||||
from seahub.utils import normalize_cache_key
|
||||
|
@@ -54,6 +54,14 @@
|
||||
{% endfor %}
|
||||
<br/>
|
||||
<label>{% trans "About me:" %}</label><textarea name="intro">{{ form.data.intro }}</textarea>
|
||||
<br/>
|
||||
|
||||
{% if form.department and form.telephone %}
|
||||
<label>{% trans "Department:" %}</label><input type="text" name="department" value="{{ form.data.department }}" class="text-input" />
|
||||
<br/>
|
||||
<label>{% trans "Telephone:" %}</label><input type="text" name="telephone" value="{{ form.data.telephone }}" class="text-input" />
|
||||
{% endif %}
|
||||
|
||||
{% for error in form.intro.errors %}
|
||||
<span class="error">{{ error|escape }}</span>
|
||||
{% endfor %}
|
||||
|
@@ -15,6 +15,10 @@
|
||||
<div class="txt fright">
|
||||
<p>{{ nickname }}</p>
|
||||
<p class="intro">{{ intro }}</p>
|
||||
{% if d_profile %}
|
||||
<p>{{ d_profile.department }}</p>
|
||||
<p>{{ d_profile.telephone }}</p>
|
||||
{% endif %}
|
||||
{% if add_to_contacts %}
|
||||
<button class="add-to-contacts" data-email="{{user.username}}">{% trans "Add to Contacts" %}</button>
|
||||
{% endif %}
|
||||
|
@@ -12,8 +12,8 @@ from seaserv import ccnet_rpc, ccnet_threaded_rpc, get_binding_peerids, \
|
||||
seafile_api
|
||||
from pysearpc import SearpcError
|
||||
|
||||
from forms import ProfileForm
|
||||
from models import Profile
|
||||
from forms import ProfileForm, DetailedProfileForm
|
||||
from models import Profile, DetailedProfile
|
||||
from utils import refresh_cache
|
||||
from seahub.auth.decorators import login_required
|
||||
from seahub.utils import render_error
|
||||
@@ -29,20 +29,13 @@ def edit_profile(request):
|
||||
"""
|
||||
username = request.user.username
|
||||
|
||||
if request.method == 'POST':
|
||||
form = ProfileForm(request.POST)
|
||||
if form.is_valid():
|
||||
nickname = form.cleaned_data['nickname']
|
||||
intro = form.cleaned_data['intro']
|
||||
try:
|
||||
profile = Profile.objects.get(user=request.user.username)
|
||||
except Profile.DoesNotExist:
|
||||
profile = Profile()
|
||||
form_class = DetailedProfileForm if settings.REQUIRE_DETAIL_ON_REGISTRATION \
|
||||
else ProfileForm
|
||||
|
||||
profile.user = username
|
||||
profile.nickname = nickname
|
||||
profile.intro = intro
|
||||
profile.save()
|
||||
if request.method == 'POST':
|
||||
form = form_class(request.POST)
|
||||
if form.is_valid():
|
||||
form.save(username=username)
|
||||
messages.success(request, _(u'Successfully edited profile.'))
|
||||
# refresh nickname cache
|
||||
refresh_cache(request.user.username)
|
||||
@@ -51,14 +44,18 @@ def edit_profile(request):
|
||||
else:
|
||||
messages.error(request, _(u'Failed to edit profile'))
|
||||
else:
|
||||
try:
|
||||
profile = Profile.objects.get(user=request.user.username)
|
||||
form = ProfileForm({
|
||||
'nickname': profile.nickname,
|
||||
'intro': profile.intro,
|
||||
})
|
||||
except Profile.DoesNotExist:
|
||||
form = ProfileForm()
|
||||
profile = Profile.objects.get_profile_by_user(username)
|
||||
d_profile = DetailedProfile.objects.get_detailed_profile_by_user(
|
||||
username)
|
||||
|
||||
init_dict = {}
|
||||
if profile:
|
||||
init_dict['nickname'] = profile.nickname
|
||||
init_dict['intro'] = profile.intro
|
||||
if d_profile:
|
||||
init_dict['department'] = d_profile.department
|
||||
init_dict['telephone'] = d_profile.telephone
|
||||
form = form_class(init_dict)
|
||||
|
||||
# common logic
|
||||
try:
|
||||
@@ -106,11 +103,14 @@ def user_profile(request, username_or_id):
|
||||
if user is not None:
|
||||
profile = Profile.objects.get_profile_by_user(user.username)
|
||||
intro = profile.intro if profile else ''
|
||||
d_profile = DetailedProfile.objects.get_detailed_profile_by_user(
|
||||
user.username)
|
||||
c = Contact.objects.get_contact_by_user(request.user.username,
|
||||
user.username)
|
||||
add_to_contacts = True if c is None else False
|
||||
else:
|
||||
intro = _(u'Has not accepted invitation yet')
|
||||
d_profile = None
|
||||
add_to_contacts = False
|
||||
|
||||
return render_to_response('profile/user_profile.html', {
|
||||
@@ -119,6 +119,7 @@ def user_profile(request, username_or_id):
|
||||
'nickname': nickname,
|
||||
'intro': intro,
|
||||
'add_to_contacts': add_to_contacts,
|
||||
'd_profile': d_profile,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
@login_required
|
||||
|
@@ -263,6 +263,8 @@ ACTIVATE_AFTER_REGISTRATION = True
|
||||
# This option will be ignored if ``ACTIVATE_AFTER_REGISTRATION`` set to ``True``.
|
||||
REGISTRATION_SEND_MAIL = False
|
||||
|
||||
REQUIRE_DETAIL_ON_REGISTRATION = False
|
||||
|
||||
# Seafile-applet address and port, used in repo download
|
||||
CCNET_APPLET_ROOT = "http://127.0.0.1:13420"
|
||||
|
||||
|
@@ -8,12 +8,27 @@
|
||||
{% else %}
|
||||
<h2>{% trans "Signup" %}</h2>
|
||||
<form action="" method="post">{% csrf_token %}
|
||||
{% if form.name %}
|
||||
<label for="id_name">{% trans "Name" %}</label>
|
||||
{{ form.name }} {{ form.name.errors }}
|
||||
{% endif %}
|
||||
|
||||
<label for="id_email">{% trans "Email" %}</label>
|
||||
{{ form.email }} {{ form.email.errors }}
|
||||
<label for="id_password1">{% trans "Password" %}</label>
|
||||
{{ form.password1 }} {{ form.password1.errors }}
|
||||
<label for="id_password2">{% trans "Confirm Password" %}</label>
|
||||
{{ form.password2 }} {{ form.password2.errors }}
|
||||
|
||||
{% if form.department and form.telephone %}
|
||||
<label for="id_department">{% trans "Department" %}</label>
|
||||
{{ form.department }} {{ form.department.errors }}
|
||||
<label for="id_telephone">{% trans "Telephone" %}</label>
|
||||
{{ form.telephone }} {{ form.telephone.errors }}
|
||||
<label for="id_note">{% trans "Note" %}</label>
|
||||
{{ form.note }} {{ form.note.errors }}
|
||||
{% endif %}
|
||||
|
||||
<p class="error hide"></p>
|
||||
<input type="submit" value="{% trans "Submit" %}" class="submit" />
|
||||
</form>
|
||||
|
@@ -19,8 +19,13 @@
|
||||
<div class="info-item-bottom home-profile ovhd">
|
||||
{% avatar email 48 %}
|
||||
<p class="txt fright">
|
||||
{% if nickname %}
|
||||
{{ nickname }}
|
||||
{% if profile %}
|
||||
<p>{{ profile.nickname }}</p>
|
||||
<p>{{ profile.intro }}</p>
|
||||
{% endif %}
|
||||
{% if d_profile %}
|
||||
<p>{{ d_profile.department }}</p>
|
||||
<p>{{ d_profile.telephone }}</p>
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
|
@@ -27,7 +27,7 @@ from seahub.auth.decorators import login_required
|
||||
from seahub.utils import IS_EMAIL_CONFIGURED
|
||||
from seahub.views import get_system_default_repo_id
|
||||
from seahub.forms import SetUserQuotaForm, AddUserForm
|
||||
from seahub.profile.models import Profile
|
||||
from seahub.profile.models import Profile, DetailedProfile
|
||||
from seahub.share.models import FileShare
|
||||
|
||||
import seahub.settings as settings
|
||||
@@ -275,12 +275,9 @@ def user_info(request, email):
|
||||
# Repos that are share to user
|
||||
in_repos = seafile_api.get_share_in_repo_list(email, -1, -1)
|
||||
|
||||
# get nickname
|
||||
if not Profile.objects.filter(user=email):
|
||||
nickname = ''
|
||||
else:
|
||||
profile = Profile.objects.filter(user=email)[0]
|
||||
nickname = profile.nickname
|
||||
# get user profile
|
||||
profile = Profile.objects.get_profile_by_user(email)
|
||||
d_profile = DetailedProfile.objects.get_detailed_profile_by_user(email)
|
||||
|
||||
return render_to_response(
|
||||
'sysadmin/userinfo.html', {
|
||||
@@ -292,7 +289,8 @@ def user_info(request, email):
|
||||
'my_usage': my_usage,
|
||||
'in_repos': in_repos,
|
||||
'email': email,
|
||||
'nickname': nickname,
|
||||
'profile': profile,
|
||||
'd_profile': d_profile,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
@login_required
|
||||
|
Reference in New Issue
Block a user