diff --git a/seahub/base/generic.py b/seahub/base/generic.py new file mode 100644 index 0000000000..bd1cc17a0b --- /dev/null +++ b/seahub/base/generic.py @@ -0,0 +1,16 @@ +from django.views.generic import TemplateView + +class DirectTemplateView(TemplateView): + """ + Extend Django ``TemplateView`` to accept extra contexts. + """ + extra_context = None + def get_context_data(self, **kwargs): + context = super(self.__class__, self).get_context_data(**kwargs) + if self.extra_context is not None: + for key, value in self.extra_context.items(): + if callable(value): + context[key] = value() + else: + context[key] = value + return context diff --git a/seahub/base/registration_urls.py b/seahub/base/registration_urls.py index 4438ba3b15..983eabed98 100644 --- a/seahub/base/registration_urls.py +++ b/seahub/base/registration_urls.py @@ -7,6 +7,7 @@ from registration.views import activate from registration.views import register from seahub.base.accounts import RegistrationForm +from seahub.base.generic import DirectTemplateView reg_dict = { 'backend': 'seahub.base.accounts.RegistrationBackend', 'form_class': RegistrationForm, @@ -42,12 +43,11 @@ if ENABLE_SIGNUP: register, reg_dict, name='registration_register'), - # Refer http://stackoverflow.com/questions/11005733/moving-from-direct-to-template-to-new-templateview-in-django to migrate direct_to_template with extra_context. - # url(r'^register/complete/$', - # TemplateView.as_view( - # template_name='registration/registration_complete.html', - # extra_context={ 'send_mail': settings.REGISTRATION_SEND_MAIL } ), - # name='registration_complete'), + url(r'^register/complete/$', + DirectTemplateView.as_view( + template_name='registration/registration_complete.html', + extra_context={ 'send_mail': settings.REGISTRATION_SEND_MAIL } ), + name='registration_complete'), url(r'^register/closed/$', TemplateView.as_view(template_name='registration/registration_closed.html'), name='registration_disallowed'), diff --git a/seahub/settings.py b/seahub/settings.py index 35259b2af1..d4d386781f 100644 --- a/seahub/settings.py +++ b/seahub/settings.py @@ -242,10 +242,11 @@ MAX_UPLOAD_FILE_NAME_LEN = 255 MAX_FILE_NAME = MAX_UPLOAD_FILE_NAME_LEN MAX_PATH = 4096 -# Set to True when user will be activaed after registration, -# and no email sending +# Whether or not activate user when registration complete. +# If set to ``False``, new user will be activated by admin or via activate link. ACTIVATE_AFTER_REGISTRATION = True -# In order to use email sending, `ACTIVATE_AFTER_REGISTRATION` must set to False +# Whether or not send activation Email to user when registration complete. +# This option will be ignored if ``ACTIVATE_AFTER_REGISTRATION`` set to ``True``. REGISTRATION_SEND_MAIL = False # Seafile-applet address and port, used in repo download diff --git a/seahub/templates/registration/registration_complete.html b/seahub/templates/registration/registration_complete.html index 72c3a1930c..c5aa7eb5f8 100644 --- a/seahub/templates/registration/registration_complete.html +++ b/seahub/templates/registration/registration_complete.html @@ -1,11 +1,14 @@ {% extends "myhome_base.html" %} -{% block title %}感谢注册{% endblock %} +{% load i18n %} + +{% block title %}{% trans "Registration complete" %}{% endblock %} + {% block main_panel %}
感谢注册,激活邮件已发往您的邮箱,请查收。如果您在收件箱里没找到,请检查下是否被当成垃圾邮件了。
+{% trans "An activation email has been sent. Please check your email and click on the link to activate your account." %}
{% else %} -感谢注册,请等待管理员激活你的帐号。
+{% trans "Registration complete, please wait for administrator to activate your account." %}
{% endif %}