예제 #1
0
def edit_place(request, slug=None):
    template_name='editplace'
    user = request.user
    if request.method == 'POST':
        posta=request.POST.copy()
        place = get_object_or_404(Place, slug=slug)
        form = PlaceForm(posta, instance=place)
        if form.is_valid():
            place = form.save(commit=False)
            place.lat = float(request.POST.get("lat","0"))
            place.lon = float(request.POST.get("lon","0"))
            place.author = user
            place.save()
            if request.FILES.get('photo',''):
                photo = MPhoto()
                photo.name = request.REQUEST['name']
                photo.image = request.FILES['photo']
                photo.user= user
                photo.def_img = True
                photo.place = place
                photo.save()
            return HttpResponseRedirect(reverse("edit_places"))
        else:
            return render_to_response('places/edit_place.html', locals(), context_instance=RequestContext(request))
    else:
        place = get_object_or_404(Place, slug=slug)
        form = PlaceForm(instance=place)
        return render_to_response('places/edit_place.html', locals(), context_instance=RequestContext(request))
예제 #2
0
def edit_place(request, slug=None):
    template_name = 'editplace'
    user = request.user
    if request.method == 'POST':
        posta = request.POST.copy()
        place = get_object_or_404(Place, slug=slug)
        form = PlaceForm(posta, instance=place)
        if form.is_valid():
            place = form.save(commit=False)
            place.lat = float(request.POST.get("lat", "0"))
            place.lon = float(request.POST.get("lon", "0"))
            place.author = user
            place.save()
            if request.FILES.get('photo', ''):
                photo = MPhoto()
                photo.name = request.REQUEST['name']
                photo.image = request.FILES['photo']
                photo.user = user
                photo.def_img = True
                photo.place = place
                photo.save()
            return HttpResponseRedirect(reverse("edit_places"))
        else:
            return render_to_response('places/edit_place.html',
                                      locals(),
                                      context_instance=RequestContext(request))
    else:
        place = get_object_or_404(Place, slug=slug)
        form = PlaceForm(instance=place)
        return render_to_response('places/edit_place.html',
                                  locals(),
                                  context_instance=RequestContext(request))
예제 #3
0
def loadUrlImage(url, place, name='', format='jpg'):
    """ 
    Only called from importers. Be aware that we overwrite an image if
    it exists!!
    """

    image = _getUrlImage(url)

    if not image:
        return 0

    photos = MPhoto.objects.filter(place=place)
    if len(photos) > 0:
        photo = photos[0]
    else:
        photo = MPhoto()

    photo.name = name[:100]
    photo.place = place
    photo.def_img = True

    try:
        image_t = Image.open(ContentFile(image.read()))
    except:
        return photo
    image_t = image_t.convert("RGB")
    f = StringIO()
    image_t.save(f, "JPEG")
    f.seek(0)

    unique_slug = url.split('/')[-1].replace(' ', '_')

    photo.image.save(unique_slug, ContentFile(f.read()))

    try:
        photo.save()
    except:
        print 'Error with this image', photo.name

    return photo
예제 #4
0
def loadUrlImage(url, place, name='', format='jpg'):
    """ 
    Only called from importers. Be aware that we overwrite an image if
    it exists!!
    """
    
    image = _getUrlImage(url)

    if not image:
        return 0

    photos = MPhoto.objects.filter(place=place)
    if len(photos)>0:
        photo = photos[0]
    else:
        photo = MPhoto()

    photo.name = name[:100]
    photo.place = place
    photo.def_img = True
    
    try:
        image_t = Image.open(ContentFile(image.read()))
    except:
        return photo
    image_t = image_t.convert("RGB")
    f=StringIO()
    image_t.save(f,"JPEG")
    f.seek(0)    
    
    unique_slug = url.split('/')[-1].replace(' ','_')
    
    photo.image.save(unique_slug, ContentFile(f.read()))

    try:
        photo.save()
    except:
        print 'Error with this image', photo.name

    return photo