Example #1
0
def post_send(request):
    user = check_auth(request)
    if not user:
        return HttpResponseForbidden('error in user validation')

    if request.method != 'POST':
        return HttpResponseBadRequest('bad request post')

    form = PinDirectForm(request.POST, request.FILES)
    if form.is_valid():
        upload = request.FILES.values()[0]
        filename = create_filename(upload.name)
        try:
            with BufferedWriter(FileIO("%s/pin/images/o/%s" % (MEDIA_ROOT, filename), "wb")) as dest:
                for c in upload.chunks():
                    dest.write(c)
                model = Post()
                model.image = "pin/images/o/%s" % (filename)
                model.user = user
                model.timestamp = time.time()
                model.text = form.cleaned_data['description']
                model.category_id = form.cleaned_data['category']
                model.device = 2
                model.save()
                return HttpResponse('success')
        except IOError:
            return HttpResponseBadRequest('error')

        return HttpResponseBadRequest('bad request in form')
    else:
        HttpResponseBadRequest('error in form validation')

    return HttpResponseBadRequest('bad request')
Example #2
0
def post_send(request):
    user = check_auth(request)
    if not user:
        return HttpResponseForbidden('error in user validation')

    if request.method != 'POST':
        return HttpResponseBadRequest('bad request post')

    form = PinDirectForm(request.POST, request.FILES)
    if form.is_valid():
        upload = request.FILES.values()[0]
        filename = create_filename(upload.name)
        try:
            with BufferedWriter(
                    FileIO("%s/pin/images/o/%s" % (MEDIA_ROOT, filename),
                           "wb")) as dest:
                for c in upload.chunks():
                    dest.write(c)
                model = Post()
                model.image = "pin/images/o/%s" % (filename)
                model.user = user
                model.timestamp = time.time()
                model.text = form.cleaned_data['description']
                model.category_id = form.cleaned_data['category']
                model.device = 2
                model.save()
                return HttpResponse('success')
        except IOError:
            return HttpResponseBadRequest('error')

        return HttpResponseBadRequest('bad request in form')
    else:
        HttpResponseBadRequest('error in form validation')

    return HttpResponseBadRequest('bad request')
Example #3
0
def d_send(request):
    token = request.GET.get('token', '')

    if not token:
        return HttpResponse('error in user validate')

    try:
        api = ApiKey.objects.get(key=token)
        user = api.user
    except ApiKey.DoesNotExist:
        return HttpResponse('error in user validate')

    if request.method == 'POST' and user.is_active:
        form = PinDirectForm(request.POST, request.FILES)
        if form.is_valid():
            upload = request.FILES.values()[0]
            filename = create_filename(upload.name)

            try:
                from io import FileIO, BufferedWriter
                with BufferedWriter(
                        FileIO("%s/pin/images/o/%s" % (MEDIA_ROOT, filename),
                               "wb")) as dest:
                    for c in upload.chunks():
                        dest.write(c)

                    ## after upload we need to save model
                    model = Post()
                    model.image = "pin/images/o/%s" % (filename)
                    model.user = api.user
                    model.timestamp = time.time()
                    model.text = form.cleaned_data['description']
                    model.save()

                    return HttpResponse('success')
            except IOError:
                # could not open the file most likely
                return HttpResponse('error')
Example #4
0
def d_send(request):
    token = request.GET.get("token", "")

    if not token:
        return HttpResponse("error in user validate")

    try:
        api = ApiKey.objects.get(key=token)
        user = api.user
    except ApiKey.DoesNotExist:
        return HttpResponse("error in user validate")

    if request.method == "POST" and user.is_active:
        form = PinDirectForm(request.POST, request.FILES)
        if form.is_valid():
            upload = request.FILES.values()[0]
            filename = create_filename(upload.name)

            try:
                from io import FileIO, BufferedWriter

                with BufferedWriter(FileIO("%s/pin/images/o/%s" % (MEDIA_ROOT, filename), "wb")) as dest:
                    for c in upload.chunks():
                        dest.write(c)

                    ## after upload we need to save model
                    model = Post()
                    model.image = "pin/images/o/%s" % (filename)
                    model.user = api.user
                    model.timestamp = time.time()
                    model.text = form.cleaned_data["description"]
                    model.save()

                    return HttpResponse("success")
            except IOError:
                # could not open the file most likely
                return HttpResponse("error")