diff --git a/seahub/base/accounts.py b/seahub/base/accounts.py
index eb01198ebe..612edc8e9b 100644
--- a/seahub/base/accounts.py
+++ b/seahub/base/accounts.py
@@ -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"))
diff --git a/seahub/base/registration_urls.py b/seahub/base/registration_urls.py
index 983eabed98..63940c6d12 100644
--- a/seahub/base/registration_urls.py
+++ b/seahub/base/registration_urls.py
@@ -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:
diff --git a/seahub/profile/forms.py b/seahub/profile/forms.py
index 6c6f2e0bf5..006378b3df 100644
--- a/seahub/profile/forms.py
+++ b/seahub/profile/forms.py
@@ -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)
+
diff --git a/seahub/profile/models.py b/seahub/profile/models.py
index 3b6fb06292..32c82c5f3e 100644
--- a/seahub/profile/models.py
+++ b/seahub/profile/models.py
@@ -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
diff --git a/seahub/profile/templates/profile/set_profile.html b/seahub/profile/templates/profile/set_profile.html
index cf7ca421eb..cfadbede62 100644
--- a/seahub/profile/templates/profile/set_profile.html
+++ b/seahub/profile/templates/profile/set_profile.html
@@ -54,6 +54,14 @@
{% endfor %}
+
+
+ {% if form.department and form.telephone %}
+
+
+
+ {% endif %}
+
{% for error in form.intro.errors %}
{{ error|escape }}
{% endfor %}
diff --git a/seahub/profile/templates/profile/user_profile.html b/seahub/profile/templates/profile/user_profile.html
index 462fe86b0e..e5606a52c1 100644
--- a/seahub/profile/templates/profile/user_profile.html
+++ b/seahub/profile/templates/profile/user_profile.html
@@ -15,6 +15,10 @@
{{ nickname }}
{{ intro }}
+ {% if d_profile %} +{{ d_profile.department }}
+{{ d_profile.telephone }}
+ {% endif %} {% if add_to_contacts %} {% endif %} diff --git a/seahub/profile/views.py b/seahub/profile/views.py index d92cd0751e..511102284f 100644 --- a/seahub/profile/views.py +++ b/seahub/profile/views.py @@ -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 + form_class = DetailedProfileForm if settings.REQUIRE_DETAIL_ON_REGISTRATION \ + else ProfileForm + if request.method == 'POST': - form = ProfileForm(request.POST) + form = form_class(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() - - profile.user = username - profile.nickname = nickname - profile.intro = intro - profile.save() + form.save(username=username) messages.success(request, _(u'Successfully edited profile.')) # refresh nickname cache refresh_cache(request.user.username) @@ -51,15 +44,19 @@ 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: server_crypto = UserOptions.objects.is_server_crypto(username) @@ -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 diff --git a/seahub/settings.py b/seahub/settings.py index c42ebcabca..088d21594c 100644 --- a/seahub/settings.py +++ b/seahub/settings.py @@ -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" diff --git a/seahub/templates/registration/registration_form.html b/seahub/templates/registration/registration_form.html index 881e7d0667..2793fd40ee 100644 --- a/seahub/templates/registration/registration_form.html +++ b/seahub/templates/registration/registration_form.html @@ -8,12 +8,27 @@ {% else %}- {% if nickname %} - {{ nickname }} + {% if profile %} +
{{ profile.nickname }}
+{{ profile.intro }}
+ {% endif %} + {% if d_profile %} +{{ d_profile.department }}
+{{ d_profile.telephone }}
{% endif %}