def show_blog_or_workshop( request, blog_slug ): b = get_object_or_404(Blog, slug=blog_slug) posts = b.post_set.filter(draft=0) #------------ Get List of flags in blog --------- flags = Flag.objects.filter( post__blog = b.id ).filter( blog__post__draft = 0 ).distinct() #------------ If a specific flag was requested, then show only that flag ------- if( request.method == 'GET' and request.GET.has_key('flag') ): flagId = int(request.GET['flag']) posts = posts.filter( flags__id = flagId ) #------------ Create Objects for Hebrew Calender ---- calLinkType = FRONTPAGE_URL_TYPE calLinkTemplate = CALENDAR_URL_TYPE_REGISTRY[calLinkType] dateToShow = date.today() bgColorProcessor = makeHebBGColorProcessor( dateToShow ) dayLinks = makeHebCalLinks( '/?date=%s', date.today() ) calender = makeHebCalRequestContext(dayLinks, engDate=date.today(), urlType=calLinkType, highlightToday=True) render_dict = add_render_variables({ 'blog': b, 'flags': flags }, obj=b) if b.is_workshop(): for p in posts: p.make_sure_workshop_exists() #------------- Takes care of workshops -------- no_events = posts.filter(workshop__workshopevent=None) now = datetime.datetime.now() start_of_today = datetime.datetime(now.year, now.month, now.day) _have_events = posts.filter( workshop__workshopevent__workshopeventpart__start_time__gte=start_of_today ).order_by('workshop__workshopevent__workshopeventpart__start_time') temp_set = set() have_events = [] for p in _have_events: if p not in temp_set: have_events.append(p) temp_set.add(p) if settings.SHOW_WORKSHOPS_WITH_NO_EVENTS: posts = itertools.chain(have_events, no_events) else: posts = have_events render_dict['post_list'] = posts # don't show no_events for now return render_to_response('cityblog/blog_workshops.html', render_dict, context_instance = RequestContext(request, {}, [calender, bgColorProcessor]) ) else: #------------ Standard blog with normal, non workshop, posts -------- return generic_object_list( request, queryset=posts, template_object_name='post', template_name='cityblog/blog_posts.html', allow_empty=True, extra_context=render_dict, context_processors =[calender,bgColorProcessor], paginate_by=NUM_POSTS_PER_PAGE)
def blogdetail( request, blog_slug ): """ List the posts in a blog If it is a workshop blog, the list is slightly different, and the button allows creating of new workshop, not new post. """ user_blogs = Blog.objects.filter( authors=request.user.id) theBlog = get_object_or_404( Blog, slug=blog_slug ) blogPosts = theBlog.post_set.filter(author=request.user.id) #make sure user can only see their own posts theMessage = None if( not blogPosts ): theMessage = NO_BLOG_POSTS_MESSAGE elif( request.method == 'GET' and request.GET.has_key('del') ): theMessage = BLOG_POST_DELETED return generic_object_list( request, queryset=blogPosts, template_name='desk/display_list_of_blog_posts.html', allow_empty=True, extra_context={'blog':theBlog, 'user_blogs': user_blogs, 'message' : theMessage, 'section' : MAIN_SECTION , }, paginate_by=NUM_POSTS_PER_PAGE)
def main_page(request): # ------------ Create Objects for Hebrew Calender ---- calLinkType = FRONTPAGE_URL_TYPE calLinkTemplate = CALENDAR_URL_TYPE_REGISTRY[calLinkType] dateToShow = date.today() bgColorProcessor = makeHebBGColorProcessor(dateToShow) dayLinks = makeHebCalLinks("/?date=%s", date.today()) calender = makeHebCalRequestContext(dayLinks, engDate=date.today(), urlType=calLinkType, highlightToday=True) return generic_object_list( request, queryset=Blog.objects.all(), template_object_name="blog", template_name="feeds_main_page.html", context_processors=[calender, bgColorProcessor], allow_empty=True, )
def subject_view( request, subject_slug ): theSubject = get_object_or_404(Subject, slug=subject_slug) flags = theSubject.flags.all() cat_ids = [ cat.id for cat in flags ] thePosts = Post.objects.filter( draft=0, flags__in = cat_ids ) frontpage = FrontPage.objects.filter(draft=False).latest() return generic_object_list( request, queryset=thePosts, template_object_name='post', template_name='cityblog/subject_view.html', allow_empty=True, extra_context=add_render_variables( { 'theSubject' : theSubject, 'frontpage' : frontpage }, obj=theSubject), context_processors =[], paginate_by=NUM_SUBJECTS_PER_PAGE)
def object_list(request, *args, **kwargs): if not request.user.is_superuser: return HttpResponseRedirect('/gcm/login/?next=%s' % request.path) return generic_object_list(request, *args, **kwargs)