Exemplo n.º 1
0
def handle_uploaded_file(f,name):
    """ """
    photo = MPhoto()
    photo.title = name 
    photo.image = f
    photo.save()
    return photo
Exemplo n.º 2
0
def loadUrlImage(url, place, name='', format='jpg'):
    """ """
    if not url:
        url = 'http://irudiak.argazkiak.org/1d3023545b4051907e533648e66329f8_c.jpg'
        name = 'Kakalardoa'

    if " " in url:
        #import pdb
        #pdb.set_trace()
        a=1
    image = _getUrlImage(url)

    if not image:
        return 0

    photo = MPhoto()
    photo.name = name[:100]
    photo.place = place
    
    image_t = Image.open(ContentFile(image.read()))
    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:
        a = 3
    except Exception, e:
        print 'Errorea irudi honekin RGB', photo.name, e
        return photo      
Exemplo n.º 3
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))
Exemplo n.º 4
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))
Exemplo n.º 5
0
def handle_uploaded_file(f, name):
    """ """
    photo = MPhoto()
    photo.title = name
    photo.image = f
    photo.save()
    return photo
Exemplo n.º 6
0
def addPhoto(request, slug=''):
    template_name = 'addphoto'
    place = get_object_or_404(Place, slug=slug)
    if request.method == 'POST':  # If the form has been submitted...
        if request.FILES.get('image', ''):
            photo = MPhoto()
            photo.name = request.REQUEST['name']
            photo.image = request.FILES['image']
            photo.user = request.user
            photo.place = place
            photo.save()
        return HttpResponseRedirect(
            place.get_absolute_url())  # Redirect after POST
    else:
        return render_to_response('addphoto.html',
                                  locals(),
                                  context_instance=RequestContext(request))
Exemplo n.º 7
0
def addPhoto(request, slug=''):
    template_name='addphoto'
    place = get_object_or_404(Place, slug=slug)
    if request.method == 'POST': # If the form has been submitted...
        if request.FILES.get('image',''):
            photo = MPhoto()
            photo.name = request.REQUEST['name']
            photo.image = request.FILES['image']
            photo.user= request.user
            photo.place = place
            photo.save()
        return HttpResponseRedirect(place.get_absolute_url()) # Redirect after POST
    else:
        return render_to_response('addphoto.html', locals(), context_instance=RequestContext(request)
        )
Exemplo n.º 8
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
Exemplo n.º 9
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