def upload(request, slug, **kwargs): # For GET, just return blank response. See issue #327. if request.method != "POST": return HttpResponse("") error = None file_form = PageFileForm(request.POST, request.FILES) uploaded = request.FILES["file"] if "file" in kwargs: # Replace existing file if exists try: file = PageFile.objects.get(slug__exact=slug, name__exact=kwargs["file"]) file.file = uploaded except PageFile.DoesNotExist: file = PageFile(file=uploaded, name=uploaded.name, slug=slug) file_form.instance = file if not file_form.is_valid(): error = file_form.errors.values()[0] else: file_form.save() if error is not None: return HttpResponseBadRequest(error) return HttpResponseRedirect(reverse("pages:file-info", args=[slug, kwargs["file"]])) # uploaded from ckeditor relative_url = "_files/" + urlquote(uploaded.name) try: file = PageFile(file=uploaded, name=uploaded.name, slug=slug) file.save() return ck_upload_result(request, url=relative_url) except IntegrityError: error = "A file with this name already exists" return ck_upload_result(request, url=relative_url, message=error)
def upload(request, slug, **kwargs): error = None file_form = PageFileForm(request.POST, request.FILES) uploaded = request.FILES['file'] if 'file' in kwargs: # Replace existing file if exists try: file = PageFile.objects.get(slug__exact=slug, name__exact=kwargs['file']) file.file = uploaded except PageFile.DoesNotExist: file = PageFile(file=uploaded, name=uploaded.name, slug=slug) file_form.instance = file if not file_form.is_valid(): error = file_form.errors.values()[0] else: file_form.save() if error is not None: return HttpResponseBadRequest(error) return HttpResponseRedirect(reverse('pages:file-info', args=[slug, kwargs['file']])) # uploaded from ckeditor relative_url = '_files/' + uploaded.name try: file = PageFile(file=uploaded, name=uploaded.name, slug=slug) file.save() return ck_upload_result(request, url=relative_url) except IntegrityError: error = 'A file with this name already exists' return ck_upload_result(request, url=relative_url, message=error)
def get_object(self, request, slug='', file=''): obj = PageFile(slug=slugify(slug), name=file) page = Page(slug=slugify(slug)) obj.page = page.versions.most_recent() obj.title = _('File %(filename)=s on page "%(pagename)s"') % { 'filename': obj.name, 'pagename': obj.page.name} return obj
def get_object(self, request, slug='', file=''): obj = PageFile(slug=slugify(slug), name=file) page = Page(slug=slugify(slug)) obj.page = page.versions.most_recent() obj.title = _('File %(filename)s on page "%(pagename)s"') % { 'filename': obj.name, 'pagename': obj.page.name} return obj
def get_object(self, request, slug="", file=""): obj = PageFile(slug=slugify(slug), name=file) page = Page(slug=slugify(slug)) obj.page = page.versions.most_recent() obj.title = _('File %(filename)=s on page "%(pagename)s"') % { "filename": obj.name, "pagename": obj.pageobj.name, } return obj
def get_queryset(self): all_file_versions = PageFile(slug=self.kwargs['slug'], name=self.kwargs['file']).versions.all() # We set self.file to the most recent historical instance of the # file. if all_file_versions: self.file = all_file_versions[0] else: self.file = PageFile(slug=self.kwargs['slug'], name=self.kwargs['file']) return all_file_versions
def get_redirect_url(self, slug, file, **kwargs): page_file = PageFile(slug=slug, name=file) version = self.kwargs.get('version') date = self.kwargs.get('date') if version: page_file = page_file.versions.as_of(version=int(version)) if date: page_file = page_file.versions.as_of(date=dateparser(date)) return page_file.file.url
def upload(request, slug, **kwargs): # For GET, just return blank response. See issue #327. if request.method != 'POST': return HttpResponse('') error = None file_form = PageFileForm(request.POST, request.FILES) uploaded = request.FILES['file'] if 'file' in kwargs: # Replace existing file if exists try: file = PageFile.objects.get(slug__exact=slug, name__exact=kwargs['file']) file.file = uploaded except PageFile.DoesNotExist: file = PageFile(file=uploaded, name=uploaded.name, slug=slug) file_form.instance = file if not file_form.is_valid(): error = file_form.errors.values()[0] else: file_form.save() if error is not None: return HttpResponseBadRequest(error) return HttpResponseRedirect( reverse('pages:file-info', args=[slug, kwargs['file']])) # uploaded from ckeditor filename = _find_available_filename(uploaded.name, slug) relative_url = '_files/' + urlquote(filename) try: file = PageFile(file=uploaded, name=filename, slug=slug) file.save() return ck_upload_result(request, url=relative_url) except IntegrityError: error = _('A file with this name already exists') return ck_upload_result(request, url=relative_url, message=error)
def get_object(self): file = PageFile(slug=self.kwargs['slug'], name=self.kwargs['file']) return file.versions.as_of(version=int(self.kwargs['version']))
def get_object(self): return PageFile(slug=self.kwargs['slug'], name=self.kwargs['file'])
def get_object(self, request, slug='', file=''): obj = PageFile(slug=slugify(slug), name=file) page = Page(slug=slugify(slug)) obj.page = page.versions.most_recent() obj.title = 'File %s on page "%s"' % (obj.name, obj.page.name) return obj