Example #1
0
def file_edit(request, project_slug, file_id):
    """
    Edit an existing file
    """
    project = get_object_or_404(request.user.projects.live(), slug=project_slug)
    file = get_object_or_404(project.files.live(), pk=file_id)

    form = FileForm(instance=file, data=request.POST or None)

    if request.method == 'POST' and form.is_valid():
        form.save()
        project_manage = reverse('projects_manage', args=[project.slug])
        return HttpResponseRedirect(project_manage)

    return render_to_response(
        'projects/file_edit.html',
        {'form': form, 'project': project, 'file': file},
        context_instance=RequestContext(request)
    )
Example #2
0
def file_add(request, project_slug):
    """
    Add a file to a project, redirecting on success to the projects mgmt page
    """
    project = get_object_or_404(request.user.projects.live(), slug=project_slug)
    file = File(project=project)

    form = FileForm(instance=file, data=request.POST or None)

    if request.method == 'POST' and form.is_valid():
        form.instance.project = project
        file = form.save()
        project_manage = reverse('projects_manage', args=[project.slug])
        return HttpResponseRedirect(project_manage)

    return render_to_response(
        'projects/file_add.html',
        {'form': form, 'project': project},
        context_instance=RequestContext(request)
    )