src/cm/views/site.py
author gibus
Tue, 25 Jun 2013 11:56:01 +0200
changeset 504 b2e0186daa5b
parent 482 00f61fe2430a
child 566 ff30d7bda752
permissions -rw-r--r--
Adds a category to comments, painted with colored vertical bar.
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
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    24
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    25
ACTIVITY_PAGINATION = 10
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    26
RECENT_TEXT_NB = 5
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    27
RECENT_COMMENT_NB = RECENT_TEXT_NB
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    28
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    29
MODERATE_NB = 5
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    30
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    31
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    32
def dashboard(request):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    33
    request.session.set_test_cookie()
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    34
    if request.user.is_authenticated():
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    35
        act_view = {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    36
                    'view_texts' : get_int(request.GET, 'view_texts', 1),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    37
                    'view_comments' : get_int(request.GET, 'view_comments', 1),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    38
                    'view_users' : get_int(request.GET, 'view_users', 1),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    39
                    }
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    40
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    41
        paginate_by = get_int(request.GET, 'paginate', ACTIVITY_PAGINATION)
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    42
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    43
        # texts with can_view_unapproved_comment perms
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    44
        moderator_texts = get_texts_with_perm(request, 'can_view_unapproved_comment')
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    45
        viewer_texts = get_texts_with_perm(request, 'can_view_approved_comment')
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    46
        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
    47
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    48
        span = get_among(request.GET, 'span', ('day', 'month', 'week',), 'week')
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    49
        template_dict = {
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    50
                         'span' : span,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    51
                         '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
    52
                         '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
    53
                         #'last_users' : User.objects.all().order_by('-date_joined')[:5],
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    54
                         }
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    55
        template_dict.update(act_view)
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    56
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    57
        #selected_activities = []
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    58
        #[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
    59
        activities = get_viewable_activities(request, act_view)
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    60
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    61
        if not has_perm(request, 'can_manage_workspace'):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    62
            template_dict['to_mod_profiles'] = []
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    63
        else:
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    64
            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
    65
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    66
        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
    67
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    68
        activities = activities.order_by('-created')
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    69
        return object_list(request, activities,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    70
                           template_name='site/dashboard.html',
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    71
                           paginate_by=paginate_by,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    72
                           extra_context=template_dict,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    73
                           )
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    74
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    75
    else:
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    76
        if request.method == 'POST':
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    77
            form = AuthenticationForm(request, request.POST)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    78
            if form.is_valid():
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    79
                user = form.get_user()
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    80
                user.backend = 'django.contrib.auth.backends.ModelBackend'
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    81
                cm_login(request, user)
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    82
                display_message(request, _(u"You're logged in!"))
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    83
                return HttpResponseRedirect(reverse('index'))
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    84
        else:
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    85
            form = AuthenticationForm()
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    86
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    87
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    88
        public_texts = get_texts_with_perm(request, 'can_view_text').order_by('-modified')
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    89
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    90
        template_dict = {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    91
                         'form' : form,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    92
                         'public_texts' : public_texts,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    93
                         }
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    94
        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
    95
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    96
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
    97
class HeaderContactForm(forms.Form):
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    98
    name = forms.CharField(
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
    99
                           max_length=100,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   100
                           label=ugettext_lazy(u"Your name"),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   101
                           )
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   102
    email = forms.EmailField(label=ugettext_lazy(u"Your email address"),)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   103
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   104
class BodyContactForm(forms.Form):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   105
    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
   106
    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
   107
    copy = forms.BooleanField(
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   108
                              label=ugettext_lazy(u"Send me a copy of the email"),
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   109
                              #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
   110
                              required=False)
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   111
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   112
class ContactForm(HeaderContactForm, BodyContactForm):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   113
    pass
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   114
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   115
def contact(request):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   116
    if request.method == 'POST':
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   117
        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
   118
        if form.is_valid():
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   119
            name = form.cleaned_data.get('name', None) or request.user.username
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   120
            email = form.cleaned_data.get('email', None) or request.user.email
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   121
            message = render_to_string('email/site_contact_email.txt',
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   122
                                       {
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   123
                                         'body' : form.cleaned_data['body'],
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   124
                                         'name' : name,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   125
                                         'email' : email,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   126
                                         'referer' : request.META.get('HTTP_REFERER', None),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   127
                                          }, context_instance=RequestContext(request))
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   128
            subject = form.cleaned_data['title']
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   129
            # Email subject *must not* contain newlines
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   130
            subject = ''.join(subject.splitlines())
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   131
            dest = settings.CONTACT_DEST
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   132
            send_mail(subject, message, email, [dest])
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   133
            if form.cleaned_data['copy']:
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   134
                my_subject = _(u"Copy of message:") + u" " + subject
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   135
                send_mail(my_subject, message, email, [email])
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   136
            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
   137
            redirect_url = reverse('index')
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   138
            return HttpResponseRedirect(redirect_url)
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   139
    else:
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   140
        form = BodyContactForm() if request.user.is_authenticated() else ContactForm()
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   141
    return render_to_response('site/contact.html', {'form': form}, context_instance=RequestContext(request))
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   142
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   143
def global_feed(request):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   144
    pass
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   145
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   146
from cm.role_models import role_models_choices
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   147
from django.utils.safestring import mark_safe
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   148
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   149
class BaseSettingsForm(forms.Form):
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   150
    def __init__(self, data=None, initial=None):
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   151
        forms.Form.__init__(self, data=data, initial=initial)
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   152
        for field in self.fields:
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   153
            if field in self.conf_fields:
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   154
                self.fields[field].initial = Configuration.objects.get_key(field)
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   155
164
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
    def save(self):
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   159
        for field in self.fields:
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   160
            if field in self.conf_fields:
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   161
                val = self.cleaned_data[field]
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   162
                Configuration.objects.set_key(field, val)
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   163
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   164
class SettingsForm(BaseSettingsForm):
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   165
    workspace_name = forms.CharField(label=ugettext_lazy("Workspace name"),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   166
                                     widget=forms.TextInput,
160
0c01050f9717 add logo in settings / fix static file settings
raph
parents: 158
diff changeset
   167
                                     required=False,
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   168
                                     )
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   169
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   170
    workspace_tagline = forms.CharField(label=ugettext_lazy("Workspace tagline"),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   171
                                        widget=forms.TextInput,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   172
                                        required=False,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   173
                                        )
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   174
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   175
    workspace_registration = forms.BooleanField(label=ugettext_lazy("Workspace registration"),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   176
                                                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
   177
                                                required=False,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   178
                                                )
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   179
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   180
    workspace_registration_moderation = forms.BooleanField(label=ugettext_lazy("Workspace registration moderation"),
158
raph
parents: 0
diff changeset
   181
                                                           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
   182
                                                           required=False,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   183
                                                           )
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   184
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   185
    workspace_role_model = forms.ChoiceField(label=ugettext_lazy("Role model"),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   186
                                             help_text=(ugettext_lazy("Change the roles available in the workspace")),
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   187
                                             choices=role_models_choices,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   188
                                             required=False,
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   189
                                             )
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   190
504
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   191
    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
   192
                                        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
   193
                                        widget=forms.TextInput,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   194
                                        required=False,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   195
                                        max_length=20,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   196
                                        )
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   197
    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
   198
                                        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
   199
                                        widget=forms.TextInput,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   200
                                        required=False,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   201
                                        max_length=20,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   202
                                        )
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   203
    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
   204
                                        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
   205
                                        widget=forms.TextInput,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   206
                                        required=False,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   207
                                        max_length=20,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   208
                                        )
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   209
    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
   210
                                        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
   211
                                        widget=forms.TextInput,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   212
                                        required=False,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   213
                                        max_length=20,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   214
                                        )
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   215
    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
   216
                                        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
   217
                                        widget=forms.TextInput,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   218
                                        required=False,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   219
                                        max_length=20,
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   220
                                        )
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   221
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   222
    # fields to save in the Configuration objects
504
b2e0186daa5b Adds a category to comments, painted with colored vertical bar.
gibus
parents: 482
diff changeset
   223
    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
   224
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   225
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   226
@has_global_perm('can_manage_workspace')
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   227
def settingss(request):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   228
    if request.method == 'POST':
160
0c01050f9717 add logo in settings / fix static file settings
raph
parents: 158
diff changeset
   229
        if 'delete_logo' in request.POST:
0c01050f9717 add logo in settings / fix static file settings
raph
parents: 158
diff changeset
   230
            Configuration.objects.del_key('workspace_logo_file_key')
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   231
            display_message(request, _(u'Settings saved'))
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   232
            return HttpResponseRedirect(reverse('settings'))
160
0c01050f9717 add logo in settings / fix static file settings
raph
parents: 158
diff changeset
   233
        else:
0c01050f9717 add logo in settings / fix static file settings
raph
parents: 158
diff changeset
   234
            form = SettingsForm(data=request.POST)
0c01050f9717 add logo in settings / fix static file settings
raph
parents: 158
diff changeset
   235
            if form.is_valid() :
0c01050f9717 add logo in settings / fix static file settings
raph
parents: 158
diff changeset
   236
                form.save()
0c01050f9717 add logo in settings / fix static file settings
raph
parents: 158
diff changeset
   237
                display_message(request, _(u'Settings saved'))
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   238
                return HttpResponseRedirect(reverse('settings'))
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   239
    else:
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   240
        form = SettingsForm()
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   241
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   242
    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
   243
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   244
class SettingsDesignForm(BaseSettingsForm):
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   245
    workspace_logo_file  = forms.FileField(label=ugettext_lazy("Workspace logo"),required=False)
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   246
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   247
    custom_css = forms.CharField(label=ugettext_lazy("Custom CSS rules"),
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   248
                                     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
   249
                                     widget=forms.Textarea,
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   250
                                     required=False,
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   251
                                     )
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   252
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   253
    custom_font = forms.CharField(label=ugettext_lazy("Custom font"),
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   254
                                        widget=forms.TextInput,
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   255
                                        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
   256
                                        required=False,
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   257
                                        )
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   258
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   259
    custom_titles_font = forms.CharField(label=ugettext_lazy("Custom font for titles"),
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   260
                                        widget=forms.TextInput,
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   261
                                        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
   262
                                        required=False,
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   263
                                        )
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   264
    conf_fields = ['custom_css', 'custom_font', 'custom_titles_font']
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   265
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   266
    def save_file(self, logo_file):
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   267
        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
   268
        Configuration.objects.set_key('workspace_logo_file_key', attach.key)
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   269
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   270
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   271
@has_global_perm('can_manage_workspace')
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   272
def settings_design(request):
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   273
    if request.method == 'POST':
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   274
        if 'delete_logo' in request.POST:
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   275
            Configuration.objects.del_key('workspace_logo_file_key')
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   276
            display_message(request, _(u'Settings saved'))
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   277
            return HttpResponseRedirect(reverse('settings-design'))
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   278
        else:
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   279
            form = SettingsDesignForm(data=request.POST)
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   280
            if form.is_valid() :
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   281
                form.save()
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   282
                logo_file = request.FILES.get('workspace_logo_file',None)
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   283
                if logo_file:
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   284
                    form.save_file(logo_file)
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   285
                display_message(request, _(u'Settings saved'))
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   286
                return HttpResponseRedirect(reverse('settings-design'))
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   287
    else:
482
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   288
      from cm.models import ApplicationConfiguration
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   289
      custom_css = ApplicationConfiguration.get_key('custom_css')
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   290
      if custom_css:
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   291
        default_css = custom_css
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   292
      else:
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   293
        default_css = '''
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   294
.voted {
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   295
  color: #008000;
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   296
}
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   297
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   298
.rejected, .fallen, .withdrawn {
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   299
  color: #ff0000;
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   300
}
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   301
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   302
div.frame {
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   303
  border: 1px solid #000;
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   304
  padding: 5px;
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   305
}
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   306
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   307
div.frame .title {
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   308
  font-weight: bold;
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   309
  text-align: center;
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   310
}'''
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   311
      form = SettingsDesignForm(initial={'custom_css': default_css})
00f61fe2430a Add custom CSS and fonts.
gibus
parents: 225
diff changeset
   312
164
cc217bd00476 add design customisation option
raph
parents: 161
diff changeset
   313
    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
   314
220
7d278fde2748 add forgot password function
raph
parents: 164
diff changeset
   315
225
67e1a89d6bca refactor forgot pw function to use django methods / add password change page in profile / i18n update
raph
parents: 220
diff changeset
   316
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
   317
    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
   318
    return HttpResponseRedirect(reverse('index'))
220
7d278fde2748 add forgot password function
raph
parents: 164
diff changeset
   319
225
67e1a89d6bca refactor forgot pw function to use django methods / add password change page in profile / i18n update
raph
parents: 220
diff changeset
   320
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
   321
    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
   322
    return HttpResponseRedirect(reverse('index'))
220
7d278fde2748 add forgot password function
raph
parents: 164
diff changeset
   323
0
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   324
def help(request):
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   325
    return render_to_response('site/help.html', context_instance=RequestContext(request))
40c8f766c9b8 import from internal svn r 4007
raph
parents:
diff changeset
   326