src/cm/views/site.py
author gibus
Thu, 23 Jan 2014 10:12:25 +0100
changeset 566 ff30d7bda752
parent 504 b2e0186daa5b
permissions -rw-r--r--
clear cache on login.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     1
from django.db.models import Q
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     2
from django.contrib.auth.decorators import login_required
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     3
from cm.security import get_viewable_comments, get_viewable_activities
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     4
from cm.message import display_message
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     5
from cm.models import Comment, Activity, UserProfile, Notification
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     6
from cm.models_utils import Email
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     7
from cm.security import has_global_perm
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     8
from cm.security import get_texts_with_perm, has_perm
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
     9
from cm.utils import get_among, get_int
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    10
from cm.utils.mail import send_mail
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    11
from cm.views.user import cm_login
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    12
from django import forms
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    13
from django.conf import settings
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    14
from django.contrib.auth.forms import AuthenticationForm
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    15
from django.core.urlresolvers import reverse
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    16
from django.http import HttpResponse, HttpResponseRedirect, Http404
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    17
from django.shortcuts import render_to_response
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    18
from django.template import RequestContext
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    19
from django.template.loader import render_to_string
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    20
from django.utils.translation import get_language, ugettext as _, ugettext_lazy
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    21
from django.views.generic.list_detail import object_list
220
7d278fde2748 add forgot password function
raph
parents: 164
diff changeset
    22
from django.contrib.auth.models import User
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    23
from cm.models import Text, TextVersion, Attachment, Comment, Configuration, Activity
566
ff30d7bda752 clear cache on login.
gibus
parents: 504
diff changeset
    24
from django.core.cache import cache
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    25
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    26
ACTIVITY_PAGINATION = 10
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    27
RECENT_TEXT_NB = 5
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    28
RECENT_COMMENT_NB = RECENT_TEXT_NB
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    29
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    30
MODERATE_NB = 5
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    31
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    32
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    33
def dashboard(request):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    34
    request.session.set_test_cookie()
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    35
    if request.user.is_authenticated():
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    36
        act_view = {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    37
                    'view_texts' : get_int(request.GET, 'view_texts', 1),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    38
                    'view_comments' : get_int(request.GET, 'view_comments', 1),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    39
                    'view_users' : get_int(request.GET, 'view_users', 1),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    40
                    }
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    41
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    42
        paginate_by = get_int(request.GET, 'paginate', ACTIVITY_PAGINATION)
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    43
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    44
        # texts with can_view_unapproved_comment perms
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    45
        moderator_texts = get_texts_with_perm(request, 'can_view_unapproved_comment')
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    46
        viewer_texts = get_texts_with_perm(request, 'can_view_approved_comment')
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    47
        all_texts_ids = [t.id for t in moderator_texts] + [t.id for t in viewer_texts]
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    48
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    49
        span = get_among(request.GET, 'span', ('day', 'month', 'week',), 'week')
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    50
        template_dict = {
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    51
                         'span' : span,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    52
                         'last_texts' : get_texts_with_perm(request, 'can_view_text').order_by('-modified')[:RECENT_TEXT_NB],
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    53
                         'last_comments' : Comment.objects.filter(text_version__text__in=all_texts_ids).order_by('-created')[:RECENT_COMMENT_NB], # TODO: useful?
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    54
                         #'last_users' : User.objects.all().order_by('-date_joined')[:5],
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    55
                         }
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    56
        template_dict.update(act_view)
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    57
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    58
        #selected_activities = []
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    59
        #[selected_activities.extend(Activity.VIEWABLE_ACTIVITIES[k]) for k in act_view.keys() if act_view[k]]
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    60
        activities = get_viewable_activities(request, act_view)
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    61
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    62
        if not has_perm(request, 'can_manage_workspace'):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    63
            template_dict['to_mod_profiles'] = []
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    64
        else:
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    65
            template_dict['to_mod_profiles'] = UserProfile.objects.filter(user__is_active=False).filter(is_suspended=True).order_by('-user__date_joined')[:MODERATE_NB]
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    66
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    67
        template_dict['to_mod_comments'] = Comment.objects.filter(state='pending').filter(text_version__text__in=moderator_texts).order_by('-modified')[:MODERATE_NB - len(template_dict['to_mod_profiles'])]
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    68
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    69
        activities = activities.order_by('-created')
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    70
        return object_list(request, activities,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    71
                           template_name='site/dashboard.html',
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    72
                           paginate_by=paginate_by,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    73
                           extra_context=template_dict,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    74
                           )
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    75
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    76
    else:
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    77
        if request.method == 'POST':
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    78
            form = AuthenticationForm(request, request.POST)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    79
            if form.is_valid():
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    80
                user = form.get_user()
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    81
                user.backend = 'django.contrib.auth.backends.ModelBackend'
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    82
                cm_login(request, user)
566
ff30d7bda752 clear cache on login.
gibus
parents: 504
diff changeset
    83
                cache.clear()
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    84
                display_message(request, _(u"You're logged in!"))
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    85
                return HttpResponseRedirect(reverse('index'))
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    86
        else:
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    87
            form = AuthenticationForm()
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    88
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    89
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    90
        public_texts = get_texts_with_perm(request, 'can_view_text').order_by('-modified')
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    91
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    92
        template_dict = {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    93
                         'form' : form,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    94
                         'public_texts' : public_texts,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    95
                         }
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    96
        return render_to_response('site/non_authenticated_index.html', template_dict, context_instance=RequestContext(request))
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    97
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    98
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    99
class HeaderContactForm(forms.Form):
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   100
    name = forms.CharField(
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   101
                           max_length=100,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   102
                           label=ugettext_lazy(u"Your name"),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   103
                           )
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   104
    email = forms.EmailField(label=ugettext_lazy(u"Your email address"),)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   105
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   106
class BodyContactForm(forms.Form):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   107
    title = forms.CharField(label=ugettext_lazy(u"Subject of the message"), max_length=100)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   108
    body = forms.CharField(label=ugettext_lazy(u"Body of the message"), widget=forms.Textarea)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   109
    copy = forms.BooleanField(
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   110
                              label=ugettext_lazy(u"Send me a copy of the email"),
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   111
                              #help_text=ugettext_lazy(u"also send me a copy of the email"),
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   112
                              required=False)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   113
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   114
class ContactForm(HeaderContactForm, BodyContactForm):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   115
    pass
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   116
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   117
def contact(request):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   118
    if request.method == 'POST':
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   119
        form = BodyContactForm(request.POST) if request.user.is_authenticated() else ContactForm(request.POST)
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   120
        if form.is_valid():
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   121
            name = form.cleaned_data.get('name', None) or request.user.username
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   122
            email = form.cleaned_data.get('email', None) or request.user.email
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   123
            message = render_to_string('email/site_contact_email.txt',
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   124
                                       {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   125
                                         'body' : form.cleaned_data['body'],
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   126
                                         'name' : name,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   127
                                         'email' : email,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   128
                                         'referer' : request.META.get('HTTP_REFERER', None),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   129
                                          }, context_instance=RequestContext(request))
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   130
            subject = form.cleaned_data['title']
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   131
            # Email subject *must not* contain newlines
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   132
            subject = ''.join(subject.splitlines())
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   133
            dest = settings.CONTACT_DEST
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   134
            send_mail(subject, message, email, [dest])
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   135
            if form.cleaned_data['copy']:
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   136
                my_subject = _(u"Copy of message:") + u" " + subject
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   137
                send_mail(my_subject, message, email, [email])
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   138
            display_message(request, _(u"Email sent. We will get back to you as quickly as possible."))
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   139
            redirect_url = reverse('index')
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   140
            return HttpResponseRedirect(redirect_url)
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   141
    else:
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   142
        form = BodyContactForm() if request.user.is_authenticated() else ContactForm()
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   143
    return render_to_response('site/contact.html', {'form': form}, context_instance=RequestContext(request))
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   144
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   145
def global_feed(request):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   146
    pass
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   147
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   148
from cm.role_models import role_models_choices
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   149
from django.utils.safestring import mark_safe
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   150
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   151
class BaseSettingsForm(forms.Form):
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   152
    def __init__(self, data=None, initial=None):
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   153
        forms.Form.__init__(self, data=data, initial=initial)
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   154
        for field in self.fields:
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   155
            if field in self.conf_fields:
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   156
                self.fields[field].initial = Configuration.objects.get_key(field)
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   157
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   158
                self.fields[field].initial = Configuration.objects.get_key(field)
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   159
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   160
    def save(self):
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   161
        for field in self.fields:
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   162
            if field in self.conf_fields:
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   163
                val = self.cleaned_data[field]
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   164
                Configuration.objects.set_key(field, val)
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   165
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   166
class SettingsForm(BaseSettingsForm):
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   167
    workspace_name = forms.CharField(label=ugettext_lazy("Workspace name"),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   168
                                     widget=forms.TextInput,
160
0c01050f9717 add logo in settings / fix static file settings
raph
parents: 158
diff changeset
   169
                                     required=False,
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   170
                                     )
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   171
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   172
    workspace_tagline = forms.CharField(label=ugettext_lazy("Workspace tagline"),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   173
                                        widget=forms.TextInput,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   174
                                        required=False,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   175
                                        )
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   176
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   177
    workspace_registration = forms.BooleanField(label=ugettext_lazy("Workspace registration"),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   178
                                                help_text=ugettext_lazy("Can users register themselves into the workspace? (if not, only invitations by managers can create new users)"),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   179
                                                required=False,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   180
                                                )
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   181
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   182
    workspace_registration_moderation = forms.BooleanField(label=ugettext_lazy("Workspace registration moderation"),
158
raph
parents: 0
diff changeset
   183
                                                           help_text=ugettext_lazy("Should new users be moderated (registration will require manager's approval)?"),
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   184
                                                           required=False,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   185
                                                           )
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   186
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   187
    workspace_role_model = forms.ChoiceField(label=ugettext_lazy("Role model"),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   188
                                             help_text=(ugettext_lazy("Change the roles available in the workspace")),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   189
                                             choices=role_models_choices,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   190
                                             required=False,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   191
                                             )
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   192
504
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   193
    workspace_category_1 = forms.CharField(label=ugettext_lazy("Label for the first category of comments"),
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   194
                                        help_text=mark_safe(ugettext_lazy("Paragraphs including at least one comment of this category will have a vertical bar with this color: ") + '<span style="width: 2px; height: 5px; background-color: #1523f4">&nbsp;</span>'),
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   195
                                        widget=forms.TextInput,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   196
                                        required=False,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   197
                                        max_length=20,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   198
                                        )
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   199
    workspace_category_2 = forms.CharField(label=ugettext_lazy("Label for the second category of comments"),
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   200
                                        help_text=mark_safe(ugettext_lazy("Paragraphs including at least one comment of this category will have a vertical bar with this color: ") + '<span style="width: 2px; height: 5px; background-color: #f4154f">&nbsp;</span>'),
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   201
                                        widget=forms.TextInput,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   202
                                        required=False,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   203
                                        max_length=20,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   204
                                        )
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   205
    workspace_category_3 = forms.CharField(label=ugettext_lazy("Label for the third category of comments"),
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   206
                                        help_text=mark_safe(ugettext_lazy("Paragraphs including at least one comment of this category will have a vertical bar with this color: ") + '<span style="width: 2px; height: 5px; background-color: #09ff09">&nbsp;</span>'),
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   207
                                        widget=forms.TextInput,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   208
                                        required=False,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   209
                                        max_length=20,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   210
                                        )
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   211
    workspace_category_4 = forms.CharField(label=ugettext_lazy("Label for the fourth category of comments"),
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   212
                                        help_text=mark_safe(ugettext_lazy("Paragraphs including at least one comment of this category will have a vertical bar with this color: ") + '<span style="width: 2px; height: 5px; background-color: #bc39cf">&nbsp;</span>'),
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   213
                                        widget=forms.TextInput,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   214
                                        required=False,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   215
                                        max_length=20,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   216
                                        )
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   217
    workspace_category_5 = forms.CharField(label=ugettext_lazy("Label for the fifth category of comments"),
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   218
                                        help_text=mark_safe(ugettext_lazy("Paragraphs including at least one comment of this category will have a vertical bar with this color: ") + '<span style="width: 2px; height: 5px; background-color: #ffbd08">&nbsp;</span>'),
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   219
                                        widget=forms.TextInput,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   220
                                        required=False,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   221
                                        max_length=20,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   222
                                        )
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   223
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   224
    # fields to save in the Configuration objects
504
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   225
    conf_fields = ['workspace_name', 'workspace_tagline', 'workspace_registration', 'workspace_registration_moderation', 'workspace_role_model', 'workspace_category_1', 'workspace_category_2', 'workspace_category_3', 'workspace_category_4', 'workspace_category_5']
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   226
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   227
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   228
@has_global_perm('can_manage_workspace')
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   229
def settingss(request):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   230
    if request.method == 'POST':
160
0c01050f9717 add logo in settings / fix static file settings
raph
parents: 158
diff changeset
   231
        if 'delete_logo' in request.POST:
0c01050f9717 add logo in settings / fix static file settings
raph
parents: 158
diff changeset
   232
            Configuration.objects.del_key('workspace_logo_file_key')
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   233
            display_message(request, _(u'Settings saved'))
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   234
            return HttpResponseRedirect(reverse('settings'))
160
0c01050f9717 add logo in settings / fix static file settings
raph
parents: 158
diff changeset
   235
        else:
0c01050f9717 add logo in settings / fix static file settings
raph
parents: 158
diff changeset
   236
            form = SettingsForm(data=request.POST)
0c01050f9717 add logo in settings / fix static file settings
raph
parents: 158
diff changeset
   237
            if form.is_valid() :
0c01050f9717 add logo in settings / fix static file settings
raph
parents: 158
diff changeset
   238
                form.save()
0c01050f9717 add logo in settings / fix static file settings
raph
parents: 158
diff changeset
   239
                display_message(request, _(u'Settings saved'))
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   240
                return HttpResponseRedirect(reverse('settings'))
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   241
    else:
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   242
        form = SettingsForm()
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   243
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   244
    return render_to_response('site/settings.html', {'form' : form, 'help_links' : {'workspace_role_model':'role_model'}}, context_instance=RequestContext(request))
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   245
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   246
class SettingsDesignForm(BaseSettingsForm):
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   247
    workspace_logo_file  = forms.FileField(label=ugettext_lazy("Workspace logo"),required=False)
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   248
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   249
    custom_css = forms.CharField(label=ugettext_lazy("Custom CSS rules"),
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   250
                                     help_text=mark_safe(ugettext_lazy("Add stylesheet rules in CSS format (do not include <code>&lt;style&gt;</code> HTML tags). Warning: this code will be added to all content, make sure you know what you're doing before adding something here.")),
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   251
                                     widget=forms.Textarea,
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   252
                                     required=False,
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   253
                                     )
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   254
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   255
    custom_font = forms.CharField(label=ugettext_lazy("Custom font"),
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   256
                                        widget=forms.TextInput,
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   257
                                        help_text=mark_safe(ugettext_lazy("Custom alternative font family to 'modern', 'classic' and 'code' that visitors can chose for the body of co-ment texts. Enter a coma separated list of font families. Font family names including space characters should be enclosed in double quotes. Eg. ") + '<code>"Times New Roman", Times, serif</code>.'),
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   258
                                        required=False,
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   259
                                        )
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   260
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   261
    custom_titles_font = forms.CharField(label=ugettext_lazy("Custom font for titles"),
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   262
                                        widget=forms.TextInput,
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   263
                                        help_text=mark_safe(ugettext_lazy("Custom alternative font family to 'modern', 'classic' and 'code' that visitors can chose for titles (h1 to h6) of co-ment texts. Enter a coma separated list of font families. Font family names including space characters should be enclosed in double quotes. Eg. ") + '<code>"Gill Sans", Helvetica, sans-serif</code>.'),
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   264
                                        required=False,
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   265
                                        )
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   266
    conf_fields = ['custom_css', 'custom_font', 'custom_titles_font']
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   267
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   268
    def save_file(self, logo_file):
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   269
        attach = Attachment.objects.create_attachment(filename='wp_logo', data=logo_file.read(), text_version=None)
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   270
        Configuration.objects.set_key('workspace_logo_file_key', attach.key)
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   271
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   272
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   273
@has_global_perm('can_manage_workspace')
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   274
def settings_design(request):
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   275
    if request.method == 'POST':
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   276
        if 'delete_logo' in request.POST:
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   277
            Configuration.objects.del_key('workspace_logo_file_key')
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   278
            display_message(request, _(u'Settings saved'))
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   279
            return HttpResponseRedirect(reverse('settings-design'))
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   280
        else:
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   281
            form = SettingsDesignForm(data=request.POST)
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   282
            if form.is_valid() :
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   283
                form.save()
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   284
                logo_file = request.FILES.get('workspace_logo_file',None)
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   285
                if logo_file:
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   286
                    form.save_file(logo_file)
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   287
                display_message(request, _(u'Settings saved'))
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   288
                return HttpResponseRedirect(reverse('settings-design'))
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   289
    else:
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   290
      from cm.models import ApplicationConfiguration
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   291
      custom_css = ApplicationConfiguration.get_key('custom_css')
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   292
      if custom_css:
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   293
        default_css = custom_css
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   294
      else:
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   295
        default_css = '''
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   296
.voted {
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   297
  color: #008000;
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   298
}
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   299
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   300
.rejected, .fallen, .withdrawn {
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   301
  color: #ff0000;
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   302
}
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   303
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   304
div.frame {
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   305
  border: 1px solid #000;
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   306
  padding: 5px;
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   307
}
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   308
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   309
div.frame .title {
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   310
  font-weight: bold;
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   311
  text-align: center;
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   312
}'''
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   313
      form = SettingsDesignForm(initial={'custom_css': default_css})
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   314
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   315
    return render_to_response('site/settings_design.html', {'form' : form}, context_instance=RequestContext(request))
225
67e1a89d6bca refactor forgot pw function to use django methods / add password change page in profile / i18n update
raph
parents: 220
diff changeset
   316
220
7d278fde2748 add forgot password function
raph
parents: 164
diff changeset
   317
225
67e1a89d6bca refactor forgot pw function to use django methods / add password change page in profile / i18n update
raph
parents: 220
diff changeset
   318
def password_reset_done(request):
67e1a89d6bca refactor forgot pw function to use django methods / add password change page in profile / i18n update
raph
parents: 220
diff changeset
   319
    display_message(request, _(u'A link to reset your password has been sent to the profile email. Please check your email.'))
67e1a89d6bca refactor forgot pw function to use django methods / add password change page in profile / i18n update
raph
parents: 220
diff changeset
   320
    return HttpResponseRedirect(reverse('index'))
220
7d278fde2748 add forgot password function
raph
parents: 164
diff changeset
   321
225
67e1a89d6bca refactor forgot pw function to use django methods / add password change page in profile / i18n update
raph
parents: 220
diff changeset
   322
def password_reset_complete(request):
67e1a89d6bca refactor forgot pw function to use django methods / add password change page in profile / i18n update
raph
parents: 220
diff changeset
   323
    display_message(request, _(u'Password changed'))
67e1a89d6bca refactor forgot pw function to use django methods / add password change page in profile / i18n update
raph
parents: 220
diff changeset
   324
    return HttpResponseRedirect(reverse('index'))
220
7d278fde2748 add forgot password function
raph
parents: 164
diff changeset
   325
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   326
def help(request):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   327
    return render_to_response('site/help.html', context_instance=RequestContext(request))
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   328