Beispiel #1
0
def gallery(request, slugs=None):
    parent_slug, current_gallery = process_category_thread(request, slugs)
    no_image_thumb_url = os.path.join(settings.STATIC_URL, 
                                          settings.DAG_NO_IMAGE[settings.DAG_GALLERY_THUMB_SIZE_KEY])
    
    # TODO Find a better way to do this (parent by default for a category, i.e. root)
    if current_gallery:
        children_galleries = current_gallery.get_children().filter(is_public=True)
        brother_galleries = current_gallery.get_siblings(include_self=True).filter(is_public=True)
        photos = current_gallery.photos.public()
        if current_gallery.photos_ordering:
            photos = photos.custom_order_by(current_gallery.photos_ordering)
    else:
        brother_galleries = None
        children_galleries = None
        photos = Photo.objects.public().orphans()
    
    page_no = int(request.GET.get('page', 1))
    paginator = DiggPaginator(photos, django_settings.get('DAG_RESULTS_PER_PAGE'))
    template = 'website/gallery.html' if slugs else 'website/index.html'  
    return render_to_response(template, {'gallery': current_gallery, 
                                         'brother_galleries': brother_galleries, 
                                         'children_galleries': children_galleries,
                                         'search_options_form': SearchOptionsForm(),
                                         'no_image_thumb_url': no_image_thumb_url,
                                         'photos_page': paginator.page(page_no),
                                         }, context_instance=RequestContext(request)
                              )
Beispiel #2
0
def index(request, slugs=None):
    # TODO This function is perfect for a request context processors reused
    # in gallery pages...
    parent_slug, current_category = process_category_thread(request, slugs, 'daguerro')
    categories = Gallery.objects.filter(parent__title_slug=parent_slug)

    if current_category:
        photos = current_category.photos.all()
        if current_category.photos_ordering:
            photos = photos.custom_order_by(current_category.photos_ordering)
    else:
        photos = Photo.objects.orphans()

    user_groups = request.user.groups.all().values_list("name", flat=True)
    if 'Editor' in user_groups and len(user_groups) == 1:
        return HttpResponseRedirect(reverse("daguerro-pages-index"))

    page_no = int(request.GET.get('page', 1))
    paginator = DiggPaginator(photos, django_settings.get('DAG_RESULTS_PER_PAGE'))
    context = {'categories': categories,
               'current_category': current_category,
               'photos_page': paginator.page(page_no),
               'add_photo_in_root': django_settings.get('DAG_ALLOW_PHOTOS_IN_ROOT_GALLERY'),
               'no_image_thumb_url': os.path.join(settings.STATIC_URL,
                                                  settings.DAG_NO_IMAGE[settings.DAG_GALLERY_THUMB_SIZE_KEY]),
               'search_options_form': SearchOptionsForm(),
               }
    return render_to_response('daguerro/gallery.html', context,
                              context_instance=RequestContext(request))
Beispiel #3
0
def gallery_delete(request, slugs=None):
    parent_slug, current_category = process_category_thread(request, slugs, 'daguerro')
    if current_category.parent:
        slugs = current_category.parent.slugs_path()
    else:
        slugs = None
    gallery = get_object_or_404(Gallery, id=current_category.id)
    gallery.delete()
    return redirect_to_gallery(slugs)
Beispiel #4
0
def gallery_delete_intent(request, slugs):
    parent_slug, current_category = process_category_thread(request, slugs, 'daguerro')
    photos_to_delete = Photo.objects.only_in_gallery(current_category)
    galleries_to_delete = current_category.children.all()
    return render_to_response('daguerro/gallery_modal_body.html',
                              {'gallery': current_category,
                               'photos_to_delete': photos_to_delete,
                               'galleries_to_delete': galleries_to_delete,
                               },
                              context_instance=RequestContext(request))
Beispiel #5
0
def photo(request, gallery_slugs, photo_slug):
    parent_slug, current_gallery = process_category_thread(request, gallery_slugs)
    parent_category = current_gallery.parent
    
    try:
        photo = Photo.objects.get(title_slug=photo_slug)
    except Photo.DoesNotExist:
        raise Http404
    custom_fields = photo.custom_fields.exclude(value='')
    
    return render_to_response('website/photo.html', {
            'photo': photo,
            'custom_fields': custom_fields,
            'parent_category': parent_category,
            'gallery_slugs': gallery_slugs,
            'search_options_form': SearchOptionsForm(),
            }, context_instance=RequestContext(request))
Beispiel #6
0
def photo(request, action='add', slugs=None, slug=None):
    # TODO This function is perfect for a request context processor reused in gallery pages...
    parent_slug, current_category = process_category_thread(request, slugs, 'daguerro')

    if slug:
        current_action_title = _("Edit photography")
        extra_context = {'current_action': 'edit'}
        photo = get_object_or_404(Photo, title_slug=slug)
        initial_galleries = photo.galleries.all().values_list('id', flat=True)
    else:
        current_action_title = _("Add photography")
        extra_context = {'current_action': 'add'}
        photo = Photo()
        try:
            initial_galleries = [Gallery.objects.get(title_slug=parent_slug).id]
        except Gallery.DoesNotExist:
            initial_galleries = None

    request.breadcrumbs(current_action_title, None)

    if request.method == 'POST':
        # Force slugify, otherwise I need to fix photologue model or need client-side filling.
        request.POST['title_slug'] = slugify(request.POST['title'])
        form = PhotoForm(request.POST, request.FILES, instance=photo)
        if form.is_valid():
            form.save()
            return redirect_to_gallery(slugs, page=request.GET.get("page", None))
    else:
        form = PhotoForm(instance=photo, initial={
                'galleries': initial_galleries,
                'is_public': django_settings.get('DAG_PUBLISH_BY_DEFAULT', default=False)
                })

    return render_to_response('daguerro/photo.html',
                              {'form': form,
                               'photo': photo,
                               'extra_context': extra_context,
                               'current_category': current_category,
                               'current_action_title': current_action_title,
                               'current_action': action,
                               'no_image_thumb_url': os.path.join(settings.STATIC_URL,
                                                     settings.DAG_NO_IMAGE[settings.DAG_PHOTO_THUMB_SIZE_KEY]),
                               },
                              context_instance=RequestContext(request))
Beispiel #7
0
def gallery(request, action='add', slugs=""):
    # TODO This function is perfect for a request context processors reused in gallery pages...
    parent_slug, current_category = process_category_thread(request, slugs, 'daguerro', action)

    if action == 'edit':
        current_action_title = _("Edit Gallery")
        parent_gallery = current_category.parent.id if current_category.parent else None
        gallery = get_object_or_404(Gallery, title_slug=current_category.title_slug)
    elif action == 'add':
        current_action_title = _("Add Gallery")
        parent_gallery = current_category.id if current_category else None
        gallery = Gallery()

    request.breadcrumbs(current_action_title, None)

    if request.method == 'POST':
        # Force slugify, otherwise I need to fix photologue model or need client-side filling.
        request.POST['title_slug'] = slugify(request.POST['title'])
        form = GalleryForm(request.POST, request.FILES, instance=gallery)
        if form.is_valid():
            form.save()
            return redirect_to_gallery(slugs, gallery, action)
    else:
        form = GalleryForm(instance=gallery, initial={
                'parent': parent_gallery,
                'is_public': django_settings.get('DAG_PUBLISH_BY_DEFAULT', default=False)
                })

    return render_to_response('daguerro/gallery_form.html',
                              {'form': form,
                               'current_category': current_category,
                               'current_action_title': current_action_title,
                               'current_action': action,
                               'no_image_thumb_url': os.path.join(settings.STATIC_URL,
                                                                  settings.DAG_NO_IMAGE['gallery']),
                               'search_options_form': SearchOptionsForm(),
                               },
                              context_instance=RequestContext(request))