Ejemplo n.º 1
0
def upload_beat(request):
    placeid = request.POST.get('places_id', 0)
    place_list = Place.objects.filter(pk=placeid)
    place = None
    if place_list:
        place = place_list[0]

    # Create the place if it's not there yet
    if not (placeid and place):
        place_form = PlaceForm(request.POST)
        if place_form.is_valid():
            place = place_form.save()
        else:
            return HttpResponseForbidden(place_form.errors)

    # Create the beat
    request.POST.update({'creator': request.user.id, 'place': placeid})
    beat_form = BeatForm(request.POST, request.FILES)
    if beat_form.is_valid():
        beat = beat_form.save(commit=False)
        beat.geohash = place.geohash
        beat.save()
        beat.update_tags()
        place.add_beat(beat.id)
        request.user.add_place(placeid)
        request.user.distribute_feed(beat.id)
        resp = HttpResponseCreated()
        resp['Location'] = '/api/v1/beats/%d' % beat.id
        return resp
    else:
        return HttpResponseForbidden(beat_form.errors)
Ejemplo n.º 2
0
def submit(request):

    if request.method == 'POST':
        form = PlaceForm(request.POST, request.FILES or None)
        if form.is_valid():
                cmodel = form.save()
                if cmodel.image:
                    fn, ext = os.path.splitext(cmodel.image.name)
                    im = Image.open(cmodel.image)
            	    if im.mode not in ("L", "RGB"):
                	    im = image.convert("RGB")
                    im.thumbnail((300,300), Image.ANTIALIAS)
                    th_fl = fn + '_thumb' + ext
                    im.save(settings.MEDIA_ROOT + '/' + th_fl, "JPEG")
                    cmodel.thumb =  th_fl
                
                cmodel.save()

                return redirect(index)

        return render_to_response('places/submit.html',
                                {'contact_form': form},
                                context_instance=RequestContext(request))
    else:
        form = PlaceForm()                            
        return render_to_response('places/submit.html',
                                {'contact_form': form},
                                context_instance=RequestContext(request))
Ejemplo n.º 3
0
def add_place(request):
    if request.method == 'POST':
        form = PlaceForm(request.POST)
        if form.is_valid():
            place = form.save(commit=False)
            place.save()
            return HttpResponseRedirect(reverse(list_places) + '?info=success')
        else:
            return render(request, 'places/new_place.html', {'form': form})

    else:
        context = {'form': PlaceForm()}

        return render(request, 'places/new_place.html', context)
Ejemplo n.º 4
0
def edit_place(request, place_id):
    place = get_object_or_404(Place, pk=place_id)
    if request.method == 'POST':
        form = PlaceForm(request.POST, instance=place)
        if form.is_valid():
            p = form.save(commit=False)
            p.save()
            return HttpResponseRedirect(
                reverse(list_places) + '?info=success-edit')
        else:
            return render(request, 'places/edit_place.html', {
                'form': form,
                'place_name': place.name
            })

    else:
        return render(request, 'places/edit_place.html', {
            'form': PlaceForm(instance=place),
            'place_name': place.name
        })
Ejemplo n.º 5
0
def new_place(request):
    header = "Новое место"
    if request.user.is_authenticated:
        if request.method == "POST":
            form = PlaceForm(request.POST)
            if form.is_valid():
                place = form.save(commit=False)
                place.author = request.user
                place.save()
                return redirect('place_detail', pk=place.pk)
        else:
            form = PlaceForm()
    else:
        return HttpResponseForbidden()

    return render(request, 'edit.html', {'form': form, 'header': header})
Ejemplo n.º 6
0
def place_edit(request, pk):
    header = "Редактировать место"
    place = get_object_or_404(Place, pk=pk)
    if place.author != request.user:
        return HttpResponseForbidden()

    if request.method == "POST":
        form = PlaceForm(request.POST, instance=place)
        if form.is_valid():
            place = form.save(commit=False)
            place.save()
            return redirect('place_detail', pk=place.pk)
    else:
        form = PlaceForm(instance=place)
    return render(request, 'edit.html', {
        'form': form,
        'header': header,
        'place': place
    })
Ejemplo n.º 7
0
def new_place(request):
    if request.method == 'POST':
        form = PlaceForm(request.POST, request.FILES)
        if form.is_valid():
            new_place = form.save(commit=False)
            new_place.submitter = request.user
            new_place.save()
            
            # required because of commit=False above
            # see: http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method
            form.save_m2m() 

            # handle images
            for f in request.FILES.getlist('image'):
                new_photo = Photo(place=new_place)
                file_content = ContentFile(f.read())
                new_photo.pic.save(f.name, file_content)
                
            return HttpResponseRedirect(reverse('new-place-thanks')) 
        else:
            print form.errors
    else:
        form = PlaceForm()
    return render_to_response('places/new.html', { 'form' : form }, context_instance=RequestContext(request))
Ejemplo n.º 8
0
def add(request):
    form = PlaceForm(request.POST)
    if form.is_valid():
        form.save()
    return HttpResponse(json.dumps({'status': 'ok'}), content_type="application/json")