示例#1
0
def add_edit(request, slug=None):
    """ Add/Edit Project """
    form = ProjectForm(request.POST or None,
                       instance=slug and Project.objects.get(slug__iexact=slug))

    tags = Tag.objects.usage_for_queryset(Project.objects.filter(members=request.user), counts=True)
    project = None
    if slug:
        check = ProjectPermission(request.user)
        project = Project.objects.get(slug__iexact=slug)
        if not check.change_project(project):
            raise Http404

    if request.method == "POST" and form.is_valid():
        project = form.save(request.user, slug)
        form.save_m2m()

        # Notification
        if slug:
            msg = _("Project '%(project)s' has been updated" % {'project': project.name })
            project.create_activity(request.user, Activity.UPDATE)
        else:
            msg = _("Project '%(project)s' has been created" % {'project': project.name })
            project.create_activity(request.user, Activity.START)
        request.user.message_set.create(message=msg)
        
        return HttpResponseRedirect(reverse('project-detail', kwargs = {'slug': project.slug}))

    return direct_to_template(request,
                              template='blproject/form.html',
                              extra_context={'form':form,
                                             'project': project,
                                             'tags': tags})
示例#2
0
def index(request, project_slug):
    """ Invite for a project """
    # Get Project
    project = get_object_or_404(Project,
                                slug=project_slug,
                                members=request.user)

    # Get Permissions
    perm = ProjectPermission(request.user)
    if not perm.change_project(project):
        raise Http404

    # Member suggestions
    suggestions = Invite.objects.get_suggestions(request.user, project)

    # Forms
    user_form = InviteUserForm(project)

    initial_email = {
        'pm': INITIAL_INVITE_PM,
    }
    email_form = InviteEmailForm(project, initial=initial_email)

    if request.method == "POST":
        # Which form was posted?
        if request.POST.has_key('usernames'):
            user_form = InviteUserForm(project, request.POST)
            if user_form.is_valid():
                invites = user_form.save(request.user)
                request.user.message_set.create(
                    message=_('%(amount)s invite(s) has been sent out.' %
                              {'amount': invites}))
                return HttpResponseRedirect(
                    reverse('project-detail', kwargs={'slug': project.slug}))

        elif request.POST.has_key('email_addresses'):
            email_form = InviteEmailForm(project, request.POST)
            if email_form.is_valid():
                (useri, emaili) = email_form.save(request.user)
                if len(emaili) == 1 and useri == 0:
                    request.user.message_set.create(message=_(
                        'Your invite to %(invited)s has been sent out.' %
                        {'invited': emaili[0]}))
                else:
                    request.user.message_set.create(
                        message=_('%(amount)s invites has been sent out.' %
                                  {'amount': useri + len(emaili)}))
                return HttpResponseRedirect(
                    reverse('project-detail', kwargs={'slug': project.slug}))

    extra_context = {
        'user_form': user_form,
        'email_form': email_form,
        'project': project,
        'members': suggestions
    }

    return direct_to_template(request,
                              template='blinvite/index.html',
                              extra_context=extra_context)
示例#3
0
def index(request, project_slug):
    """ Invite for a project """
    # Get Project
    project = get_object_or_404(Project, slug=project_slug, members=request.user)
    
    # Get Permissions
    perm = ProjectPermission(request.user)
    if not perm.change_project(project):
        raise Http404

    # Member suggestions
    suggestions = Invite.objects.get_suggestions(request.user, project)

    # Forms
    user_form = InviteUserForm(project)

    initial_email = {'pm': INITIAL_INVITE_PM,}
    email_form = InviteEmailForm(project, initial=initial_email)

    if request.method == "POST":
        # Which form was posted?
        if request.POST.has_key('usernames'):
            user_form = InviteUserForm(project, request.POST)
            if user_form.is_valid():
                invites = user_form.save(request.user)
                request.user.message_set.create(message=_('%(amount)s invite(s) has been sent out.' % {'amount': invites}))
                return HttpResponseRedirect(reverse('project-detail', kwargs={'slug': project.slug}))

        elif request.POST.has_key('email_addresses'):
            email_form = InviteEmailForm(project, request.POST)
            if email_form.is_valid():
                (useri, emaili) = email_form.save(request.user)
                if len(emaili) == 1 and useri == 0:
                    request.user.message_set.create(message=_('Your invite to %(invited)s has been sent out.' % {'invited': emaili[0]}))
                else:
                    request.user.message_set.create(message=_('%(amount)s invites has been sent out.' % {'amount': useri + len(emaili)}))
                return HttpResponseRedirect(reverse('project-detail', kwargs={'slug': project.slug}))

    extra_context = {'user_form': user_form,
                     'email_form': email_form,
                     'project': project,
                     'members': suggestions}

    return direct_to_template(request,
                              template='blinvite/index.html',
                              extra_context=extra_context)
示例#4
0
def add_edit(request, slug=None):
    """ Add/Edit Project """
    form = ProjectForm(request.POST or None,
                       instance=slug
                       and Project.objects.get(slug__iexact=slug))

    tags = Tag.objects.usage_for_queryset(
        Project.objects.filter(members=request.user), counts=True)
    project = None
    if slug:
        check = ProjectPermission(request.user)
        project = Project.objects.get(slug__iexact=slug)
        if not check.change_project(project):
            raise Http404

    if request.method == "POST" and form.is_valid():
        project = form.save(request.user, slug)
        form.save_m2m()

        # Notification
        if slug:
            msg = _("Project '%(project)s' has been updated" %
                    {'project': project.name})
            project.create_activity(request.user, Activity.UPDATE)
        else:
            msg = _("Project '%(project)s' has been created" %
                    {'project': project.name})
            project.create_activity(request.user, Activity.START)
        request.user.message_set.create(message=msg)

        return HttpResponseRedirect(
            reverse('project-detail', kwargs={'slug': project.slug}))

    return direct_to_template(request,
                              template='blproject/form.html',
                              extra_context={
                                  'form': form,
                                  'project': project,
                                  'tags': tags
                              })