コード例 #1
0
ファイル: views.py プロジェクト: bansalrajnikant/djime
def index(request):
    # Data returned to the template
    data = {
            'projects_active': Project.objects.filter(members=request.user, state='active').order_by('name'),
            'projects_on_hold': Project.objects.filter(members=request.user, state='on_hold').order_by('name'),
            'projects_completed': Project.objects.filter(members=request.user, state='completed').order_by('name'),
            'projects_dropped': Project.objects.filter(members=request.user, state='dropped').order_by('name'),
            }
    # Adding a form to create a new project if user is viewing this page.
    if request.method == 'GET':
        data['project_add_form'] = ProjectAddForm()
    # Handleing the form data that's being posted.
    elif request.method == 'POST':
        form = ProjectAddForm(request.POST)
        if form.is_valid:
            new_project = form.save()
            # Need to save the new project before we can assign the user to the project.
            new_project.members.add(request.user)
            new_project.save()
            return HttpResponseRedirect(reverse('project_page', kwargs={'project_id': new_project.id}))
        # if form doesn't validate, return the form with errors.
        else:
            data['project_add_form'] = form
    return render_to_response('project/project_index.html', data,
                                         context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: omeinusch/Palco
def backstage_project_add(request):
    if request.POST:
        form = ProjectAddForm(request.POST)
        if form.is_valid():
            actor = form.cleaned_data['manager']
            project = Project.objects.create(title=form.cleaned_data['title'])
            Role.objects.create(name=Role._meta.get_field('perm_is_manager').verbose_name, project=project,
                                actor=actor, appearance=1)

            request.get_full_path()

            mail = EMailTemplate.objects.prepare('project-added', {
                'first_name': actor.user.first_name,
                'last_name': actor.user.last_name,
                'admin': request.user,
                'project': project,
                'dashboard_url': request.build_absolute_uri(reverse('bs-dashboard', kwargs={'project': project.pk}))
            })
            mail.to = [actor.user.email, ]
            mail.send()

            message_object_created(request, project)
            return redirect('bs-dashboard', project=project.pk)
    else:
        form = ProjectAddForm()

    return render(request, 'administrator/projects-form.html',
                  get_context_backstage(request, 'bs-project-add', {'form': form}))