def folder_add_document_sidebar(request, document_id): check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW]) document = get_object_or_404(Document, pk=document_id) previous = request.META.get('HTTP_REFERER', '/') if request.method == 'POST': form = AddDocumentForm(request.POST, user=request.user) if form.is_valid(): if form.cleaned_data['existing_folder']: folder = form.cleaned_data['existing_folder'] elif form.cleaned_data['title']: folder, created = Folder.objects.get_or_create(user=request.user, title=form.cleaned_data['title']) if created: messages.success(request, _(u'Folder created successfully')) else: messages.error(request, _(u'A folder named: %s, already exists.') % form.cleaned_data['title']) return HttpResponseRedirect(previous) else: messages.error(request, _(u'Must specify a new folder or an existing one.')) return HttpResponseRedirect(previous) folder_document, created = FolderDocument.objects.get_or_create(folder=folder, document=document) if created: messages.success(request, _(u'Document: %(document)s added to folder: %(folder)s successfully.') % { 'document': document, 'folder': folder}) else: messages.warning(request, _(u'Document: %(document)s is already in folder: %(folder)s.') % { 'document': document, 'folder': folder}) return HttpResponseRedirect(previous)
def folder_add_document_sidebar(request, document_id): check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW]) document = get_object_or_404(Document, pk=document_id) previous = request.META.get('HTTP_REFERER', '/') if request.method == 'POST': form = AddDocumentForm(request.POST, user=request.user) if form.is_valid(): if form.cleaned_data['existing_folder']: folder = form.cleaned_data['existing_folder'] elif form.cleaned_data['title']: folder, created = Folder.objects.get_or_create( user=request.user, title=form.cleaned_data['title']) if created: messages.success(request, _(u'Folder created successfully')) else: messages.error( request, _(u'A folder named: %s, already exists.') % form.cleaned_data['title']) return HttpResponseRedirect(previous) else: messages.error( request, _(u'Must specify a new folder or an existing one.')) return HttpResponseRedirect(previous) folder_document, created = FolderDocument.objects.get_or_create( folder=folder, document=document) if created: messages.success( request, _(u'Document: %(document)s added to folder: %(folder)s successfully.' ) % { 'document': document, 'folder': folder }) else: messages.warning( request, _(u'Document: %(document)s is already in folder: %(folder)s.' ) % { 'document': document, 'folder': folder }) return HttpResponseRedirect(previous)
def get_add_document_to_folder_form(context): context.update({ 'form': AddDocumentForm(user=context['request'].user), 'request': context['request'], 'form_action': reverse('folder_add_document_sidebar', args=[context['object'].pk]), 'title': _('Add document to a folder') }) return context
def folder_add_document(request, document_id): # TODO: merge with folder_add_document_sidebar check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW]) document = get_object_or_404(Document, pk=document_id) next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', '/')))#reverse('document_tags', args=[document.pk])))) if request.method == 'POST': form = AddDocumentForm(request.POST, user=request.user) if form.is_valid(): if form.cleaned_data['existing_folder']: folder = form.cleaned_data['existing_folder'] elif form.cleaned_data['title']: folder, created = Folder.objects.get_or_create(user=request.user, title=form.cleaned_data['title']) if created: messages.success(request, _(u'Folder "%s" created successfully') % form.cleaned_data['title']) else: messages.error(request, _(u'A folder named: %s, already exists.') % form.cleaned_data['title']) return HttpResponseRedirect(next) else: messages.error(request, _(u'Must specify a new folder or an existing one.')) return HttpResponseRedirect(next) folder_document, created = FolderDocument.objects.get_or_create(folder=folder, document=document) if created: messages.success(request, _(u'Document: %(document)s added to folder: %(folder)s successfully.') % { 'document': document, 'folder': folder}) else: messages.warning(request, _(u'Document: %(document)s is already in folder: %(folder)s.') % { 'document': document, 'folder': folder}) return HttpResponseRedirect(next) else: form = AddDocumentForm(user=request.user) return render_to_response('generic_form.html', { 'title': _(u'add document "%s" to a folder') % document, 'form': form, 'object': document, 'next': next, }, context_instance=RequestContext(request))
def folder_add_document(request, document_id): # TODO: merge with folder_add_document_sidebar check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW]) document = get_object_or_404(Document, pk=document_id) next = request.POST.get( 'next', request.GET.get('next', request.META.get( 'HTTP_REFERER', '/'))) #reverse('document_tags', args=[document.pk])))) if request.method == 'POST': form = AddDocumentForm(request.POST, user=request.user) if form.is_valid(): if form.cleaned_data['existing_folder']: folder = form.cleaned_data['existing_folder'] elif form.cleaned_data['title']: folder, created = Folder.objects.get_or_create( user=request.user, title=form.cleaned_data['title']) if created: messages.success( request, _(u'Folder "%s" created successfully') % form.cleaned_data['title']) else: messages.error( request, _(u'A folder named: %s, already exists.') % form.cleaned_data['title']) return HttpResponseRedirect(next) else: messages.error( request, _(u'Must specify a new folder or an existing one.')) return HttpResponseRedirect(next) folder_document, created = FolderDocument.objects.get_or_create( folder=folder, document=document) if created: messages.success( request, _(u'Document: %(document)s added to folder: %(folder)s successfully.' ) % { 'document': document, 'folder': folder }) else: messages.warning( request, _(u'Document: %(document)s is already in folder: %(folder)s.' ) % { 'document': document, 'folder': folder }) return HttpResponseRedirect(next) else: form = AddDocumentForm(user=request.user) return render_to_response('generic_form.html', { 'title': _(u'add document "%s" to a folder') % document, 'form': form, 'object': document, 'next': next, }, context_instance=RequestContext(request))