Example #1
0
File: views.py Project: mitshel/HM
def guest_collection(request, guest_hash=None):
    args = RequestContext(request)
    collection = None
    if guest_hash!=None:
        try:
            collection = PhotoCollections.objects.get(access_hash=guest_hash)
        except PhotoCollections.DoesNotExist:
            collection = None

    if  collection == None:
        return Http404

    breadcumbs=[]
    photos=[]
    images=PhotoImages.objects.filter(Q(id__in = collection.get_list()))

    for i in images:
        full_path=os.path.join(i.album.base_path,i.path,i.filename).replace('\\','/')
        thumb_path=os.path.join(settings.PHOTOGAL_THUMBS_DIR,i.album.tag,i.path,addthumb(i.filename,settings.PHOTOGAL_THUMB_STR)).replace('\\','/')
        prev_path=os.path.join(settings.PHOTOGAL_THUMBS_DIR,i.album.tag,i.path,addthumb(i.filename, settings.PHOTOGAL_PREV_STR)).replace('\\','/')
        checked=False
        photos.append(element(1, i.id, i.title, full_path, thumb_path, prev_path,'', i.errorflag, checked))

    args['photos'] = photos
    args['collection'] = collection
    args['breadcumbs'] = breadcumbs
    args['guest_access'] = True
    args['guest_hash'] = guest_hash

    return render_to_response('album.html', args)
Example #2
0
File: views.py Project: mitshel/HM
def show_album(request, album_id=None, cat_id=None):
    args = RequestContext(request)
    user=request.user
    if not user.is_authenticated():
        return Http404

    if album_id==None:
        album=PhotoAlbums.objects.first()
    else:
        album=PhotoAlbums.objects.get(id=album_id)

    if cat_id!=None:
        folder=PhotoCats.objects.get(id=cat_id)
    else:
        folder=None

    breadcumbs=[]
    f=folder
    cl='current'
    while f:
        breadcumbs.insert(0,breadcumb(f.name, "/photo/album/%s/%s/"%(album.id,f.id),cl))
        cl=None
        f=f.parent
    breadcumbs.insert(0,breadcumb(album.title,"/photo/album/%s/"%album.id,cl))
    breadcumbs.insert(0,breadcumb('Фотоальбомы',"/photo/album/",))

    folders=[]
    catalogs=PhotoCats.objects.filter(album=album, parent_id=cat_id)
    for c in catalogs:
        folders.append(element(0, c.id, c.name, c.path))

    photos=[]
    images=PhotoImages.objects.filter(album=album, cat=cat_id)
    try:
        favorites = PhotoCollections.objects.get(uid=user, favorite=True).get_list()
    except PhotoCollections.DoesNotExist:
        favorites = []

    for i in images:
        full_path=os.path.join(album.base_path,i.path,i.filename).replace('\\','/')
        thumb_path=os.path.join(settings.PHOTOGAL_THUMBS_DIR,album.tag,i.path,addthumb(i.filename,settings.PHOTOGAL_THUMB_STR)).replace('\\','/')
        prev_path=os.path.join(settings.PHOTOGAL_THUMBS_DIR,album.tag,i.path,addthumb(i.filename, settings.PHOTOGAL_PREV_STR)).replace('\\','/')
        checked=(str(i.id) in favorites)
        photos.append(element(1, i.id, i.title, full_path, thumb_path, prev_path,'', i.errorflag, checked))

    args['folders'] = folders
    args['photos'] = photos
    args['album_id'] = album.id
    args['album'] = album
    args['folder'] = folder
    args['breadcumbs'] = breadcumbs

    return render_to_response('album.html', args)
Example #3
0
File: views.py Project: mitshel/HM
def show_collection(request, collection_id=None):
    args = RequestContext(request)
    user = request.user
    if not user.is_authenticated():
        return Http404

    if collection_id==None:
        collection = PhotoCollections.objects.get(favorite=True)
    else:
        collection = PhotoCollections.objects.get(id=collection_id)

    breadcumbs=[]
    cl='current'
    breadcumbs.insert(0,breadcumb(collection.title,"/photo/collect/%s/"%collection.id,cl))
    breadcumbs.insert(0,breadcumb('Коллекции',"/photo/collect/",))

    photos=[]
    images=PhotoImages.objects.filter(Q(id__in = collection.get_list()))

    try:
        favorites = PhotoCollections.objects.get(uid=user, favorite=True).get_list()
    except PhotoCollections.DoesNotExist:
        favorites = []

    for i in images:
        full_path=os.path.join(i.album.base_path,i.path,i.filename).replace('\\','/')
        thumb_path=os.path.join(settings.PHOTOGAL_THUMBS_DIR,i.album.tag,i.path,addthumb(i.filename,settings.PHOTOGAL_THUMB_STR)).replace('\\','/')
        prev_path=os.path.join(settings.PHOTOGAL_THUMBS_DIR,i.album.tag,i.path,addthumb(i.filename, settings.PHOTOGAL_PREV_STR)).replace('\\','/')
        checked=(str(i.id) in favorites)
        photos.append(element(1, i.id, i.title, full_path, thumb_path, prev_path,'', i.errorflag, checked))

    args['photos'] = photos
    args['collection'] = collection
    args['breadcumbs'] = breadcumbs

    return render_to_response('album.html', args)
Example #4
0
File: views.py Project: mitshel/HM
def guest_download_collection(request, guest_hash=None):
    collection = None
    if guest_hash!=None:
        try:
            collection = PhotoCollections.objects.get(access_hash=guest_hash)
        except PhotoCollections.DoesNotExist:
            collection = None

    if  collection == None:
        return Http404

    in_memory = BytesIO()
    zip = ZipFile(in_memory, "a")

    for id in collection.get_list():
        if id!=None and id!='':
            f=PhotoImages.objects.get(id=int(id))
            prev_path=os.path.join(PHOTOGAL_THUMBS_ROOT,f.album.tag,f.path,addthumb(f.filename, settings.PHOTOGAL_PREV_STR)).replace('\\','/')
            zip.write(prev_path, f.filename)

    # fix for Linux zip files read in Windows
    for file in zip.filelist:
        file.create_system = 0

    zip.close()

    response = HttpResponse()
    response["Content-Type"]='application/zip'
    response["Content-Disposition"] = 'attachment; filename="hmc_%s_%s.zip"'%('guest',translit(collection.title))
    response["Content-Transfer-Encoding"]='binary'

    #buf=in_memory.getvalue()
    #response["Content-Length"]=str(len(buf))
    #response.write(buf)

    in_memory.seek(0)
    response.write(in_memory.read())

    return response
Example #5
0
File: views.py Project: mitshel/HM
def info_photo(request, photo_id=None):
    user=request.user
    if not user.is_authenticated():
        return Http404
    if photo_id==None:
        return Http404

    try:
        photo = PhotoImages.objects.get(id=photo_id)
    except PhotoImages.DoesNotExist:
        return Http404
    args = RequestContext(request)
    args['photo']=photo
    args['image_path']=os.path.join(settings.PHOTOGAL_THUMBS_DIR,photo.album.tag,photo.path,addthumb(photo.filename, settings.PHOTOGAL_PREV_STR)).replace('\\','/')
    return render_to_response('info.html', args)