Exemple #1
0
    def test_member_form(self):
        """
        Test 'MemberForm'
        - member must be existent
        """
        form = MemberForm(data={'username': '******'})

        self.failIf(form.is_valid())
        self.assertEqual(form.errors['username'], [u"Deze gebruiker bestaat niet."])

        form = MemberForm(data={'username':'******'})

        self.failUnless(form.is_valid())
Exemple #2
0
    def test_member_form(self):
        """
        Test 'MemberForm'
        - member must be existent
        """
        form = MemberForm(data={'username': '******'})

        self.failIf(form.is_valid())
        self.assertEqual(form.errors['username'],
                         [u"Deze gebruiker bestaat niet."])

        form = MemberForm(data={'username': '******'})

        self.failUnless(form.is_valid())
Exemple #3
0
def add_member(request,
               model,
               model_slug,
               template='blprofile/includes/form.html'):
    """ Add member to model """
    model = get_model(*model.split('.'))
    model_object = get_object_or_404(model,
                                     slug=model_slug,
                                     members=request.user)

    if isinstance(model_object, Group):
        redirect_reverse = 'group-detail'
        extra_context = {'group': model_object}
        check = GroupPermission(request.user)
        if not check.change_group(model_object):
            raise Http404

    elif isinstance(model_object, Project):
        redirect_reverse = 'project-detail'
        extra_context = {'project': model_object}
        check = ProjectPermission(request.user)
        if not check.change_project(model_object):
            raise Http404

    form = MemberForm()
    invite_form = InviteForm()
    msg = ''

    # Load every member of your projects
    projects = Project.objects.filter(members=request.user).distinct()
    members = []
    for project in projects:
        for member in project.members.all():
            if member not in members and member not in model_object.members.all(
            ):
                members.append(member)

    if request.method == "POST":
        if 'invite' in request.POST.keys():
            invite_form = InviteForm(request.POST)
            if invite_form.is_valid():
                invite = invite_form.save(request.user, model, model_object.id)
                msg = _(
                    "Invite for '%(project)s' has been send to '%(invite)s'" %
                    {
                        'project': model_object.name,
                        'invite': invite
                    })
        else:
            form = MemberForm(request.POST)
            if form.is_valid():
                members = form.save(model, model_object.id)

                member_string = ''
                for member in members:
                    member_string = member_string + member.strip() + ", "
                if len(members) > 1:
                    msg = _(
                        "Members '%(member)s' have been invited to '%(project)s'"
                        % {
                            'member': member_string[:-2],
                            'project': model_object.name
                        })
                    model_object.create_activity(request.user, Activity.INVITE)
                else:
                    msg = _(
                        "Member '%(member)s' has been invited to '%(project)s'"
                        % {
                            'member': member_string[:-2],
                            'project': model_object.name
                        })
                    user = User.objects.get(username__iexact=member)
                    model_object.create_activity(request.user, Activity.INVITE,
                                                 user)

        # Notification
        request.user.message_set.create(message=msg)

        return HttpResponseRedirect(
            reverse(redirect_reverse, kwargs={
                'slug': model_slug,
            }))

    extra_context['form'] = form
    extra_context['inviteform'] = invite_form
    extra_context['members'] = members
    return simple.direct_to_template(request,
                                     template=template,
                                     extra_context=extra_context)
Exemple #4
0
def add_member(request, model, model_slug, template='blprofile/includes/form.html'):
    """ Add member to model """
    model = get_model(*model.split('.'))
    model_object = get_object_or_404(model, slug=model_slug, members=request.user)

    if isinstance(model_object, Group):
        redirect_reverse = 'group-detail'
        extra_context = {'group': model_object}
        check = GroupPermission(request.user)
        if not check.change_group(model_object):
            raise Http404

    elif isinstance(model_object, Project):
        redirect_reverse = 'project-detail'
        extra_context = {'project': model_object}
        check = ProjectPermission(request.user)
        if not check.change_project(model_object):
            raise Http404

    form = MemberForm()
    invite_form = InviteForm()
    msg = ''

    # Load every member of your projects
    projects = Project.objects.filter(members=request.user).distinct()
    members = []
    for project in projects:
        for member in project.members.all():
            if member not in members and member not in model_object.members.all():
                members.append(member)
        
    if request.method == "POST":
        if 'invite' in request.POST.keys():
            invite_form = InviteForm(request.POST)
            if invite_form.is_valid():
                invite = invite_form.save(request.user, model, model_object.id)
                msg = _("Invite for '%(project)s' has been send to '%(invite)s'" % {'project': model_object.name, 'invite': invite })
        else:
            form = MemberForm(request.POST)
            if form.is_valid():
                members = form.save(model, model_object.id)

                member_string = ''
                for member in members:
                    member_string = member_string + member.strip() + ", "
                if len(members) > 1:
                    msg = _("Members '%(member)s' have been invited to '%(project)s'" % {'member': member_string[:-2], 'project': model_object.name })
                    model_object.create_activity(request.user, Activity.INVITE)
                else:
                    msg = _("Member '%(member)s' has been invited to '%(project)s'" % {'member': member_string[:-2], 'project': model_object.name })
                    user = User.objects.get(username__iexact=member)
                    model_object.create_activity(request.user, Activity.INVITE, user)
                    
        # Notification
        request.user.message_set.create(message=msg)
                
        return HttpResponseRedirect(reverse(redirect_reverse,
                                            kwargs = {'slug': model_slug,}))

    extra_context['form'] = form
    extra_context['inviteform'] = invite_form
    extra_context['members'] = members
    return simple.direct_to_template(request,
                                     template=template,
                                     extra_context=extra_context)