Exemplo n.º 1
0
def service_image(request, sid, picid, action_type):
    """ Контроллер картинок услуг """
    serv = Service.objects.get(id=sid)
    if action_type == 'insert':
        if request.FILES.get('service_image'):
            pic = ServicePic.objects.create(image=request.FILES['service_image'],
                                            filename=request.FILES['service_image'],
                                            position=ServicePic.objects.filter(service=serv).count() + 1,
                                            service=serv)
            pic.save()
    elif action_type == 'delete':
        pic = ServicePic.objects.get(id=picid)
        thumb = pic.image.path + "." + "170x120" + "_q85_crop-smart.jpg"
        if os.path.isfile(thumb):
            os.remove(thumb)
        pic.image.delete()
        ServicePic.objects.filter(id=picid).delete()
    elif action_type == 'posinc' or action_type == 'posdec':
        picthis = ServicePic.objects.get(id=picid)
        pos = picthis.position
        if action_type == 'posinc':
            picnext = ServicePic.objects.get(position=pos+1)
            picthis.position = pos+1
            picnext.position = pos
            picthis.save()
            picnext.save()
        elif action_type == 'posdec':
            picprev = ServicePic.objects.get(position=pos-1)
            picthis.position = pos-1
            picprev.position = pos
            picthis.save()
            picprev.save()
    return HttpResponseRedirect(reverse('ns_adminka:ns_services:single', args=[str(sid)]))
Exemplo n.º 2
0
def prices_image(request):
    """ Контроллер картинки с ценами """
    if request.FILES.get('prices_image'):
        pricepics = PricePic.objects.all()
        if pricepics.count() > 0:
            for p in pricepics:
                thumb = p.image.path + "." + p.size + "_q85_crop-smart.jpg"
                if os.path.isfile(thumb):
                    os.remove(thumb)
                p.image.delete()
                p.delete()
        img_file = request.FILES['prices_image']
        pic = PricePic.objects.create()
        pic.save()
        pic.image = img_file
        pic.filename = img_file
        pic.save()
    return HttpResponseRedirect(reverse('ns_adminka:ns_prices:page'))
Exemplo n.º 3
0
def prices_image(request):
    """ Контроллер картинки с ценами """
    if request.FILES.get('prices_image'):
        pricepics = PricePic.objects.all()
        if pricepics.count() > 0:
            for p in pricepics:
                thumb = p.image.path + "." + p.size + "_q85_crop-smart.jpg"
                if os.path.isfile(thumb):
                    os.remove(thumb)
                p.image.delete()
                p.delete()
        img_file = request.FILES['prices_image']
        pic = PricePic.objects.create()
        pic.save()
        pic.image = img_file
        pic.filename = img_file
        pic.save()
    return HttpResponseRedirect(reverse('ns_adminka:ns_prices:page'))
Exemplo n.º 4
0
def faq_image(request, fid, action_type):
    """ Контроллер картинок вопросов и ответов """
    faq = FAQRecord.objects.get(id=fid)
    if action_type == 'upload':
        if request.FILES.get('faq_image'):
            if faq.image:
                thumb = faq.image.path + "." + faq.size + "_q85_crop-smart.jpg"
                if os.path.isfile(thumb):
                    os.remove(thumb)
                faq.image.delete()
            img_file = request.FILES['faq_image']
            faq.image = img_file
            faq.filename = img_file
        if request.REQUEST.get('faq_size'):
            old = faq.image.path + "." + faq.size + "_q85_crop-smart.jpg"
            if os.path.isfile(old):
                os.remove(old)
            faq.size = request.REQUEST['faq_size']
    elif action_type == 'clear':
        thumb = faq.image.path + "." + faq.size + "_q85_crop-smart.jpg"
        if os.path.isfile(thumb):
            os.remove(thumb)
        faq.image.delete()
        faq.filename = None
        faq.size = u'170x120'
    elif action_type == 'align_left':
        faq.align_left = True
    elif action_type == 'align_right':
        faq.align_left = False
    faq.save()
    return HttpResponseRedirect(reverse('ns_adminka:ns_faq:single', args=[str(fid)]))
Exemplo n.º 5
0
def frontpage_advert_crud(request, advid, action_type):
    """ CRUD-контроллер популярного """
    if action_type == 'insert':
        advert = FrontpageAdvert()
        advert.position = FrontpageAdvert.objects.all().count() + 1
        advert.save()
        advid = advert.id
    elif action_type == 'delete':
        advert = FrontpageAdvert.objects.get(id=advid)
        if advert.image:
            thumb = advert.image.path + "." + "240x240" + "_q85_crop-smart.jpg"
            if os.path.isfile(thumb):
                os.remove(thumb)
            advert.image.delete()
        FrontpageAdvert.objects.filter(id=advid).delete()
        return HttpResponseRedirect(reverse('ns_adminka:ns_frontpage:list'))
    elif action_type == 'update':
        # UPDATE не вызывает метод save(), т.е. auto_now=True для поля changed не сработает!!!
        advert = FrontpageAdvert.objects.get(id=advid)
        if request.REQUEST.get('advert_title'):
            advert.title = request.REQUEST['advert_title']
        if request.REQUEST.get('advert_link'):
            advert.link = request.REQUEST['advert_link']
        if request.REQUEST.get('advert_text'):
            advert.text = request.REQUEST['advert_text']
        if request.FILES.get('advert_image'):
            if advert.image:
                thumb = advert.image.path + "." + "240x240" + "_q85_crop-smart.jpg"
                if os.path.isfile(thumb):
                    os.remove(thumb)
                advert.image.delete()
            img_file = request.FILES['advert_image']
            advert.image = img_file
            advert.filename = img_file
        advert.save()
    elif action_type == 'clear':
        advert = FrontpageAdvert.objects.get(id=advid)
        thumb = advert.image.path + "." + "240x240" + "_q85_crop-smart.jpg"
        if os.path.isfile(thumb):
            os.remove(thumb)
        advert.image.delete()
        advert.filename = None
        advert.save()
    elif action_type == 'posinc' or action_type == 'posdec':
        advthis = FrontpageAdvert.objects.get(id=advid)
        pos = advthis.position
        if action_type == 'posinc':
            advnext = FrontpageSlide.objects.get(position=pos+1)
            advthis.position = pos+1
            advnext.position = pos
            advthis.save()
            advnext.save()
        elif action_type == 'posdec':
            advprev = FrontpageAdvert.objects.get(position=pos-1)
            advthis.position = pos-1
            advprev.position = pos
            advthis.save()
            advprev.save()
        return HttpResponseRedirect(reverse('ns_adminka:ns_frontpage:list'))
    return HttpResponseRedirect(reverse('ns_adminka:ns_frontpage:advert_single', args=[str(advid)]))
Exemplo n.º 6
0
def faq_image(request, fid, action_type):
    """ Контроллер картинок вопросов и ответов """
    faq = FAQRecord.objects.get(id=fid)
    if action_type == 'upload':
        if request.FILES.get('faq_image'):
            if faq.image:
                thumb = faq.image.path + "." + faq.size + "_q85_crop-smart.jpg"
                if os.path.isfile(thumb):
                    os.remove(thumb)
                faq.image.delete()
            img_file = request.FILES['faq_image']
            faq.image = img_file
            faq.filename = img_file
        if request.REQUEST.get('faq_size'):
            old = faq.image.path + "." + faq.size + "_q85_crop-smart.jpg"
            if os.path.isfile(old):
                os.remove(old)
            faq.size = request.REQUEST['faq_size']
    elif action_type == 'clear':
        thumb = faq.image.path + "." + faq.size + "_q85_crop-smart.jpg"
        if os.path.isfile(thumb):
            os.remove(thumb)
        faq.image.delete()
        faq.filename = None
        faq.size = u'170x120'
    elif action_type == 'align_left':
        faq.align_left = True
    elif action_type == 'align_right':
        faq.align_left = False
    faq.save()
    return HttpResponseRedirect(
        reverse('ns_adminka:ns_faq:single', args=[str(fid)]))
Exemplo n.º 7
0
def frontpage_banner(request, bid, action_type):
    """ Контроллер баннера """
    banner = FrontpageBanner.objects.get(id=bid)
    if action_type == 'upload':
        if request.FILES.get('banner_image'):
            if banner.image:
                thumb = banner.image.path + "." + "1400x320" + "_q85_crop-smart.jpg"
                if os.path.isfile(thumb):
                    os.remove(thumb)
                banner.image.delete()
            img_file = request.FILES['banner_image']
            banner.image = img_file
            banner.filename = img_file
    elif action_type == 'clear':
        thumb = banner.image.path + "." + "1400x320" + "_q85_crop-smart.jpg"
        if os.path.isfile(thumb):
            os.remove(thumb)
        banner.image.delete()
        banner.filename = None
        banner.size = u'170x120'
    banner.save()
    return HttpResponseRedirect(reverse('ns_adminka:ns_frontpage:list'))
Exemplo n.º 8
0
def sugarwaxing_image(request, pid, action_type):
    """ Контроллер картинок """
    pg = PageType1.objects.get(id=pid)
    if action_type == 'upload':
        if request.FILES.get('faq_image'):
            if pg.image:
                thumb = pg.image.path + "." + "819x614" + "_q85_crop-smart.jpg"
                if os.path.isfile(thumb):
                    os.remove(thumb)
                pg.image.delete()
            img_file = request.FILES['faq_image']
            pg.image = img_file
            pg.filename = img_file
    elif action_type == 'clear':
        thumb = pg.image.path + "." + "819x614" + "_q85_crop-smart.jpg"
        if os.path.isfile(thumb):
            os.remove(thumb)
        pg.image.delete()
        pg.filename = None
        pg.size = u'170x120'
    pg.save()
    return HttpResponseRedirect(reverse('ns_adminka:ns_sugarwaxing:page'))
Exemplo n.º 9
0
def frontpage_banner(request, bid, action_type):
    """ Контроллер баннера """
    banner = FrontpageBanner.objects.get(id=bid)
    if action_type == 'upload':
        if request.FILES.get('banner_image'):
            if banner.image:
                thumb = banner.image.path + "." + "1400x320" + "_q85_crop-smart.jpg"
                if os.path.isfile(thumb):
                    os.remove(thumb)
                banner.image.delete()
            img_file = request.FILES['banner_image']
            banner.image = img_file
            banner.filename = img_file
    elif action_type == 'clear':
        thumb = banner.image.path + "." + "1400x320" + "_q85_crop-smart.jpg"
        if os.path.isfile(thumb):
            os.remove(thumb)
        banner.image.delete()
        banner.filename = None
        banner.size = u'170x120'
    banner.save()
    return HttpResponseRedirect(reverse('ns_adminka:ns_frontpage:list'))
Exemplo n.º 10
0
def frontpage_slide_crud(request, sid, action_type):
    """ CRUD-контроллер слайдов """
    if action_type == 'insert':
        slide = FrontpageSlide()
        slide.position = FrontpageSlide.objects.all().count() + 1
        slide.save()
        sid = slide.id
    elif action_type == 'delete':
        slide = FrontpageSlide.objects.get(id=sid)
        if slide.image:
            thumb = slide.image.path + "." + "170x120" + "_q85_crop-smart.jpg"
            if os.path.isfile(thumb):
                os.remove(thumb)
            slide.image.delete()
        FrontpageSlide.objects.filter(id=sid).delete()
        return HttpResponseRedirect(reverse('ns_adminka:ns_frontpage:list'))
    elif action_type == 'update':
        # UPDATE не вызывает метод save(), т.е. auto_now=True для поля changed не сработает!!!
        slide = FrontpageSlide.objects.get(id=sid)
        if request.REQUEST.get('slide_title'):
            slide.title = request.REQUEST['slide_title']
        if request.FILES.get('slide_image'):
            if slide.image:
                thumb = slide.image.path + "." + "170x120" + "_q85_crop-smart.jpg"
                if os.path.isfile(thumb):
                    os.remove(thumb)
                slide.image.delete()
            img_file = request.FILES['slide_image']
            slide.image = img_file
            slide.filename = img_file
        slide.save()
    elif action_type == 'clear':
        slide = FrontpageSlide.objects.get(id=sid)
        thumb = slide.image.path + "." + "170x120" + "_q85_crop-smart.jpg"
        if os.path.isfile(thumb):
            os.remove(thumb)
        slide.image.delete()
        slide.filename = None
        slide.save()
    elif action_type == 'posinc' or action_type == 'posdec':
        slidethis = FrontpageSlide.objects.get(id=sid)
        pos = slidethis.position
        if action_type == 'posinc':
            slidenext = FrontpageSlide.objects.get(position=pos + 1)
            slidethis.position = pos + 1
            slidenext.position = pos
            slidethis.save()
            slidenext.save()
        elif action_type == 'posdec':
            slideprev = FrontpageSlide.objects.get(position=pos - 1)
            slidethis.position = pos - 1
            slideprev.position = pos
            slidethis.save()
            slideprev.save()
        return HttpResponseRedirect(reverse('ns_adminka:ns_frontpage:list'))
    return HttpResponseRedirect(
        reverse('ns_adminka:ns_frontpage:slide_single', args=[str(sid)]))
Exemplo n.º 11
0
def frontpage_slide_crud(request, sid, action_type):
    """ CRUD-контроллер слайдов """
    if action_type == 'insert':
        slide = FrontpageSlide()
        slide.position = FrontpageSlide.objects.all().count() + 1
        slide.save()
        sid = slide.id
    elif action_type == 'delete':
        slide = FrontpageSlide.objects.get(id=sid)
        if slide.image:
            thumb = slide.image.path + "." + "170x120" + "_q85_crop-smart.jpg"
            if os.path.isfile(thumb):
                os.remove(thumb)
            slide.image.delete()
        FrontpageSlide.objects.filter(id=sid).delete()
        return HttpResponseRedirect(reverse('ns_adminka:ns_frontpage:list'))
    elif action_type == 'update':
        # UPDATE не вызывает метод save(), т.е. auto_now=True для поля changed не сработает!!!
        slide = FrontpageSlide.objects.get(id=sid)
        if request.REQUEST.get('slide_title'):
            slide.title = request.REQUEST['slide_title']
        if request.FILES.get('slide_image'):
            if slide.image:
                thumb = slide.image.path + "." + "170x120" + "_q85_crop-smart.jpg"
                if os.path.isfile(thumb):
                    os.remove(thumb)
                slide.image.delete()
            img_file = request.FILES['slide_image']
            slide.image = img_file
            slide.filename = img_file
        slide.save()
    elif action_type == 'clear':
        slide = FrontpageSlide.objects.get(id=sid)
        thumb = slide.image.path + "." + "170x120" + "_q85_crop-smart.jpg"
        if os.path.isfile(thumb):
            os.remove(thumb)
        slide.image.delete()
        slide.filename = None
        slide.save()
    elif action_type == 'posinc' or action_type == 'posdec':
        slidethis = FrontpageSlide.objects.get(id=sid)
        pos = slidethis.position
        if action_type == 'posinc':
            slidenext = FrontpageSlide.objects.get(position=pos+1)
            slidethis.position = pos+1
            slidenext.position = pos
            slidethis.save()
            slidenext.save()
        elif action_type == 'posdec':
            slideprev = FrontpageSlide.objects.get(position=pos-1)
            slidethis.position = pos-1
            slideprev.position = pos
            slidethis.save()
            slideprev.save()
        return HttpResponseRedirect(reverse('ns_adminka:ns_frontpage:list'))
    return HttpResponseRedirect(reverse('ns_adminka:ns_frontpage:slide_single', args=[str(sid)]))
Exemplo n.º 12
0
def frontpage_advert_crud(request, advid, action_type):
    """ CRUD-контроллер популярного """
    if action_type == 'insert':
        advert = FrontpageAdvert()
        advert.position = FrontpageAdvert.objects.all().count() + 1
        advert.save()
        advid = advert.id
    elif action_type == 'delete':
        advert = FrontpageAdvert.objects.get(id=advid)
        if advert.image:
            thumb = advert.image.path + "." + "240x240" + "_q85_crop-smart.jpg"
            if os.path.isfile(thumb):
                os.remove(thumb)
            advert.image.delete()
        FrontpageAdvert.objects.filter(id=advid).delete()
        return HttpResponseRedirect(reverse('ns_adminka:ns_frontpage:list'))
    elif action_type == 'update':
        # UPDATE не вызывает метод save(), т.е. auto_now=True для поля changed не сработает!!!
        advert = FrontpageAdvert.objects.get(id=advid)
        if request.REQUEST.get('advert_title'):
            advert.title = request.REQUEST['advert_title']
        if request.REQUEST.get('advert_link'):
            advert.link = request.REQUEST['advert_link']
        if request.REQUEST.get('advert_text'):
            advert.text = request.REQUEST['advert_text']
        if request.FILES.get('advert_image'):
            if advert.image:
                thumb = advert.image.path + "." + "240x240" + "_q85_crop-smart.jpg"
                if os.path.isfile(thumb):
                    os.remove(thumb)
                advert.image.delete()
            img_file = request.FILES['advert_image']
            advert.image = img_file
            advert.filename = img_file
        advert.save()
    elif action_type == 'clear':
        advert = FrontpageAdvert.objects.get(id=advid)
        thumb = advert.image.path + "." + "240x240" + "_q85_crop-smart.jpg"
        if os.path.isfile(thumb):
            os.remove(thumb)
        advert.image.delete()
        advert.filename = None
        advert.save()
    elif action_type == 'posinc' or action_type == 'posdec':
        advthis = FrontpageAdvert.objects.get(id=advid)
        pos = advthis.position
        if action_type == 'posinc':
            advnext = FrontpageSlide.objects.get(position=pos + 1)
            advthis.position = pos + 1
            advnext.position = pos
            advthis.save()
            advnext.save()
        elif action_type == 'posdec':
            advprev = FrontpageAdvert.objects.get(position=pos - 1)
            advthis.position = pos - 1
            advprev.position = pos
            advthis.save()
            advprev.save()
        return HttpResponseRedirect(reverse('ns_adminka:ns_frontpage:list'))
    return HttpResponseRedirect(
        reverse('ns_adminka:ns_frontpage:advert_single', args=[str(advid)]))