def gallery(request, gallery_slug, image_slug=None): """Display the Gallery Viewer, optionally opened at a specific image.""" gallery = get_object_or_404(Gallery, title_slug=gallery_slug) photos = gallery.photos.filter(is_public=True).order_by("date_taken")[:] if len(photos) == 0: raise Http404 if image_slug is None: image_slug = photos[0].title_slug next, current, prev = None, None, None for index, current in enumerate(photos): try: next = photos[index + 1] except IndexError: next = None if current.title_slug == image_slug: break prev = photos[index] if current is None: raise Http404 data = common_data(request) data.update({"gallery": gallery, "photos": photos, "prev": prev, "current": current, "next": next}) return render("photologue/gallery_detail.html", request, data)
def galleries_submit(request): """Try to upload a new gallery.""" # :TODO: check this -- file is not used?! if "zip_file" in request.FILES: file = request.FILES["zip_file"] return render("meta_manage_galleries.html", request, data_for_management(request))
def archive_general(request, template, selected_tags, year, month, day, articles, selected_blog = None, selected_user = None): """A generic archive view, used by the other, more specialized archive views.""" search_term = None tag_objects = None date_selected = None date_configuration = {'year': False, 'month': False, 'day': False} if "query" in request.GET: search_term = request.GET["query"] search_query = \ Q(title__contains = search_term) | Q(html_teaser__contains = search_term) | Q(html__contains = search_term) articles = articles.filter(search_query) if selected_tags is not None: tag_objects = Tag.objects.all().filter(url_name__in = selected_tags.split(",")) articles = articles.filter(tags__in = tag_objects).distinct() if year is not None: articles = articles.filter(publication_date__year = int(year)) date_selected = datetime(int(year), 1, 1) date_configuration['year'] = True if month is not None: articles = articles.filter(publication_date__month = Article.month_number(month)) date_selected = date_selected.replace(month = Article.month_number(month)) date_configuration['month'] = True if day is not None: articles = articles.filter(publication_date__day = int(day)) date_selected = date_selected.replace(day = int(day)) date_configuration['day'] = True articles = articles.filter(public = True) articles = articles[: ARCHIVE_LIMIT] archive_user_id = None archive_qualifier = "" if selected_user is not None: archive_user_id = selected_user.id archive_qualifier = "/%s" % selected_user.username recent_active_months = selected_blog.last_active_months() else: recent_active_months = Blog.recent_active_months() data = common_data(request) data.update({"articles": articles, "active_blog": selected_blog, "tags": Tag.used_tags(archive_user_id), "recent_active_months" : recent_active_months, "archive_qualifier": archive_qualifier, "search_term": search_term, "tags_selected": tag_objects, "date_selected": date_selected, "date_configuration": date_configuration}) return render(template, request, data)
def manage(request): """Display an welcome/overview page to the logged-in user.""" data = data_for_management(request) data.update({"welcome_phrase": random.choice( ["%s, m**********r!", "rock on, %s!", "%s to the max!", "%s, hey dude!", "hax0r %s", "%s, you bastard!", "%s, mottafokka!"]) % data["current_user"].first_name}) return render("meta_toolbox.html", request, data)
def galleries(request): """Galleries overview""" data = data_for_all(request) data["galleries"] = Gallery.objects.all() return render("meta_manage_galleries.html", request, data)
def article(request, author, year, month, day, slug): """ Display a single blog article in its blog. If the article references photos or galleries, these references are expanded to combinations of previews and links. """ user = User.objects.get(username = author) blog = get_object_or_404(Blog, owner__username = author) article = get_object_or_404(Article, author__id = user.id, publication_date__year = int(year), publication_date__month = Article.month_number(month), publication_date__day = int(day), title_in_url = slug) if not (article.public or request.user.is_authenticated()): return handle_403(request) older_articles = Article.objects.filter(publication_date__lt = article.publication_date, author = user).order_by("-publication_date") newer_articles = Article.objects.filter(publication_date__gt = article.publication_date, author = user).order_by("publication_date") if not request.user.is_authenticated(): older_articles = older_articles.filter(public = True) newer_articles = newer_articles.filter(public = True) try: previous_article = older_articles[0] except IndexError: previous_article = None try: next_article = newer_articles[0] except IndexError: next_article = None data = common_data(request) data.update({"article": article, "previous_article": previous_article, "next_article": next_article, "active_blog": blog, "tags": Tag.used_tags(user.id), "recent_active_months" : blog.last_active_months(), "archive_qualifier": "/%s" % user.username}) # Substitute gallery links: def gallery_link(match): gallery = get_object_or_404(Gallery, title_slug = match.group("gallery_slug")) context = RequestContext(request, dict = {"gallery": gallery, "caption": match.group("caption") or gallery.description}) return loader.render_to_string("gallery_fragment.html", None, context) data["html_teaser"] = GALLERY_MATCHER.sub(gallery_link, data["article"].html_teaser) data["html_text"] = GALLERY_MATCHER.sub(gallery_link, data["article"].html) # Substitute photo links: def photo_link(match): photo = get_object_or_404(Photo, title_slug = match.group("photo_slug")) size = match.group("size") or "display" url = photo.__getattribute__("get_standalone_%s_url" % size)() context = RequestContext(request, dict = {"photo": photo, "url": url, "size": size, "caption": match.group("caption") or photo.caption}) return loader.render_to_string("photo_fragment.html", None, context) data["html_teaser"] = PHOTO_MATCHER.sub(photo_link, data["html_teaser"]) data["html_text"] = PHOTO_MATCHER.sub(photo_link, data["html_text"]) # Substitute youtube links: def youtube_link(match): youtube_id = match.group("youtube_id") context = RequestContext(request, dict = {"youtube_id": youtube_id}) return loader.render_to_string("youtube_fragment.html", None, context) data["html_teaser"] = YOUTUBE_MATCHER.sub(youtube_link, data["html_teaser"]) data["html_text"] = YOUTUBE_MATCHER.sub(youtube_link, data["html_text"]) return render("blog_article.html", request, data)
def about(request, author): user = User.objects.get( username = author ) return render("blog_about.html", request, data_for_selected_blog(request, user))
def images_new(request): """Show gallery upload form.""" return render("meta_manage_images.html", request, data_for_management(request))
def start(request): """Display the start / overview page.""" return render("meta_blogs.html", request, data_for_all(request))
def galleries(request): """List galleries.""" return render("meta_manage_galleries.html", request, data_for_management(request))
def logout(request): """Log out the current user.""" auth.logout(request) return render("meta_logout.html", request, data_for_all(request))
def login_failed(request): """Re-display the login form, inform the user about the failure.""" data = data_for_all(request) data.update({"login_failed": True, "show_login_form": True}) return render("meta_blogs.html", request, data)
def login(request): """Authenticate and log-in a user.""" data = data_for_all(request) data.update({"show_login_form": True}) return render("meta_blogs.html", request, data)
def images_submit(request): """Try to upload a new gallery.""" return render("meta_manage_images.html", request, data_for_management(request))
def imprint(request): return render("meta_imprint.html", request, data_for_all(request))
def contact(request): return render("meta_contact.html", request, data_for_all(request))
def galleries_new(request): """Show gallery upload form.""" data = data_for_management(request) data.update({"show_new_gallery_form": True}) return render("meta_manage_galleries.html", request, data)
def about(request): return render("meta_about.html", request, data_for_all(request))
def images(request): """List individual images.""" return render("meta_manage_images.html", request, data_for_management(request))