Browse Source

Simple forum terms of service app.

Ralfp 12 years ago
parent
commit
a11e104e66

+ 1 - 1
misago/forms/__init__.py

@@ -156,4 +156,4 @@ class YesNoSwitch(forms.CheckboxInput):
     """
     Custom Yes-No switch as fancier alternative to checkboxes
     """
-    pass
+    pass

+ 25 - 20
misago/register/forms.py

@@ -25,26 +25,31 @@ class UserRegisterForm(Form):
                       {
                        'different': _("Entered passwords do not match."),
                        }]
-    
-    layout = [
-              (
-               None,
-               [('username', {'label': _('Username'), 'help_text': _("Your displayed username. Between 3 and 15 characters, only letters and digits are allowed."),'attrs': {'placeholder': _("Enter your desired username")}})]
-               ),
-              (
-               None,
-               [('nested', [('email', {'label': _('E-mail address'), 'help_text': _("Working e-mail inbox is required to maintain control over your forum account."), 'attrs': {'placeholder': _("Enter your e-mail")}, 'width': 50}), ('email_rep', {'attrs': {'placeholder': _("Repeat your e-mail")}, 'width': 50})]), 
-               ('nested', [('password', {'label': _('Password'), 'help_text': _("Password you will be using to sign in to your account. Make sure it's strong."), 'has_value': False, 'attrs': {'placeholder': _("Enter your password")}, 'width': 50}), ('password_rep', {'has_value': False, 'attrs': {'placeholder': _("Repeat your password")}, 'width': 50})])]
-               ),
-              (
-               None,
-               ['captcha_qa', 'recaptcha']
-               ),
-              (
-               None,
-               [('accept_tos', {'label': _("Forum Terms of Service"), 'inline': _("I have read and accept this forums Terms of Service.")})]
-               ),
-              ]
+      
+    def finalize_form(self):
+        self.layout = [
+                      (
+                       None,
+                       [('username', {'label': _('Username'), 'help_text': _("Your displayed username. Between 3 and 15 characters, only letters and digits are allowed."),'attrs': {'placeholder': _("Enter your desired username")}})]
+                       ),
+                      (
+                       None,
+                       [('nested', [('email', {'label': _('E-mail address'), 'help_text': _("Working e-mail inbox is required to maintain control over your forum account."), 'attrs': {'placeholder': _("Enter your e-mail")}, 'width': 50}), ('email_rep', {'attrs': {'placeholder': _("Repeat your e-mail")}, 'width': 50})]), 
+                       ('nested', [('password', {'label': _('Password'), 'help_text': _("Password you will be using to sign in to your account. Make sure it's strong."), 'has_value': False, 'attrs': {'placeholder': _("Enter your password")}, 'width': 50}), ('password_rep', {'has_value': False, 'attrs': {'placeholder': _("Repeat your password")}, 'width': 50})])]
+                       ),
+                      (
+                       None,
+                       ['captcha_qa', 'recaptcha']
+                       ),
+                      (
+                       None,
+                       [('accept_tos', {'label': _("Forum Terms of Service"), 'widget': 'forumTos'})]
+                       ),
+                      ]
+        
+        if not self.request.settings['tos_url'] and not self.request.settings['tos_content']:
+            del self.fields['accept_tos']
+            del self.layout[3]
         
     def clean_username(self):
         new_user = User.objects.get_blank_user()

+ 1 - 0
misago/settings_base.py

@@ -145,6 +145,7 @@ INSTALLED_APPS = (
     'misago.settings', # Database level application configuration
     'misago.monitor', # Forum statistics monitor
     'misago.utils', # Utility classes
+    'misago.tos', # Terms of Service AKA Guidelines
     # Applications with dependencies
     'misago.banning', # Banning and blacklisting users
     'misago.crawlers', # Web crawlers handling

+ 0 - 0
misago/tos/__init__.py


+ 43 - 0
misago/tos/fixtures.py

@@ -0,0 +1,43 @@
+from misago.settings.fixtures import load_settings_fixture, update_settings_fixture
+from misago.utils import ugettext_lazy as _
+from misago.utils import get_msgid
+
+settings_fixtures = (
+    # Avatars Settings
+    ('tos', {
+         'name': _("Forum Terms of Service"),
+         'description': _("Those settings allow you to set up forum terms of service."),
+         'settings': (
+            ('tos_title', {
+                'value':        "Terms of Service",
+                'type':         "string",
+                'input':        "text",
+                'separator':    _("Terms of Service Settings"),
+                'name':         _("Page Title"),
+                'description':  _("Title of page community ToS are displayed on."),
+            }),
+            ('tos_url', {
+                'value':        "",
+                'type':         "string",
+                'input':        "text",
+                'name':         _("Link to remote page with ToS"),
+                'description':  _("If your forum's ToS are located on remote page, enter here its address."),
+            }),
+            ('tos_content', {
+                'value':        "",
+                'type':         "string",
+                'input':        "textarea",
+                'name':         _("OR enter ToS content"),
+                'description':  _("Instead of linking to remote page, forum can create dedicated ToS page for you. To display ToS page, enter here your forum Terms of Service."),
+            }),
+       ),
+    }),
+)
+
+
+def load_fixtures():
+    load_settings_fixture(settings_fixtures)
+    
+    
+def update_fixtures():
+    update_settings_fixture(settings_fixtures)

+ 0 - 0
misago/tos/forms.py


+ 8 - 0
misago/tos/views.py

@@ -0,0 +1,8 @@
+from django.template import RequestContext
+from misago.views import error404
+
+def forum_tos(request):
+    if request.settings.tos_url or not request.settings.tos_content:
+        return error404(request)
+    return request.theme.render_to_response('forum_tos.html',
+                                            context_instance=RequestContext(request));

+ 1 - 0
misago/urls.py

@@ -16,6 +16,7 @@ urlpatterns = patterns('',
     url(r'^redirect/(?P<slug>(\w|-)+)-(?P<forum>\d+)/$', 'misago.views.redirection', name="redirect"),
     url(r'^markdown/preview/$', 'misago.markdown.views.preview', name="md_preview"),
     url(r'^$', 'misago.views.home', name="index"),
+    url(r'^tos/$', 'misago.tos.views.forum_tos', name="tos"),
     url(r'^read/$', 'misago.views.read_all', name="read_all"),
 )
 

+ 14 - 0
templates/_forms.html

@@ -55,6 +55,10 @@
 {{ input_file_clearable(field, attrs=attrs, classes=[], horizontal=horizontal, width=width, nested=nested) }}
 {%- endif -%}
 
+{%- if field.widget == "forumTos" -%}
+{{ input_forum_tos(field, attrs=attrs, classes=[], horizontal=horizontal, width=width, nested=nested) }}
+{%- endif -%}
+
 {%- if field.widget == "recaptcha" -%}
 {{ input_recaptcha(field, attrs=attrs, classes=[], horizontal=horizontal, width=width, nested=nested) }}
 {%- endif -%}
@@ -105,6 +109,16 @@
 </label>
 {%- endmacro -%}
 
+{# Forum Terms of Service input #}
+{%- macro input_forum_tos(field, attrs={}, classes=[], horizontal=false, width=12, nested=false) -%}
+<label class="checkbox">
+  <input type="checkbox" name="{{ field.html_name }}" id="{{ field.html_id }}" value="1"{% if field.value %} checked="checked"{% endif %}>
+  {% trans forum_tos=make_tos()|safe %}I have read and accept this forums {{forum_tos}}.{% endtrans %}
+</label>
+{%- endmacro -%}
+{%- macro make_tos() -%}
+<a href="{% if settings.tos_url %}{{ settings.tos_url }}{% else %}{% url 'tos' %}{% endif %}">{% if settings.tos_title %}{{ settings.tos_title }}{% else %}{% trans %}Terms of Service{% endtrans %}{% endif %}</a>
+{%- endmacro -%}
 
 {# Date input #}
 {%- macro input_date(field, attrs={}, classes=[], horizontal=false, width=12, nested=false) -%}

+ 22 - 0
templates/sora/forum_tos.html

@@ -0,0 +1,22 @@
+{% extends "sora/layout.html" %}
+{% load i18n %}
+{% import "sora/macros.html" as macros with context %}
+
+{% block title %}{% if settings.tos_title -%}
+{{ macros.page_title(title=settings.tos_title) }}
+{%- else -%}
+{{ macros.page_title(title=_('Terms of Service')) }}
+{%- endif %}{% endblock %}
+
+{% block content %}
+<div class="page-header">
+  <h1>{% if settings.tos_title -%}
+{{ settings.tos_title }}
+{%- else -%}
+{% trans %}Terms of Service{% endtrans %}
+{%- endif %}</h1>
+</div>
+<div class="markdown">
+{{ settings.tos_content|markdown|safe }}
+</div>
+{% endblock %}

+ 1 - 0
templates/sora/layout.html

@@ -13,6 +13,7 @@
         <li><a href="{% url 'index' %}" title="{% trans %}Forum Home{% endtrans %}" class="tooltip-bottom"><i class="icon-comment"></i></a></li>{% if not user.crawler %}
         <li><a href="#" title="{% trans %}Search Community{% endtrans %}" class="tooltip-bottom"><i class="icon-search"></i></a></li>{% endif %}
         <li><a href="{% url 'users' %}" title="{% trans %}Browse Users{% endtrans %}" class="tooltip-bottom"><i class="icon-user"></i></a></li>
+        {% if settings.tos_url or settings.tos_content %}<li><a href="{% if settings.tos_url %}{{ settings.tos_url }}{% else %}{% url 'tos' %}{% endif %}" title="{% if settings.tos_title %}{{ settings.tos_title }}{% else %}{% trans %}Forum Terms of Service{% endtrans %}{% endif %}" class="tooltip-bottom"><i class="icon-certificate"></i></a></li>{% endif %}
       </ul>{% if not user.crawler %}
       <form class="form-inline search-form">
         <input type="text" class="span3" placeholder="{% trans %}Search community...{% endtrans %}">