Пример #1
0
def sort_photos(request):
    if request.method == 'POST':
        slugs_path = request.POST['slugs_path']
        ordering_field = request.POST['ordering_field']
        ordering_type = request.POST['ordering_type']
        gallery_id = request.POST['gallery_id']
        if gallery_id:
            try:
                gallery = Gallery.objects.get(pk=gallery_id)
            except Gallery.DoesNotExist:
                return redirect_to_gallery(slugs_path)
            gallery.photos_ordering = "%s%s" % (ordering_type, ordering_field)
            gallery.save()
        return redirect_to_gallery(slugs_path)
Пример #2
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)
Пример #3
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))
Пример #4
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))
Пример #5
0
def photo_delete(request, photo_id, slugs=None, ):
    photo = get_object_or_404(Photo, pk=photo_id)
    photo.delete()
    return redirect_to_gallery(slugs)