예제 #1
0
파일: page.py 프로젝트: Twikie/frat
def new_page(request, user_name, project_slug):
    user = request.user
    if request.POST:
        form = NewPageForm(request.POST, request.FILES)
        if form.is_valid():
            new_page = form.save(commit=False)
            owner = User.objects.get(username=user_name)
            new_page.project = Project.objects.get(owner=owner, slug=project_slug)
            new_page.slug = slugify(new_page.name)
            new_page.save()
            rev_file_name = upload_cloud_file(request.FILES['image_file'], user_name, project_slug, new_page.slug, 1)
            initial_revision = Revision(revision_number=1, page=new_page, media_file_name=rev_file_name)
            initial_revision.save()
            return HttpResponseRedirect('/%s/%s' % (user_name, project_slug))
    else:
        form = NewPageForm()
    return render(request, 'new.html', {'form':form, 'type':'page'})
예제 #2
0
파일: revision.py 프로젝트: Twikie/frat
def new_revision(request, user_name, project_slug, page_slug):
    user = request.user
    if request.POST:
        form = NewRevisionForm(request.POST, request.FILES)
        if form.is_valid():
            new_revision = form.save(commit=False)
            owner = User.objects.get(username=user_name)
            project = Project.objects.get(owner=owner, slug=project_slug)
            rev_page = Page.objects.get(project=project, slug=page_slug)
            new_revision.page = rev_page
            rev_num = Revision.objects.filter(page=rev_page).aggregate(Max('revision_number'))['revision_number__max'] + 1
            new_revision.revision_number = rev_num
            new_revision.media_file_name = upload_cloud_file(request.FILES['image_file'], user_name, project_slug, page_slug, new_revision.revision_number)
            new_revision.save()
            return HttpResponseRedirect('/%s/%s/%s' % (user_name, project_slug, page_slug))
    else:
        form = NewRevisionForm()
    return render(request, 'new.html', {'form':form, 'type':'revision'})