def detail(self, request):
        """
        Show detail page for a file.
        Rename existing File/Directory (deletes existing Image Versions/Thumbnails).
        """
        from filebrowser.forms import ChangeForm
        query = request.GET
        path = u'%s' % os.path.join(self.directory, query.get('dir', ''))
        fileobject = FileObject(os.path.join(path, query.get('filename', '')), site=self)

        if request.method == 'POST':
            form = ChangeForm(request.POST, path=path, fileobject=fileobject, filebrowser_site=self)
            if form.is_valid():
                new_name = form.cleaned_data['name']
                action_name = form.cleaned_data['custom_action']
                try:
                    action_response = None
                    if action_name:
                        action = self.get_action(action_name)
                        # Pre-action signal
                        signals.filebrowser_actions_pre_apply.send(sender=request, action_name=action_name, fileobject=[fileobject], site=self)
                        # Call the action to action
                        action_response = action(request=request, fileobjects=[fileobject])
                        # Post-action signal
                        signals.filebrowser_actions_post_apply.send(sender=request, action_name=action_name, fileobject=[fileobject], result=action_response, site=self)
                    if new_name != fileobject.filename:
                        signals.filebrowser_pre_rename.send(sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name, site=self)
                        fileobject.delete_versions()
                        self.storage.move(fileobject.path, os.path.join(fileobject.head, new_name))
                        signals.filebrowser_post_rename.send(sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name, site=self)
                        messages.add_message(request, messages.SUCCESS, _('Renaming was successful.'))
                    if isinstance(action_response, HttpResponse):
                        return action_response
                    if "_continue" in request.POST:
                        redirect_url = reverse("filebrowser:fb_detail", current_app=self.name) + query_helper(query, "filename=" + new_name, "filename")
                    else:
                        redirect_url = reverse("filebrowser:fb_browse", current_app=self.name) + query_helper(query, "", "filename")
                    return HttpResponseRedirect(redirect_url)
                except OSError:
                    form.errors['name'] = forms.util.ErrorList([_('Error.')])
        else:
            form = ChangeForm(initial={"name": fileobject.filename}, path=path, fileobject=fileobject, filebrowser_site=self)

        return render(
            admin_request(request, self.name),
            'filebrowser/detail.html',
            admin_context({
                'form': form,
                'fileobject': fileobject,
                'query': query,
                'title': u'%s' % fileobject.filename,
                'is_popup': "pop" in request.GET,
                'settings_var': get_settings_var(directory=self.directory),
                'breadcrumbs': get_breadcrumbs(query, query.get('dir', '')),
                'breadcrumbs_title': u'%s' % fileobject.filename,
                'filebrowser_site': self
            }, request),
        )
def detail(request):
    """
    Show detail page for a file.
    
    Rename existing File/Directory (deletes existing Image Versions/Thumbnails).
    """
    from filebrowser.forms import ChangeForm
    query = request.GET
    abs_path = u'%s' % os.path.join(MEDIA_ROOT, DIRECTORY, query.get(
        'dir', ''))
    fileobject = FileObject(os.path.join(abs_path, query.get('filename', '')))

    if request.method == 'POST':
        form = ChangeForm(request.POST, path=abs_path, fileobject=fileobject)
        if form.is_valid():
            new_name = form.cleaned_data['name']
            transpose = form.cleaned_data['transpose']
            try:
                if new_name != fileobject.filename:
                    filebrowser_pre_rename.send(sender=request,
                                                path=fileobject.path,
                                                name=fileobject.filename,
                                                new_name=new_name)
                    fileobject.delete_versions()
                    os.rename(fileobject.path,
                              os.path.join(fileobject.head, new_name))
                    filebrowser_post_rename.send(sender=request,
                                                 path=fileobject.path,
                                                 name=fileobject.filename,
                                                 new_name=new_name)
                    messages.add_message(request, messages.SUCCESS,
                                         _('Renaming was successful.'))
                if transpose:
                    im = Image.open(fileobject.path)
                    new_image = im.transpose(int(transpose))
                    try:
                        new_image.save(
                            fileobject.path,
                            quality=VERSION_QUALITY,
                            optimize=(os.path.splitext(
                                fileobject.path)[1].lower() != '.gif'))
                    except IOError:
                        new_image.save(fileobject.path,
                                       quality=VERSION_QUALITY)
                    fileobject.delete_versions()
                    messages.add_message(request, messages.SUCCESS,
                                         _('Transposing was successful.'))
                if "_continue" in request.POST:
                    redirect_url = reverse("fb_detail") + query_helper(
                        query, "filename=" + new_name, "filename")
                else:
                    redirect_url = reverse("fb_browse") + query_helper(
                        query, "", "filename")
                return HttpResponseRedirect(redirect_url)
            except OSError, (errno, strerror):
                form.errors['name'] = forms.util.ErrorList([_('Error.')])
    def detail(self, request):
        """
        Show detail page for a file.
        
        Rename existing File/Directory (deletes existing Image Versions/Thumbnails).
        """
        from filebrowser.forms import ChangeForm

        query = request.GET
        abs_path = u"%s" % os.path.join(self.media_root, query.get("dir", ""))
        fileobject = FileObject(
            os.path.join(abs_path, query.get("filename", "")), media_root=self.media_root, media_url=self.media_url
        )

        if request.method == "POST":
            form = ChangeForm(request.POST, path=abs_path, fileobject=fileobject, site=self)
            if form.is_valid():
                new_name = form.cleaned_data["name"]
                action_name = form.cleaned_data["custom_action"]
                try:
                    action_response = None
                    if action_name:
                        action = self.get_action(action_name)
                        # Pre-action signal
                        self.filebrowser_actions_pre_apply.send(
                            sender=request, action_name=action_name, fileobject=[fileobject]
                        )
                        # Call the action to action
                        action_response = action(request=request, fileobjects=[fileobject])
                        # Post-action signal
                        self.filebrowser_actions_post_apply.send(
                            sender=request, action_name=action_name, fileobject=[fileobject], result=action_response
                        )
                    if new_name != fileobject.filename:
                        self.filebrowser_pre_rename.send(
                            sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name
                        )
                        fileobject.delete_versions()
                        os.rename(fileobject.path, os.path.join(fileobject.head, new_name))
                        self.filebrowser_post_rename.send(
                            sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name
                        )
                        messages.add_message(request, messages.SUCCESS, _("Renaming was successful."))
                    if isinstance(action_response, HttpResponse):
                        return action_response
                    if "_continue" in request.POST:
                        redirect_url = reverse("filebrowser:fb_detail", current_app=self.name) + query_helper(
                            query, "filename=" + new_name, "filename"
                        )
                    else:
                        redirect_url = reverse("filebrowser:fb_browse", current_app=self.name) + query_helper(
                            query, "", "filename"
                        )
                    return HttpResponseRedirect(redirect_url)
                except OSError, (errno, strerror):
                    form.errors["name"] = forms.util.ErrorList([_("Error.")])
Exemple #4
0
 def detail(self, request):
     """
     Show detail page for a file.
     
     Rename existing File/Directory (deletes existing Image Versions/Thumbnails).
     """
     from filebrowser.forms import ChangeForm
     query = request.GET
     path = u'%s' % os.path.join(self.directory, query.get('dir', ''))
     fileobject = FileObject(os.path.join(path, query.get('filename', '')), site=self)
     
     if request.method == 'POST':
         form = ChangeForm(request.POST, path=path, fileobject=fileobject, filebrowser_site=self)
         if form.is_valid():
             new_name = form.cleaned_data['name']
             action_name = form.cleaned_data['custom_action']
             try:
                 action_response = None
                 if action_name:
                     action = self.get_action(action_name)
                     # Pre-action signal
                     self.filebrowser_actions_pre_apply.send(sender=request, action_name=action_name, fileobject=[fileobject])
                     # Call the action to action
                     action_response = action(request=request, fileobjects=[fileobject])
                     # Post-action signal
                     self.filebrowser_actions_post_apply.send(sender=request, action_name=action_name, fileobject=[fileobject], result=action_response)
                 if new_name != fileobject.filename:
                     self.filebrowser_pre_rename.send(sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name)
                     fileobject.delete_versions()
                     self.storage.move(fileobject.path, os.path.join(fileobject.head, new_name))
                     self.filebrowser_post_rename.send(sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name)
                     messages.add_message(request, messages.SUCCESS, _('Renaming was successful.'))
                 if isinstance(action_response, HttpResponse):
                     return action_response
                 if "_continue" in request.POST:
                     redirect_url = reverse("filebrowser:fb_detail", current_app=self.name) + query_helper(query, "filename="+new_name, "filename")
                 else:
                     redirect_url = reverse("filebrowser:fb_browse", current_app=self.name) + query_helper(query, "", "filename")
                 return HttpResponseRedirect(redirect_url)
             except OSError, (errno, strerror):
                 form.errors['name'] = forms.util.ErrorList([_('Error.')])
def detail(request):
    """
    Show detail page for a file.
    
    Rename existing File/Directory (deletes existing Image Versions/Thumbnails).
    """
    from filebrowser.forms import ChangeForm
    query = request.GET
    abs_path = u'%s' % os.path.join(MEDIA_ROOT, DIRECTORY, query.get('dir', ''))
    fileobject = FileObject(os.path.join(abs_path, query.get('filename', '')))
    
    if request.method == 'POST':
        form = ChangeForm(request.POST, path=abs_path, fileobject=fileobject)
        if form.is_valid():
            new_name = form.cleaned_data['name']
            transpose = form.cleaned_data['transpose']
            try:
                if transpose:
                    im = Image.open(fileobject.path)
                    new_image = im.transpose(int(transpose))
                    try:
                        new_image.save(fileobject.path, quality=VERSION_QUALITY, optimize=(os.path.splitext(fileobject.path)[1].lower() != '.gif'))
                    except IOError:
                        new_image.save(fileobject.path, quality=VERSION_QUALITY)
                    fileobject.delete_versions()
                    messages.add_message(request, messages.SUCCESS, _('Transposing was successful.'))
                if new_name != fileobject.filename:
                    filebrowser_pre_rename.send(sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name)
                    fileobject.delete_versions()
                    os.rename(fileobject.path, os.path.join(fileobject.head, new_name))
                    filebrowser_post_rename.send(sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name)
                    messages.add_message(request, messages.SUCCESS, _('Renaming was successful.'))
                if "_continue" in request.POST:
                    redirect_url = reverse("fb_detail") + query_helper(query, "filename="+new_name, "filename")
                else:
                    redirect_url = reverse("fb_browse") + query_helper(query, "", "filename")
                return HttpResponseRedirect(redirect_url)
            except OSError, (errno, strerror):
                form.errors['name'] = forms.util.ErrorList([_('Error.')])
    def detail(self, request):
        """
        Show detail page for a file.
        Rename existing File/Directory (deletes existing Image Versions/Thumbnails).
        """
        from filebrowser.forms import ChangeForm
        query = request.GET
        path = u'%s' % os.path.join(self.directory, query.get('dir', ''))
        fileobject = FileObject(os.path.join(path, query.get('filename', '')), site=self)

        if request.method == 'POST':
            form = ChangeForm(request.POST, path=path, fileobject=fileobject, filebrowser_site=self)
            if form.is_valid():
                new_name = form.cleaned_data['name']
                action_name = form.cleaned_data['custom_action']
                try:
                    action_response = None
                    if action_name:
                        action = self.get_action(action_name)
                        # Pre-action signal
                        signals.filebrowser_actions_pre_apply.send(sender=request, action_name=action_name, fileobject=[fileobject], site=self)
                        # Call the action to action
                        action_response = action(request=request, fileobjects=[fileobject])
                        # Post-action signal
                        signals.filebrowser_actions_post_apply.send(sender=request, action_name=action_name, fileobject=[fileobject], result=action_response, site=self)
                    if new_name != fileobject.filename:
                        signals.filebrowser_pre_rename.send(sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name, site=self)
                        fileobject.delete_versions()
                        self.storage.move(fileobject.path, os.path.join(fileobject.head, new_name))
                        signals.filebrowser_post_rename.send(sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name, site=self)
                        messages.add_message(request, messages.SUCCESS, _('Renaming was successful.'))
                    if isinstance(action_response, HttpResponse):
                        return action_response
                    if "_continue" in request.POST:
                        redirect_url = reverse("filebrowser:fb_detail", current_app=self.name) + query_helper(query, "filename=" + new_name, "filename")
                    else:
                        redirect_url = reverse("filebrowser:fb_browse", current_app=self.name) + query_helper(query, "", "filename")
                    return HttpResponseRedirect(redirect_url)
                except OSError:
                    form.errors['name'] = forms.util.ErrorList([_('Error.')])
        else:
            form = ChangeForm(initial={"name": fileobject.filename}, path=path, fileobject=fileobject, filebrowser_site=self)

        request.current_app = self.name
        return TemplateResponse(request, 'filebrowser/detail.html', dict(
            admin_site.each_context(request),
            **{
                'form': form,
                'fileobject': fileobject,
                'query': query,
                'title': u'%s' % fileobject.filename,
                'is_popup': "pop" in request.GET,
                'settings_var': get_settings_var(directory=self.directory),
                'breadcrumbs': get_breadcrumbs(query, query.get('dir', '')),
                'breadcrumbs_title': u'%s' % fileobject.filename,
                'filebrowser_site': self
            }
        ))
Exemple #7
0
                    if "_continue" in request.POST:
                        redirect_url = reverse(
                            "filebrowser:fb_detail",
                            current_app=self.name) + query_helper(
                                query, "filename=" + new_name, "filename")
                    else:
                        redirect_url = reverse(
                            "filebrowser:fb_browse",
                            current_app=self.name) + query_helper(
                                query, "", "filename")
                    return HttpResponseRedirect(redirect_url)
                except OSError, (errno, strerror):
                    form.errors['name'] = forms.util.ErrorList([_('Error.')])
        else:
            form = ChangeForm(initial={"name": fileobject.filename},
                              path=path,
                              fileobject=fileobject,
                              filebrowser_site=self)

        return render_to_response(
            'filebrowser/detail.html', {
                'form': form,
                'fileobject': fileobject,
                'query': query,
                'title': u'%s' % fileobject.filename,
                'settings_var': get_settings_var(directory=self.directory),
                'breadcrumbs': get_breadcrumbs(query, query.get('dir', '')),
                'breadcrumbs_title': u'%s' % fileobject.filename,
                'filebrowser_site': self
            },
            context_instance=Context(request, current_app=self.name))
Exemple #8
0
    def detail(self, request):
        """
        Show detail page for a file.
        Rename existing File/Directory (deletes existing Image Versions/Thumbnails).
        """
        from filebrowser.forms import ChangeForm
        from filebrowser.models import FileDescription

        query = request.GET
        path = u"%s" % os.path.join(self.directory, query.get("dir", ""))
        fileobject = FileObject(os.path.join(path, query.get("filename", "")), site=self)

        try:
            file_description = FileDescription.objects.get(file_path=fileobject)
        except:
            file_description = FileDescription(file_path=fileobject.path)

        if request.method == "POST":
            form = ChangeForm(request.POST, path=path, fileobject=fileobject, filebrowser_site=self)
            if form.is_valid():
                new_name = form.cleaned_data["name"]
                action_name = form.cleaned_data["custom_action"]
                try:
                    action_response = None
                    if action_name:
                        action = self.get_action(action_name)
                        # Pre-action signal
                        signals.filebrowser_actions_pre_apply.send(
                            sender=request, action_name=action_name, fileobject=[fileobject], site=self
                        )
                        # Call the action to action
                        action_response = action(request=request, fileobjects=[fileobject])
                        # Post-action signal
                        signals.filebrowser_actions_post_apply.send(
                            sender=request,
                            action_name=action_name,
                            fileobject=[fileobject],
                            result=action_response,
                            site=self,
                        )
                    new_file_description = form.save(commit=False)
                    new_file_description.file_path = fileobject.path
                    new_file_description.pk = file_description.pk
                    if new_name != fileobject.filename:
                        signals.filebrowser_pre_rename.send(
                            sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name, site=self
                        )
                        fileobject.delete_versions()
                        new_path = os.path.join(fileobject.head, new_name)
                        self.storage.move(fileobject.path, os.path.join(fileobject.head, new_name))
                        if new_file_description:
                            new_file_description.file_path = new_path
                        signals.filebrowser_post_rename.send(
                            sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name, site=self
                        )
                        if fileobject.filetype == "Folder":
                            for fd in FileDescription.objects.filter(file_path__startswith=fileobject.path):
                                fd.file_path = new_path + fd.file_path.path[len(fileobject.path) :]
                                fd.save()
                        messages.add_message(request, messages.SUCCESS, _("Renaming was successful."))
                    new_file_description.save()
                    if isinstance(action_response, HttpResponse):
                        return action_response
                    if "_continue" in request.POST:
                        redirect_url = reverse("filebrowser:fb_detail", current_app=self.name) + query_helper(
                            query, "filename=" + new_name, "filename"
                        )
                    else:
                        redirect_url = reverse("filebrowser:fb_browse", current_app=self.name) + query_helper(
                            query, "", "filename"
                        )
                    return HttpResponseRedirect(redirect_url)
                except OSError:
                    form.errors["name"] = forms.util.ErrorList([_("Error.")])
        else:
            form = ChangeForm(
                initial=dict(name=fileobject.filename, **file_description.__dict__),
                path=path,
                fileobject=fileobject,
                filebrowser_site=self,
                instance=file_description,
            )

        return render_to_response(
            "filebrowser/detail.html",
            {
                "form": form,
                "fileobject": fileobject,
                "query": query,
                "title": u"%s" % fileobject.filename,
                "settings_var": get_settings_var(directory=self.directory),
                "breadcrumbs": get_breadcrumbs(query, query.get("dir", "")),
                "breadcrumbs_title": u"%s" % fileobject.filename,
                "filebrowser_site": self,
            },
            context_instance=Context(request, current_app=self.name),
        )
                                       quality=VERSION_QUALITY)
                    fileobject.delete_versions()
                    messages.add_message(request, messages.SUCCESS,
                                         _('Transposing was successful.'))
                if "_continue" in request.POST:
                    redirect_url = reverse("fb_detail") + query_helper(
                        query, "filename=" + new_name, "filename")
                else:
                    redirect_url = reverse("fb_browse") + query_helper(
                        query, "", "filename")
                return HttpResponseRedirect(redirect_url)
            except OSError, (errno, strerror):
                form.errors['name'] = forms.util.ErrorList([_('Error.')])
    else:
        form = ChangeForm(initial={"name": fileobject.filename},
                          path=abs_path,
                          fileobject=fileobject)

    return render_to_response(
        'filebrowser/detail.html', {
            'form': form,
            'fileobject': fileobject,
            'query': query,
            'title': u'%s' % fileobject.filename,
            'settings_var': get_settings_var(),
            'breadcrumbs': get_breadcrumbs(query, query.get('dir', '')),
            'breadcrumbs_title': u'%s' % fileobject.filename
        },
        context_instance=Context(request))

Exemple #10
0
    def detail(self, request):
        """
        Show detail page for a file.
        Rename existing File/Directory (deletes existing Image Versions/Thumbnails).
        """
        from filebrowser.forms import ChangeForm
        query = request.GET
        path = u'%s' % os.path.join(self.directory, query.get('dir', ''))
        fileobject = FileObject(os.path.join(path, query.get('filename', '')), site=self)


        def copy_item(old_name, new_name):
            if not OVERWRITE_EXISTING and self.storage.exists(os.path.join(fileobject.head, new_name)):
                _new_path_name, _new_path_ext = os.path.splitext(new_name)
                new_name = u'%s_%s%s' % (_new_path_name, int(time()*1000), _new_path_ext)
            signals.filebrowser_pre_copy.send(sender=request, path=fileobject.path, name=old_name, new_name=new_name, site=self)
            fileobject.delete_versions()

            self.storage.copy(fileobject.path, os.path.join(fileobject.head, new_name))
            signals.filebrowser_post_copy.send(sender=request, path=fileobject.path, name=old_name, new_name=new_name, site=self)
            messages.add_message(request, messages.SUCCESS, _('Copying was successful.'))

            return new_name

        def move_item(old_name, new_name):
            if not OVERWRITE_EXISTING and self.storage.exists(os.path.join(fileobject.head, new_name)):
                _new_path_name, _new_path_ext = os.path.splitext(new_name)
                new_name = u'%s_%s%s' % (_new_path_name, int(time()*1000), _new_path_ext)
            signals.filebrowser_pre_rename.send(sender=request, path=fileobject.path, name=old_name, new_name=new_name, site=self)
            fileobject.delete_versions()
            self.storage.move(fileobject.path, os.path.join(fileobject.head, new_name))
            signals.filebrowser_post_rename.send(sender=request, path=fileobject.path, name=old_name, new_name=new_name, site=self)
            messages.add_message(request, messages.SUCCESS, _('Renaming was successful.'))

            return new_name

        if request.method == 'POST':
            print OVERWRITE_EXISTING
            form = ChangeForm(request.POST, path=path, fileobject=fileobject, filebrowser_site=self)
            if form.is_valid():
                new_name = form.cleaned_data['name']
                action_name = form.cleaned_data['custom_action']
                try:
                    action_response = None
                    if action_name:
                        action = self.get_action(action_name)
                        # Pre-action signal
                        signals.filebrowser_actions_pre_apply.send(sender=request, action_name=action_name, fileobject=[fileobject], site=self)
                        # Call the action to action
                        action_response = action(request=request, fileobjects=[fileobject])
                        # Post-action signal
                        signals.filebrowser_actions_post_apply.send(sender=request, action_name=action_name, fileobject=[fileobject], result=action_response, site=self)
                    if "_copy" in request.POST:
                        new_name  = copy_item(fileobject.filename, new_name)
                    elif "_save" in request.POST and new_name != fileobject.filename:
                        new_name = move_item(fileobject.filename, new_name)

                    if isinstance(action_response, HttpResponse):
                        return action_response
                    if "_copy_continue" in request.POST:
                        new_name = copy_item(fileobject.filename, new_name)
                        redirect_url = reverse("filebrowser:fb_detail", current_app=self.name) + query_helper(query, "filename="+os.path.basename(new_name)+',dir='+os.path.join(query.get('dir', ''), os.path.dirname(new_name)), "filename")
                    elif "_save_continue" in request.POST and new_name != fileobject.filename:
                        new_name = move_item(fileobject.filename, new_name)
                        redirect_url = reverse("filebrowser:fb_detail", current_app=self.name) + query_helper(query, "filename="+os.path.basename(new_name)+',dir='+os.path.join(query.get('dir', ''), os.path.dirname(new_name)), "filename")
                    else:
                        redirect_url = reverse("filebrowser:fb_browse", current_app=self.name) + query_helper(query, "", "filename")
                    return HttpResponseRedirect(redirect_url)
                except OSError:
                    form.errors['name'] = forms.util.ErrorList([_('Error.')])
        else:
            form = ChangeForm(initial={"name": fileobject.filename}, path=path, fileobject=fileobject, filebrowser_site=self)

        return render_to_response('filebrowser/detail.html', {
            'form': form,
            'fileobject': fileobject,
            'query': query,
            'title': u'%s' % fileobject.filename,
            'settings_var': get_settings_var(directory=self.directory),
            'breadcrumbs': get_breadcrumbs(query, query.get('dir', '')),
            'breadcrumbs_title': u'%s' % fileobject.filename,
            'filebrowser_site': self
        }, context_instance=Context(request, current_app=self.name))