Beispiel #1
0
def async_file_upload(request, id):
    service_provider = get_object_or_404(ServiceProvider, id=id)

    status = 200

    if request.user.service_provider_id != int(id):
        return HttpResponse("Not allowed", status=403)

    name = request.FILES.getlist('image')[0].name
    size = request.FILES.getlist('image')[0].size

    file = dict()
    file['name'] = name
    file['size'] = size

    image_form = ServiceProviderImageForm(request.POST, request.FILES)
    if image_form.is_valid():
        image = image_form.save(commit=False)
        image.service_provider_id = id
        image.save()

        file['id'] = image.id
        file['url'] = image.image.url
    else:
        file['error'] = image_form.error.encode('utf-8')

    json_payload = dict()
    json_payload['files'] = [file]

    return HttpResponse(json.dumps(json_payload),
                        content_type="application/json",
                        status=status)
Beispiel #2
0
def view_gallery(request, id):

    gallery = ServiceProviderImage.objects.filter(service_provider_id=id)
    # ServiceProviderImage.objects.all().delete()
    edit_gallery = False
    # print "id, provID", id, request.user.service_provider_id
    if hasattr(request.user, 'service_provider_id'):
        if str(id) == str(request.user.service_provider_id):
            edit_gallery = True

    if request.method == 'POST':
        if request.POST.get('action') == 'delete':
            form = ServiceProviderImageForm()
            if request.POST.getlist('img_id'):
                for img_id in request.POST.getlist('img_id'):
                    print "iiid", img_id
                    img = ServiceProviderImage.objects.get(id=int(img_id))
                    img.delete()

        if request.POST.get('action') == 'update':
            form = ServiceProviderImageForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.save(commit=False)
                image.service_provider_id = request.user.service_provider_id
                image.save()
    else:
        form = ServiceProviderImageForm()

    return render_to_response('browse/gallery.html', locals(), context_instance=RequestContext(request))
Beispiel #3
0
def async_file_upload(request, id):
    service_provider = get_object_or_404(ServiceProvider, id=id)

    status = 200

    if request.user.service_provider_id != int(id):
        return HttpResponse("Not allowed", status=403)

    name = request.FILES.getlist('image')[0].name
    size = request.FILES.getlist('image')[0].size

    file = dict()
    file['name'] = name
    file['size'] = size

    image_form = ServiceProviderImageForm(request.POST, request.FILES)
    if image_form.is_valid():
        image = image_form.save(commit=False)
        image.service_provider_id = id
        image.save()

        file['id'] = image.id
        file['url'] = image.image.url
    else:
        file['error'] = image_form.error.encode('utf-8')

    json_payload = dict()
    json_payload['files'] = [file]

    return HttpResponse(json.dumps(json_payload), content_type="application/json", status=status)
Beispiel #4
0
def view_gallery(request, id):

    gallery = ServiceProviderImage.objects.filter(service_provider_id=id)
    # ServiceProviderImage.objects.all().delete()
    edit_gallery = False
    # print "id, provID", id, request.user.service_provider_id
    if hasattr(request.user, 'service_provider_id'):
        if str(id) == str(request.user.service_provider_id):
            edit_gallery = True

    if request.method == 'POST':
        if request.POST.get('action') == 'delete':
            form = ServiceProviderImageForm()
            if request.POST.getlist('img_id'):
                for img_id in request.POST.getlist('img_id'):
                    print "iiid", img_id
                    img = ServiceProviderImage.objects.get(id=int(img_id))
                    img.delete()

        if request.POST.get('action') == 'update':
            form = ServiceProviderImageForm(request.POST, request.FILES)
            if form.is_valid():
                image = form.save(commit=False)
                image.service_provider_id = request.user.service_provider_id
                image.save()
    else:
        form = ServiceProviderImageForm()

    return render_to_response('browse/gallery.html',
                              locals(),
                              context_instance=RequestContext(request))
Beispiel #5
0
def view_gallery(request, id):
    GENERIC_GALLERY_URL = config.GENERIC_GALLERY_URL

    service_provider = ServiceProvider.objects.get(id=id)
    service_provider_category = service_provider.category

    generic_gallery = None
    generic_gallery_id_name = None
    if service_provider_category:
        generic_gallery_id_name = service_provider_category.generic_gallery
        if generic_gallery_id_name:
            generic_gallery = config.GENERIC_GALLERY_IMAGES[generic_gallery_id_name] \
                if generic_gallery_id_name in config.GENERIC_GALLERY_IMAGES \
                else {'title': service_provider_category.name, 'values': []}

    service_categories = ServiceCategory.objects.filter(show_in_gallery=True)
    cheapest_service = None
    best_service = None
    for service_category in service_categories:
        services = Service.objects.filter(category=service_category)
        for service in services:
            if cheapest_service:
                if cheapest_service.discounted_price(
                ) > service.discounted_price():
                    cheapest_service = service

            if best_service:
                if best_service.discounted_price() < service.discounted_price(
                ):
                    best_service = service

            if cheapest_service is None:
                cheapest_service = service

            if best_service is None:
                best_service = service

    foto_services = filter(lambda x: x is not None,
                           [best_service, cheapest_service])

    gallery = ServiceProviderImage.objects.filter(service_provider_id=id)
    # ServiceProviderImage.objects.all().delete()
    edit_gallery = False
    if hasattr(request.user, 'service_provider_id'):
        if str(id) == str(request.user.service_provider_id):
            edit_gallery = True

    if request.method == 'POST':

        if request.POST.get('action') == 'delete':
            selected = request.POST.getlist('img_id')
            if selected:
                for img_id in selected:
                    img = ServiceProviderImage.objects.get(id=int(img_id))
                    img.delete()

        if request.POST.get('action') == 'delete_all':
            l = ServiceProviderImage.objects.filter(service_provider_id=id)
            gallery.delete()

        if request.POST.get('action') == 'enable_generic_gallery':
            service_provider.display_generic_gallery = True
            service_provider.save()

        if request.POST.get('action') == 'disable_generic_gallery':
            service_provider.display_generic_gallery = False
            service_provider.save()

        if request.POST.get('action') == 'upload_photo':

            error_msg = None

            dataUrlPattern = re.compile('data:image/(png|jpeg);base64,(.*)$')
            ImageData = request.POST.get('captured_photo')
            if ImageData:
                ImageData = dataUrlPattern.match(ImageData).group(2)

                if not (ImageData is None or len(ImageData) == 0):
                    ImageData = base64.b64decode(ImageData)

                    buf = StringIO(ImageData)
                    buf.seek(0, 2)

                    from time import time

                    file = InMemoryUploadedFile(
                        buf, None, 'captured_image_' + str(time()) + '.jpg',
                        'image/jpeg', buf.tell(), None)
                    buf.seek(0)

                    file.seek(0)
                    helper_form = ServiceProviderImageForm(
                        request.POST, {'image': [file]})
                    if helper_form.is_valid():
                        image = helper_form.save(commit=False)
                        image.service_provider_id = request.user.service_provider_id
                        image.save()
                    else:
                        error_msg = helper_form.image.error
                else:
                    error_msg = _("Error during decoding")
            else:
                error_msg = _("No image was submitted")
    return render_to_response('browse/gallery.html',
                              locals(),
                              context_instance=RequestContext(request))
Beispiel #6
0
def view_gallery(request, id):
    GENERIC_GALLERY_URL = config.GENERIC_GALLERY_URL

    service_provider = ServiceProvider.objects.get(id=id)
    service_provider_category = service_provider.category

    generic_gallery = None
    generic_gallery_id_name = None
    if service_provider_category:
        generic_gallery_id_name = service_provider_category.generic_gallery
        if generic_gallery_id_name:
            generic_gallery = config.GENERIC_GALLERY_IMAGES[generic_gallery_id_name] \
                if generic_gallery_id_name in config.GENERIC_GALLERY_IMAGES \
                else {'title': service_provider_category.name, 'values': []}

    service_categories = ServiceCategory.objects.filter(show_in_gallery=True)
    cheapest_service = None
    best_service = None
    for service_category in service_categories:
        services = Service.objects.filter(category=service_category)
        for service in services:
            if cheapest_service:
                if cheapest_service.discounted_price() > service.discounted_price():
                    cheapest_service = service

            if best_service:
                if best_service.discounted_price() < service.discounted_price():
                    best_service = service

            if cheapest_service is None:
                cheapest_service = service

            if best_service is None:
                best_service = service

    foto_services = filter(lambda x: x is not None, [best_service, cheapest_service])

    gallery = ServiceProviderImage.objects.filter(service_provider_id=id)
    # ServiceProviderImage.objects.all().delete()
    edit_gallery = False
    if hasattr(request.user, 'service_provider_id'):
        if str(id) == str(request.user.service_provider_id):
            edit_gallery = True

    if request.method == 'POST':

        if request.POST.get('action') == 'delete':
            selected = request.POST.getlist('img_id')
            if selected:
                for img_id in selected:
                    img = ServiceProviderImage.objects.get(id=int(img_id))
                    img.delete()

        if request.POST.get('action') == 'delete_all':
            l = ServiceProviderImage.objects.filter(service_provider_id=id)
            gallery.delete()

        if request.POST.get('action') == 'enable_generic_gallery':
            service_provider.display_generic_gallery = True
            service_provider.save()

        if request.POST.get('action') == 'disable_generic_gallery':
            service_provider.display_generic_gallery = False
            service_provider.save()

        if request.POST.get('action') == 'upload_photo':

            error_msg = None

            dataUrlPattern = re.compile('data:image/(png|jpeg);base64,(.*)$')
            ImageData = request.POST.get('captured_photo')
            if ImageData:
                ImageData = dataUrlPattern.match(ImageData).group(2)

                if not (ImageData is None or len(ImageData) == 0):
                    ImageData = base64.b64decode(ImageData)

                    buf = StringIO(ImageData)
                    buf.seek(0, 2)

                    from time import time

                    file = InMemoryUploadedFile(buf, None, 'captured_image_' + str(time()) + '.jpg', 'image/jpeg',
                                                buf.tell(), None)
                    buf.seek(0)

                    file.seek(0)
                    helper_form = ServiceProviderImageForm(request.POST, {'image': [file]})
                    if helper_form.is_valid():
                        image = helper_form.save(commit=False)
                        image.service_provider_id = request.user.service_provider_id
                        image.save()
                    else:
                        error_msg = helper_form.image.error
                else:
                    error_msg = _("Error during decoding")
            else:
                error_msg = _("No image was submitted")
    return render_to_response('browse/gallery.html', locals(), context_instance=RequestContext(request))