Exemple #1
0
    def form_valid(self, form):
        user = self.request.user
        
        project = form.save(commit=False)
        project.save()
        form.save_m2m()
        
        member = Member(user=user, role=get_role('leader'), project=project)
        member.save()
        
        self.object = project
        
        project_postcreate.send(sender=self, user=user, project=project)

        return HttpResponseRedirect(self.get_success_url())
Exemple #2
0
 def save(self, *args, **kwargs):
     is_new = self.pk is None
     
     if is_new:
         self.validate_unique()
     
     if self.role != self.initial['role']:
         no_member_roles = []
         for role in settings.PROJECT_NO_MEMBER_ROLES:
             no_member_roles.append(get_role(role))
         
         if self.role in no_member_roles and not self.away_since:
             self.away_since = datetime.now()
         elif self.initial['role'] in no_member_roles:
             self.away_since = None
     
     super(Member, self).save(*args, **kwargs)
Exemple #3
0
 def _grant_permissions(self, verbosity=0):
     roles_permissions = {}
     for role_name in settings.PROJECT_ROLES_PERMISSIONS.keys():
         role = get_role(role_name)
         if not role:
             raise ValidationError(_(u"Role %(role)s doesn't exist") % {role:role_name})
         
         roles_permissions[role_name] = []
         for perm in settings.PROJECT_ROLES_PERMISSIONS[role_name]:
             is_perm = self.grant_permission(role, perm)
             if not is_perm:
                 raise ValidationError(_(u"Permission %(perm)s doesn't exist") % {perm:perm})
             
             roles_permissions[role_name].append(perm)
     
     if verbosity > 1:
         print _(u"%(project)s roles permissions:") % {project : unicode(self)}
         for role in roles_permissions.keys():
             print role, ":",
             for perm in roles_permissions[role]:
                 print perm, ",",
             print ".",
         else:
             print ""
Exemple #4
0
from __future__ import absolute_import

from django import forms
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Hidden, Fieldset
from ajax_select import make_ajax_field
from permissions.utils import get_role

from .models import Project, Member
from .conf import settings

roles = [get_role(role) for role in settings.PROJECT_ROLES]
ROLES_CHOICES = [(role.id, _(unicode(role))) for role in roles]


# @@@ we should have auto slugs, even if suggested and overrideable


class ProjectForm(forms.ModelForm):
    
    def __init__(self, *args, **kwargs):
        super(ProjectForm, self).__init__(*args, **kwargs)
        
        instance = getattr(self, 'instance', None)
        
        if not instance:
            slug_help_text = _(u"a short version of the name consisting only of letters, numbers, underscores and hyphens.")
Exemple #5
0
 def active(self, **kwargs):
     no_member_roles = []
     for role in settings.PROJECT_NO_MEMBER_ROLES:
         no_member_roles.append(get_role(role))
     
     return self.filter(~Q(role__in=no_member_roles), **kwargs)
Exemple #6
0
 def is_active(self):
     no_member_roles = []
     for role in settings.PROJECT_NO_MEMBER_ROLES:
         no_member_roles.append(get_role(role))
     
     return self.role not in no_member_roles
Exemple #7
0
 def is_role(self, role):
     if isinstance(role, basestring):
         role = get_role(role)
     
     return self.role == role