Ejemplo n.º 1
0
 def delete(self, *args, **kwargs):
     try:
         remove_thumbnails(self.pic.path)
         remove_file(self.pic.path)
     except:
         pass
     super(Pic, self).delete(*args, **kwargs)
Ejemplo n.º 2
0
 def delete(self, *args, **kwargs):
     # noinspection PyBroadException
     try:
         remove_file(self.doc.path)
     except:
         pass
     super(Doc, self).delete(*args, **kwargs)
Ejemplo n.º 3
0
 def delete(self, *args, **kwargs):
     try:
         remove_thumbnails(self.pic.path)
         remove_file(self.pic.path)
     except:
         pass
     super(Pic, self).delete(*args, **kwargs)
Ejemplo n.º 4
0
 def delete(self, *args, **kwargs):
     # noinspection PyBroadException
     try:
         remove_file(self.doc.path)
     except:
         pass
     super(Doc, self).delete(*args, **kwargs)
Ejemplo n.º 5
0
def file_uploader(request, **kwargs):
    uploader = AjaxUploader(filetype='image',
                            uploadDirectory=setting('IMAGE_UPLOAD_DIR',
                                                    'images'),
                            sizeLimit=setting('IMAGE_UPLOAD_SIZE', 10485760))
    result = uploader.handleUpload(request)
    if result['success']:
        ctype = get_object_or_404(ContentType, id=int(kwargs['content_type']))
        object_id = int(kwargs['object_id'])
        obj = ctype.get_object_for_this_type(pk=object_id)
        try:
            remove_thumbnails(obj.img.path)
            remove_file(obj.img.path)
            obj.img.delete()
        except:
            pass
        obj.img = result['path']
        obj.save()
        try:
            addons = dict(tmb=make_thumbnail(obj.img.url,
                                             width=int(kwargs['width']),
                                             height=int(kwargs['height']),
                                             aspect=int(kwargs['aspect'])))
        except:
            addons = {}
        result.update(addons)
    return AjaxAnswer(result)
Ejemplo n.º 6
0
def file_uploader(request, **kwargs):
    uploader = AjaxUploader(
        filetype="image",
        uploadDirectory=setting("IMAGE_UPLOAD_DIR", "images"),
        sizeLimit=setting("IMAGE_UPLOAD_SIZE", 10485760),
    )
    result = uploader.handleUpload(request)
    if result["success"]:
        ctype = get_object_or_404(ContentType, id=int(kwargs["content_type"]))
        object_id = int(kwargs["object_id"])
        obj = ctype.get_object_for_this_type(pk=object_id)
        try:
            remove_thumbnails(obj.img.path)
            remove_file(obj.img.path)
            obj.img.delete()
        except:
            pass
        obj.img = result["path"]
        obj.save()
        try:
            addons = dict(
                tmb=make_thumbnail(
                    obj.img.url, width=int(kwargs["width"]), height=int(kwargs["height"]), aspect=int(kwargs["aspect"])
                )
            )
        except:
            addons = {}
        result.update(addons)
    return AjaxAnswer(result)
Ejemplo n.º 7
0
 def _ajax_upload(self, request, **kwargs):
     if request.method == "POST":
         tmb = None
         self._upload_file(request, **kwargs)
         fullpath = os.path.join(settings.MEDIA_ROOT, self.extra_context['path'])
         try:
             i = Image.open(fullpath)
         except:
             messages.error(request, "File is not image format")
             os.remove(fullpath)
             self.success = False
             self.pic_id = None
         if self.success:
             ctype = get_object_or_404(ContentType, id=int(kwargs['content_type']))
             object_id = int(kwargs['object_id'])
             obj = ctype.get_object_for_this_type(pk=object_id)
             try:
                 remove_thumbnails(obj.img.path)
                 remove_file(obj.img.path)
                 obj.img.delete()
             except:
                 pass
             obj.img = self.extra_context['path']
             obj.save()
             # let Ajax Upload know whether we saved it or not
             addons = {'tmb': make_thumbnail(obj.img.url, width=int(kwargs['width']), height=int(kwargs['height']),
                                             aspect=int(kwargs['aspect']))}
         payload = {'success': self.success, 'filename': self.filename}
         if self.extra_context is not None:
             payload.update(self.extra_context)
         if addons:
             payload.update(addons)
         return AjaxAnswer(payload)
Ejemplo n.º 8
0
 def delete(self, *args, **kwargs):
     try:
         remove_thumbnails(self.agent_img.path)
         remove_file(self.agent_img.path)
     except:
         pass
     super(AbstractEmployee, self).delete(*args, **kwargs)
Ejemplo n.º 9
0
 def delete(self, *args, **kwargs):
     try:
         remove_thumbnails(self.agent_img.path)
         remove_file(self.agent_img.path)
     except:
         pass
     super(AbstractEmployee, self).delete(*args, **kwargs)
Ejemplo n.º 10
0
 def delete(self, *args, **kwargs):
     try:
         remove_thumbnails(self.img.path)
         remove_file(self.img.path)
     except:
         pass
     super(AbstractImg, self).delete(*args, **kwargs)
Ejemplo n.º 11
0
 def delete(self, *args, **kwargs):
     try:
         remove_thumbnails(self.img.path)
         remove_file(self.img.path)
     except:
         pass
     super(AbstractImg, self).delete(*args, **kwargs)
Ejemplo n.º 12
0
 def delete(self, *args, **kwargs):
     # noinspection PyBroadException
     try:
         remove_thumbnails(self.img.path)
         remove_file(self.img.path)
     except:
         pass
     super(AbstractImg, self).delete(*args, **kwargs)
Ejemplo n.º 13
0
 def delete(self, *args, **kwargs):
     # noinspection PyBroadException
     try:
         remove_thumbnails(self.pic.path)
         remove_file(self.pic.path)
     except:
         pass
     super(Pic, self).delete(*args, **kwargs)
Ejemplo n.º 14
0
 def delete(self, *args, **kwargs):
     # noinspection PyBroadException
     try:
         remove_thumbnails(self.img.path)
         remove_file(self.img.path)
     except:
         pass
     super(Pic, self).delete(*args, **kwargs)
Ejemplo n.º 15
0
 def form_valid(self, form):
     avatar_path = self.object.avatar.url
     remove_thumbnails(avatar_path)
     remove_file(avatar_path)
     self.object = form.save(commit=False)
     self.object.avatar_complete = False
     self.object.save()
     resize_image(self.object.avatar.url)
     return super(AvatarEdit, self).form_valid(form)
Ejemplo n.º 16
0
 def form_valid(self, form):
     avatar_path = self.object.img.url
     remove_thumbnails(avatar_path)
     remove_file(avatar_path)
     self.object = form.save(commit=False)
     self.object.avatar_complete = False
     self.object.save()
     resize_image(self.object.img.url)
     return super(AvatarEdit, self).form_valid(form)
Ejemplo n.º 17
0
def avatar_delete(request):
    try:
        u = request.user
        remove_thumbnails(u.img.url)
        remove_file(u.img.url)
        u.img = ''
        u.save()
        payload = {'success': True}
    except:
        payload = {'success': False}
    return AjaxLazyAnswer(payload)
Ejemplo n.º 18
0
def avatar_delete(request):
    try:
        u = request.user
        remove_thumbnails(u.img.url)
        remove_file(u.img.url)
        u.img = ''
        u.save()
        payload = {'success': True}
    except:
        payload = {'success': False}
    return AjaxLazyAnswer(payload)
Ejemplo n.º 19
0
def avatar_delete(request):
    try:
        profile = request.user.get_profile()
        remove_thumbnails(profile.avatar.url)
        remove_file(profile.avatar.url)
        profile.avatar = ''
        profile.save()
        payload = {'success': True}
    except:
        payload = {'success': False}
    return AjaxLazyAnswer(payload)
Ejemplo n.º 20
0
def avatardelete(request):
    if request.is_ajax():
        try:
            profile = request.user.get_profile()
            remove_thumbnails(profile.avatar.path)
            remove_file(profile.avatar.path)
            profile.avatar_complete = False
            profile.avatar = None
            profile.save()
            payload = {'success': True}
        except:
            payload = {'success': False}
        return AjaxLazyAnswer(payload)
    else:
        raise Http404()
Ejemplo n.º 21
0
def avatardelete(request):
    if request.is_ajax():
        try:
            u = request.user
            remove_thumbnails(u.img.path)
            remove_file(u.img.path)
            u.avatar_complete = False
            u.img = None
            u.save()
            payload = {'success': True}
        except:
            payload = {'success': False}
        return AjaxLazyAnswer(payload)
    else:
        raise Http404()
Ejemplo n.º 22
0
def avatar_delete(request):
    try:
        remove_thumbnails(request.user.img.url)
        remove_file(request.user.img.url)
        request.user.img = ''
        request.user.save()
        payload = {'success': True}
        try:
            addons = dict(html=render_to_string('user/avatar.html', {'object': request.user}))
        except:
            addons = {}
        payload.update(addons)
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
Ejemplo n.º 23
0
def avatardelete(request):
    if request.is_ajax():
        try:
            u = request.user
            remove_thumbnails(u.img.path)
            remove_file(u.img.path)
            u.avatar_complete = False
            u.img = None
            u.save()
            payload = {'success': True}
        except:
            payload = {'success': False}
        return ajax_answer_lazy(payload)
    else:
        raise Http404()
Ejemplo n.º 24
0
def avatardelete(request):
    if request.is_ajax():
        # noinspection PyBroadException
        try:
            u = request.user
            remove_thumbnails(u.img.path)
            remove_file(u.img.path)
            u.avatar_complete = False
            u.img = None
            u.save()
            payload = {'success': True}
        except:
            payload = {'success': False}
        return ajax_answer_lazy(payload)
    else:
        raise Http404()
Ejemplo n.º 25
0
def avatar_delete(request):
    try:
        remove_thumbnails(request.user.img.url)
        remove_file(request.user.img.url)
        request.user.img = ''
        request.user.save()
        payload = {'success': True}
        try:
            addons = dict(html=render_to_string('user/avatar.html',
                                                {'object': request.user}))
        except:
            addons = {}
        payload.update(addons)
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
Ejemplo n.º 26
0
def avatar_delete(request):
    # noinspection PyBroadException
    try:
        remove_thumbnails(request.user.img.path)
        remove_file(request.user.img.path)
        request.user.img = ''
        request.user.save()
        payload = dict(success=True)
        # noinspection PyBroadException
        try:
            addons = dict(html=render_to_string('user/avatar.html',
                                                {'object': request.user}))
        except:
            addons = dict()
        payload.update(addons)
    except:
        payload = dict(success=False)
    return ajax_answer_lazy(payload)
Ejemplo n.º 27
0
def avatar_set(request):
    uploader = AjaxUploader(filetype='image', upload_dir=setting('AVATAR_UPLOAD_DIR', 'avatars'),
                            size_limit=setting('AVATAR_UPLOAD_SIZE', 1024000))
    result = uploader.handle_upload(request)
    if result['success']:
        try:
            remove_thumbnails(request.user.img.url)
            remove_file(request.user.img.url)
        except:
            pass
        request.user.img = result['path']
        request.user.save()
        try:
            addons = dict(html=render_to_string('user/avatar.html', {'object': request.user}))
        except:
            addons = {}
        result.update(addons)
    return ajax_answer_lazy(result)
Ejemplo n.º 28
0
def avatar_set(request):
    uploader = AjaxUploader(filetype='image',
                            upload_dir=setting('AVATAR_UPLOAD_DIR', 'avatars'),
                            size_limit=setting('AVATAR_UPLOAD_SIZE', 1024000))
    result = uploader.handle_upload(request)
    if result['success']:
        try:
            remove_thumbnails(request.user.img.url)
            remove_file(request.user.img.url)
        except:
            pass
        request.user.img = result['path']
        request.user.save()
        try:
            addons = dict(html=render_to_string('user/avatar.html',
                                                {'object': request.user}))
        except:
            addons = {}
        result.update(addons)
    return ajax_answer_lazy(result)
Ejemplo n.º 29
0
 def _ajax_upload(self, request, **kwargs):
     if request.method == "POST":
         tmb = None
         self._upload_file(request, **kwargs)
         fullpath = os.path.join(settings.MEDIA_ROOT,
                                 self.extra_context['path'])
         try:
             i = Image.open(fullpath)
         except:
             messages.error(request, "File is not image format")
             os.remove(fullpath)
             self.success = False
             self.pic_id = None
         if self.success:
             ctype = get_object_or_404(ContentType,
                                       id=int(kwargs['content_type']))
             object_id = int(kwargs['object_id'])
             obj = ctype.get_object_for_this_type(pk=object_id)
             try:
                 remove_thumbnails(obj.img.path)
                 remove_file(obj.img.path)
                 obj.img.delete()
             except:
                 pass
             obj.img = self.extra_context['path']
             obj.save()
             # let Ajax Upload know whether we saved it or not
             addons = {
                 'tmb':
                 make_thumbnail(obj.img.url,
                                width=int(kwargs['width']),
                                height=int(kwargs['height']),
                                aspect=int(kwargs['aspect']))
             }
         payload = {'success': self.success, 'filename': self.filename}
         if self.extra_context is not None:
             payload.update(self.extra_context)
         if addons:
             payload.update(addons)
         return AjaxAnswer(payload)
Ejemplo n.º 30
0
def avatar_set(request):
    uploader = AjaxUploader(filetype='image', size_limit=4096000)
    result = uploader.handle_upload(request)
    if result['success']:
        # noinspection PyBroadException
        try:
            remove_thumbnails(request.user.img.path)
            remove_file(request.user.img.path)
        except:
            pass
        request.user.img.save(
            result['filename'],
            File(open(result['path'] + '/' + result['filename'], 'rb')))
        request.user.save()
        # noinspection PyBroadException
        try:
            addons = dict(html=render_to_string('user/avatar.html',
                                                {'object': request.user}))
        except:
            addons = dict()
        result.update(addons)
    return ajax_answer_lazy(result)
Ejemplo n.º 31
0
def file_uploader(request, **kwargs):
    uploader = AjaxUploader(filetype='image', upload_dir=setting('IMAGE_UPLOAD_DIR', 'images'),
                            size_limit=setting('IMAGE_UPLOAD_SIZE', 10485760))
    result = uploader.handle_upload(request)
    if result['success']:
        ctype = get_object_or_404(ContentType, id=int(kwargs['content_type']))
        object_id = int(kwargs['object_id'])
        obj = ctype.get_object_for_this_type(pk=object_id)
        try:
            remove_thumbnails(obj.img.path)
            remove_file(obj.img.path)
            obj.img.delete()
        except:
            pass
        obj.img = result['path']
        obj.save()
        try:
            addons = dict(tmb=make_thumbnail(obj.img.url, width=int(kwargs['width']), height=int(kwargs['height']),
                                             aspect=int(kwargs['aspect'])))
        except:
            addons = {}
        result.update(addons)
    return AjaxAnswer(result)
Ejemplo n.º 32
0
 def delete(self, *args, **kwargs):
     try:
         remove_file(self.doc.path)
     except:
         pass
     super(Doc, self).delete(*args, **kwargs)