def archive_month_wrapper(request, **kwargs): kwargs["allow_empty"] = True month = datetime.date(*time.strptime(kwargs["month"], "%b")[:3]).month if first_entry_date.year < int(kwargs["year"]): return date_based.archive_month(request, **kwargs) if first_entry_date.month < month: return date_based.archive_month(request, **kwargs) if first_entry_date.month == month: kwargs["allow_empty"] = False return date_based.archive_month(request, **kwargs) raise Http404
def article_archive_month(request, year, month): kwargs = { 'queryset': Article.objects.published(), 'date_field': 'publish_at', 'month_format': '%m', } return date_based.archive_month(request, year=year, month=month, **kwargs)
def post_archive(request, year, month=None, day=None, **kwargs): queryset = Post.objects.published() if day is not None: return date_based.archive_day( request, year=year, month=month, day=day, date_field='pub_date', month_format = '%m', queryset=queryset, **kwargs ) elif month is not None: return date_based.archive_month( request, year=year, month=month, date_field='pub_date', month_format = '%m', queryset=queryset, **kwargs ) else: return date_based.archive_year( request, year=year, date_field='pub_date', queryset=queryset, make_object_list=True, **kwargs )
def post_archive(request, year, month=None, day=None, **kwargs): queryset = Post.objects.published() if day is not None: return date_based.archive_day(request, year=year, month=month, day=day, date_field='pub_date', month_format='%m', queryset=queryset, **kwargs) elif month is not None: return date_based.archive_month(request, year=year, month=month, date_field='pub_date', month_format='%m', queryset=queryset, **kwargs) else: return date_based.archive_year(request, year=year, date_field='pub_date', queryset=queryset, make_object_list=True, **kwargs)
def month_archive(request, year, month): return archive_month(request, year=year, month=month, date_field='date_posted', queryset=Post.objects.all(), extra_context=get_archives())
def article_list_month(request, *args, **kwargs): from django.views.generic.date_based import archive_month queryset = Article.objects.published() # filter(publish_date__year=year) title = u"article año %s %s" % (month_name(kwargs.get("month")), kwargs.get("year")) category = None if kwargs.get("category", None): category = kwargs.pop("category") queryset = queryset.filter(category__slug=category) title = title + " de " + Category.objects.get(slug=category).name extra_context = {"category": category, "title": title} kwargs.update( { "queryset": queryset, "date_field": "publish_date", "template_name": "articles/article_list.html", "template_object_name": "article", "allow_empty": True, "month_format": r"%m", "allow_future": True, "extra_context": extra_context, } ) return archive_month(request, *args, **kwargs)
def archives(self, request, year=None, month=None): objects = self.filter(request, self.objects(request)) current_month = date.today() month = month or str(current_month.month) year = year or str(current_month.year) then = date(int(year), int(month), 1) # I'm so witty. extra = {} back = month_diff(start_date, then) if back is 27: return render_to_404(request, "Ok, fine. Here's a 404. Happy?") if back is 46: return redirect("http://www.youtube.com/watch?v=oHg5SJYRHA0") if back in self.conversation: extra["message"] = self.conversation[back] if back > 63: return redirect("http://www.google.com/search?q=somewhere%20more%20interesting") processors = (self.processor, self.archive_processor) return archive_month( request, year, month, objects, "published", allow_empty=True, month_format="%m", template_name=self.model.archives_template(), context_processors=processors, extra_context=extra, )
def post_archive_month(request, year, month, **kwargs): return date_based.archive_month(request, year=year, month=month, date_field='publish', queryset=Post.objects.published(), **kwargs)
def article_archive_month(request, year, month): kwargs = { 'queryset': Article.objects.published(), 'date_field': 'publish_at', 'month_format': '%m', } return date_based.archive_month(request, year=year, month=month, **kwargs)
def category_archive_month(request, slug, year, month, **kwargs): """ View of entries published in a ``Category`` in a given month. This is a short wrapper around the generic ``date_baed.archive_month`` view, so all context variables populated by that view will be available here. One extra variable is added:: object The ``Category``. Additionally, any keyword arguments which are valid for ``date_based.archive_month`` will be accepted and passed to it, with these exceptions: * ``queryset`` will always be the ``QuerySet`` of live entries in the ``Category``. * ``date_field`` will always be 'pub_date'. * ``template_name`` will always be 'coltrane/category_archive_month.html'. Template:: coltrane/category_archive_month.html """ category = get_object_or_404(Category, slug__exact=slug) kwarg_dict = _category_kwarg_helper(category, kwargs) return date_based.archive_month(request, year=year, month=month, queryset=category.live_entry_set, date_field='pub_date', template_name='coltrane/category_archive_month.html', **kwarg_dict)
def tumble_archive_month(request, year, month, content_type=None, template_name=None, **kwargs): queryset = TumbleItem.objects.all() if content_type: queryset = queryset.filter(content_type__name=content_type) select_template_name = select_template([ template_name or '', 'djumblr/%s_archive_month.html' % (content_type), 'djumblr/tumbleitem_archive_month.html', 'djumblr/tumbleitem_list.html', ]) template_name = select_template_name.name if 'extra_context' not in kwargs: kwargs['extra_context'] = {} kwargs['extra_context']['content_type'] = content_type return date_based.archive_month( request, year = year, month = month, date_field = 'pub_date', queryset = queryset, template_name = template_name, **kwargs )
def month(request, slug, y, m): posts_blog = Blog.objects.get(slug=slug) queryset = Post.objects.get_visible().filter(blog__slug=slug) return date_based.archive_month(request, y, m, queryset, date_field="publish_at", month_format="%m", extra_context={ 'blog': posts_blog })
def article_list_month(request, *args, **kwargs): from django.views.generic.date_based import archive_month queryset = Article.objects.published() # filter(publish_date__year=year) title = u'article año %s %s' % (month_name(kwargs.get('month')), kwargs.get('year')) category = None if kwargs.get('category', None): category = kwargs.pop('category') queryset = queryset.filter(category__slug=category) title = title + ' de ' + Category.objects.get(slug=category).name extra_context = { 'category' : category, 'title' : title, } kwargs.update({ 'queryset' : queryset, 'date_field' : 'publish_date', 'template_name' : 'articles/article_list.html', 'template_object_name' : 'article', 'allow_empty' : True, 'month_format' : r'%m', 'allow_future' : True, 'extra_context' : extra_context, }) return archive_month(request, *args, **kwargs)
def article_list_month(request, *args, **kwargs): from django.views.generic.date_based import archive_month queryset = Article.objects.published() # filter(publish_date__year=year) title = u'article año %s %s' % (month_name(kwargs.get('month')), kwargs.get('year')) category = None if kwargs.get('category', None): category = kwargs.pop('category') queryset = queryset.filter(category__slug=category) title = title + ' de ' + Category.objects.get(slug=category).name extra_context = { 'category' : category, 'title' : title, } kwargs.update({ 'queryset' : queryset, 'date_field' : 'publish_date', 'template_name' : 'articles/article_list.html', 'template_object_name' : 'article', 'allow_empty' : True, 'month_format' : r'%m', 'allow_future' : True, 'extra_context' : extra_context, }) return archive_month(request, *args, **kwargs)
def friends_archive_month(request, year, month): """ Post archive month Templates: ``friends/index.html`` Context: month: (date) this month next_month: (date) the first day of the next month, or None if the next month is in the future previous_month: (date) the first day of the previous month object_list: list of objects published in the given month """ return date_based.archive_month( request, year=year, month=month, month_format='%m', date_field='posted', queryset=FriendPost.objects.active(), template_name='friends/index.html' )
def custom_archive_month (request, year, month, queryset, date_field, **kwargs): # Local list for calculated info. Will be added to 'extra_context'. context = {} # We need to start with a new "queryset" to do tag-based filter. # So, any previous selection on the queryset will be lost. if kwargs.has_key('tags'): # Handling tags: preserve in context and filter objects. tags = kwargs.pop('tags') context['tags'] = tags requested_tag = Tag.objects.filter(name=tags) queryset = TaggedItem.objects.get_by_model (Event, requested_tag) else: context['tags'] = None if kwargs.has_key('category'): # Handling categories: preserve in context and filter objects. categ = kwargs.pop('category') context['category'] = categ queryset = queryset.filter(category__easyname=categ) else: context['category'] = None context['previous_month_url'], context['next_month_url'] = _month_nav_urls (request) context['categories_list'] = _make_categories_list(request) # Insert 'context' in 'extra_context'. if kwargs.has_key('extra_context'): kwargs['extra_context'].update(context) else: kwargs['extra_context'] = context # Finaly use the good old generic view. return archive_month(request, year, month, queryset, date_field, **kwargs)
def blog_archive_month(request, **kwargs): blog_slug = kwargs.pop('blog_slug') kwargs['queryset'] = kwargs['queryset'].published().filter( blog__slug=blog_slug) set_language_changer(request, language_changer) return archive_month(request, extra_context={ 'blog_slug': blog_slug }, **kwargs)
def archives(request, tags, year=None, month=None): current_month = date.today().replace(day=1) month = str(current_month.month) if month is None else month year = str(current_month.year) if year is None else year then = date(int(year), int(month), 1) extra = dict(model=Entry, tags=tags, qualifier='?tags=%s' % ','.join(tags) if tags else '', first_month=date(start.year, start.month, 1), latest_month=current_month if then < current_month else None) # I'm so witty. back = months_back(then) if back is 27: raise Http404("Ok, fine. Here's a 404. Happy?") if back in conversation: extra['message'] = conversation[back] if back > 52: return redirect('http://www.google.com/search?q=Something%20more%20interesting') if request.user.is_staff: entries = Entry.all_objects.tagged_with(tags) else: entries = Entry.objects.tagged_with(tags) return archive_month(request, year, month, entries, 'created', template_name='writing/archives.html', allow_empty=True, month_format='%m', extra_context=extra)
def archive_month(self, request, year, month, extra_context=None): queryset = self.get_queryset(request) extra_context = extra_context or {} extra_context.update({ 'configuration': self }) return archive_month(request, year, month, queryset, 'pub_date', template_object_name=self.template_object_name, extra_context=extra_context, template_name=self.archive_month_template_name)
def bookmark_archive_month(request, year, month): return date_based.archive_month( request, year=year, month=month, date_field='created', queryset=Bookmark.objects.all(), )
def article_archive_month(request, year, month): return date_based.archive_month( request, year=year, month=month, date_field='release_date', queryset=models.Article.objects.get_published(), )
def archive_month(request, year, month): return date_based.archive_month(request, queryset=Post.objects.published(), date_field='post_date', year=year, month=month, month_format="%m", template_object_name='post')
def entry_archive_month(request, *args, **kwargs): """ A thin wrapper around ``django.views.generic.date_based.archive_month``. """ kwargs['date_field'] = 'pub_date' if 'queryset' not in kwargs: kwargs['queryset'] = Entry.published_on_site.all() return date_based.archive_month(request, *args, **kwargs)
def post_archive_month(request, year, month): return date_based.archive_month( request, year = year, month = month, date_field = 'publish', queryset = Post.objects.published(), )
def archive_month(request, year, month): """ Return the articles posted that month """ return date_based.archive_month(request, year=year, month=month, date_field='published_at', template_object_name='article', queryset=Article.publish.all())
def archive_month(request, year, month): if int(year) < 1901: # to exclude all troubles with strftime raise Http404 qs = Post.objects.filter(site=Site.objects.get_current()) return date_based.archive_month(request, year, month, queryset=qs, month_format='%m', template_name='blog/post_list.html', **archive_dict)
def blog_archive_month(request, **kwargs): blog_slug = kwargs.pop('blog_slug') kwargs['queryset'] = kwargs['queryset'].published().filter( blog__slug=blog_slug) set_language_changer(request, language_changer) return archive_month(request, extra_context={'blog_slug': blog_slug}, **kwargs)
def bookmark_archive_month(request, year, month): return date_based.archive_month( request, year=year, month=month, date_field='created', queryset=Bookmark.objects.published(), )
def blog_archive_month(request, blog_slug, year, month): blog = get_object_or_404(Blog, slug=blog_slug) return date_based.archive_month(request, year=year, month=month, queryset=blog.entry_set.all(), date_field='pub_date', extra_context = {'blog': blog}, template_name = blog.template_name_date_archive or 'blogs/entry_archive_month.html')
def blog_archive_month(request, year, month, **kwargs): return date_based.archive_month( request, year=year, month=month, date_field='pub_date', month_format="%m", queryset=Entry.objects.published_for_list(), **kwargs)
def event_archive_month(request, year, month): return date_based.archive_month( request, year=year, month=month, date_field='start', queryset=EventTime.objects.all(), allow_future=True, )
def post_archive_month(request, year, month, edition=None, category=None, code=None, project_slug=None, **kwargs): if project_slug: project = get_object_or_404(Project, slug=project_slug) else: project = get_object_or_404(Project, edition=edition, category=category, code=code) return date_based.archive_month( request, year=year, month=month, date_field="publish", queryset=Post.objects.published(project), **kwargs )
def event_archive_month(request, year, month): return date_based.archive_month( request, year=year, month=month, date_field='start', queryset=EventTime.objects.all(), allow_future=True, )
def bookmark_archive_month(request, year, month): return date_based.archive_month( request, year=year, month=month, date_field="save_date", template_object_name="bookmark", queryset=Bookmark.shared_objects.all(), )
def archive_month(request, year, month): return date_based.archive_month( request, queryset=Post.objects.published().select_related(), date_field='date_published', year=year, month=month, month_format="%m", template_object_name='post', allow_empty=True)
def blog_archive_month(request, year, month): return date_based.archive_month( request, queryset=Post.objects.published(), date_field='published', allow_empty=False, year=year, month=month, template_object_name='post', extra_context=extra_context())
def entry_archive_month(request, year, month, **kwargs): return date_based.archive_month( request, year=year, month=month, date_field="pub_date", month_format="%m", queryset=Entry.objects.published(), **kwargs )
def monthly_view(request, year, month): queryset = BlogEntry.objects.filter(is_page=False, is_published=True) return archive_month(request=request, template_name='blogango/archive_view.html', year=year, month=month, queryset=queryset, date_field='created_on', allow_empty=True, extra_context=_get_sidebar_objects(request))
def post_archive_month(request, year, month, **kwargs): return date_based.archive_month( request, year = year, month = month, month_format='%m', date_field = 'publish', queryset = Post.objects.published(), **kwargs )
def article_archive_month(request, year, month, **kwargs): return date_based.archive_month( request, year = year, month = month, month_format='%m', date_field = 'pub_date', queryset = Article.objects.published(), **kwargs )
def monthly_view(request, year, month): # print year, month queryset = BlogEntry.objects.filter(is_page=False, is_published=True) return archive_month(request=request, template_name='blogango/archive_view.html', year=year, month=month, queryset=queryset, date_field='created_on', extra_context=_get_sidebar_objects(request))
def archive_month(request, year, month): return date_based.archive_month( request, queryset=Post.objects.published().select_related(), date_field='date_published', year=year, month=month, month_format="%m", template_name='post_archive_month.html', template_object_name='post', allow_empty=False)
def calendar_view(self, request, field, year=None, month=None, day=None): easy_model = EasyModel(self.site, self.model) extra_context = { 'root_url': self.site.root_url, 'model': easy_model, 'field': field } if day is not None: # TODO: The objects in this template should be EasyInstances return date_based.archive_day( request, year, month, day, self.model.objects.all(), field.name, template_name='databrowse/calendar_day.html', allow_empty=False, allow_future=True, extra_context=extra_context) elif month is not None: return date_based.archive_month( request, year, month, self.model.objects.all(), field.name, template_name='databrowse/calendar_month.html', allow_empty=False, allow_future=True, extra_context=extra_context) elif year is not None: return date_based.archive_year( request, year, self.model.objects.all(), field.name, template_name='databrowse/calendar_year.html', allow_empty=False, allow_future=True, extra_context=extra_context) else: return date_based.archive_index( request, self.model.objects.all(), field.name, template_name='databrowse/calendar_main.html', allow_empty=True, allow_future=True, extra_context=extra_context) assert False, ('%s, %s, %s, %s' % (field, year, month, day))
def calendar_view(self, request, field, year=None, month=None, day=None): easy_model = EasyModel(self.site, self.model) queryset = easy_model.get_query_set() extra_context = { 'root_url': self.site.root_url, 'model': easy_model, 'field': field } if day is not None: return date_based.archive_day( request, year, month, day, queryset, field.name, template_name='databrowse/calendar_day.html', allow_empty=False, allow_future=True, extra_context=extra_context) elif month is not None: return date_based.archive_month( request, year, month, queryset, field.name, template_name='databrowse/calendar_month.html', allow_empty=False, allow_future=True, extra_context=extra_context) elif year is not None: return date_based.archive_year( request, year, queryset, field.name, template_name='databrowse/calendar_year.html', allow_empty=False, allow_future=True, extra_context=extra_context) else: return date_based.archive_index( request, queryset, field.name, template_name='databrowse/calendar_main.html', allow_empty=True, allow_future=True, extra_context=extra_context) assert False, ('%s, %s, %s, %s' % (field, year, month, day))
def blog_date(request, blog_slug=None, year=None, month=None, day=None): """ Shows all of a blog's entries for a given day, month or year using the appropriate generic view. """ blog = Blog.objects.get(slug=blog_slug) entries = Entry.get_published.filter(blog=blog) if day: date_string = format(date(int(year), int(month), int(day)), "N j, Y") archive_name = "Posts to %s on %s" % (blog, date_string) return archive_day(request, year, month, day, entries, 'pub_date', month_format='%m', extra_context={ 'blog': blog, 'archive_name': archive_name }, allow_empty=True, template_name='blogs/entry_archive.html') elif month: date_string = format(date(int(year), int(month), 1), "F Y") archive_name = "Posts to %s in %s" % (blog, date_string) return archive_month(request, year, month, entries, 'pub_date', month_format='%m', extra_context={ 'blog': blog, 'archive_name': archive_name }, allow_empty=True, template_name='blogs/entry_archive.html') elif year: archive_name = "Months in %s with posts to %s" % (year, blog) return archive_year(request, year, entries, 'pub_date', extra_context={ 'blog': blog, 'archive_name': archive_name }, allow_empty=True, template_name='blogs/entry_archive.html')
def post_archive_month(request, year, month, template_name='nadb/post_archive_month.html', extra_context=None, **kwargs): """ Display a list of published blog posts in a given month. **Template:** nadb/post_archive_month.html or ``template_name`` keyword argument. **Template context:** In addition to extra_context, the template's context will be: ``date_list`` A DateQuerySet object containing all days that have have objects available in the given month, represented as datetime.datetime objects, in ascending order. ``month`` A datetime.date object representing the given month. ``next_month`` A datetime.date object representing the first day of the next month. If the next month is in the future, this will be None. ``previous_month`` A datetime.date object representing the first day of the previous month. Unlike next_month, this will never be None. ``object_list`` A list of objects available for the given month. """ return date_based.archive_month( request, year=year, month=month, date_field='published', queryset=Post.objects.published(), template_name=template_name, extra_context=extra_context, **kwargs )
def archive_month(request, year, month): """ Listing of all events in a given month. Template: events/event_archive_month.html Context: event_list previous_month next_month month """ return date_based.archive_month(request, year=year, month=month, queryset=Event.objects.all(), date_field='start_date', month_format='%m', allow_future=True, template_object_name='event')
def event_month(request, year=None, month=None, **kwargs): """Displays the list of calendar for the given month. """ current_day = _current_day(year, month) previous_month = current_day - datetime.timedelta(days=30) next_month = current_day + datetime.timedelta(days=30) return archive_month(request, year=year, month=month, queryset=Event.objects.for_user(request.user), date_field="start", month_format="%m", allow_empty=True, allow_future=True, template_name="calendar/event_month.html", extra_context={ 'previous_year': previous_month, 'next_year': next_month, 'current_day': current_day }, **kwargs)
def post_archive_month(request, year, month): """ Post archive month Templates: ``nebula/post_archive_month.html`` Context: month: (date) this month next_month: (date) the first day of the next month, or None if the next month is in the future previous_month: (date) the first day of the previous month object_list: list of objects published in the given month """ return date_based.archive_month( request, year = year, month = month, date_field = 'posted', queryset = AggregatedPost.objects.active(), )
def friends_archive_month(request, year, month): """ Post archive month Templates: ``friends/index.html`` Context: month: (date) this month next_month: (date) the first day of the next month, or None if the next month is in the future previous_month: (date) the first day of the previous month object_list: list of objects published in the given month """ return date_based.archive_month(request, year=year, month=month, month_format='%m', date_field='posted', queryset=FriendPost.objects.active(), template_name='friends/index.html')
def archive_month(request, *args, **kwargs): return date_based.archive_month(request, *args, **kwargs)
def blog_archive_month(request, **kwargs): kwargs['queryset'] = kwargs['queryset'].published() set_language_changer(request, language_changer) return archive_month(request, **kwargs)
def blog_archive_month(request, **kwargs): kwargs['queryset'] = kwargs['queryset'].published() return archive_month(request, **kwargs)