Example #1
0
def show_tag(request, tag_name=None):
    "Display posts by a certain tag"
    user = request.user
    # populate the session data
    sess = middleware.Session(request)

    # get the sort order
    sort_type = sess.sort_order()

    # select based on history
    tab, pill = "posts", sess.get_tab()

    params = html.Params(nav='', tab=tab, sort='')

    # the params object will carry
    layout = settings.USER_PILL_BAR if auth else settings.ANON_PILL_BAR

    # wether to show the type of the post
    params = html.Params(tab=tab,
                         pill=pill,
                         sort=sort_type,
                         sort_choices=SORT_CHOICES,
                         layout=layout,
                         title="Tagged as %s" % tag_name)

    msg = 'Filtering by tag: <b>%s</b>. Subscribe to an <a href="/feeds/tag/%s/">RSS feed</a> to this tag.' % (
        tag_name, tag_name)
    messages.info(request, msg)
    posts = models.query_by_tags(user=user, text=tag_name)
    posts = apply_sort(request=request, posts=posts, order=sort_type)
    page = get_page(request, posts, per_page=20)

    return html.template(request, name='index.html', page=page, params=params)
Example #2
0
def show_tag(request, tag_name=None):
    "Display posts by a certain tag"
    user = request.user
    # populate the session data
    sess = middleware.Session(request)
    
    # get the sort order
    sort_type = sess.sort_order()
    
    # select based on history
    tab, pill = "posts", sess.get_tab()
    
    params = html.Params(nav='', tab=tab, sort='' )
    
    # the params object will carry
    layout = settings.USER_PILL_BAR if auth else settings.ANON_PILL_BAR
    
    # wether to show the type of the post
    params  = html.Params(tab=tab, pill=pill, sort=sort_type, sort_choices=SORT_CHOICES, layout=layout, title="Tagged as %s" % tag_name)
    
    msg = 'Filtering by tag: <b>%s</b>. Subscribe to an <a href="/feeds/tag/%s/">RSS feed</a> to this tag.' % (tag_name,tag_name)
    messages.info(request, msg)
    posts = models.query_by_tags(user=user, text=tag_name)
    posts = apply_sort(request=request, posts=posts, order=sort_type)
    page  = get_page(request, posts, per_page=20)

    return html.template( request, name='index.html', page=page, params=params)
Example #3
0
def show_tag(request, tag_name=None):
    "Display posts by a certain tag"
    user = request.user
    params = html.Params(nav='', tab='tags')
    messages.warning(request, 'Filtering by tag: %s' % tag_name)
    posts = models.query_by_tags(user=user, text=tag_name).order_by('-rank')
    page  = get_page(request, posts, per_page=20)
    return html.template( request, name='index.html', page=page, params=params)
Example #4
0
def show_tag(request, tag_name=None):
    "Display posts by a certain tag"
    user = request.user
    params = html.Params(nav='', tab='tags', sort='')
    msg = 'Filtering by tag: <b>%s</b>. Subscribe to an <a href="/feeds/tag/%s/">RSS feed</a> to this tag.' % (tag_name,tag_name)
    messages.info(request, msg)
    posts = models.query_by_tags(user=user, text=tag_name).order_by('-rank')
    page  = get_page(request, posts, per_page=20)
    return html.template( request, name='index.html', page=page, params=params)
Example #5
0
def mytags_posts(request):
    "Gets posts that correspond to mytags settins or sets warnings"
    user = request.user
    if not user.is_authenticated():
        messages.warning(request, "This Tab is populated only for registered users based on the My Tags field in their user profile")
        text = ""
    else:
        text = request.user.profile.my_tags 
        if not text:
            messages.warning(request, "Showing posts matching the My Tags fields in your user profile. Currently this field is not set.")
            
    return models.query_by_tags(user, text=text)
Example #6
0
def mytags_posts(request):
    "Gets posts that correspond to mytags settins or sets warnings"
    user = request.user
    if not user.is_authenticated():
        messages.warning(request, "This Tab is populated only for registered users based on the My Tags field in their user profile")
        text = ""
    else:
        text = request.user.profile.my_tags 
        if not text:
            messages.warning(request, "Showing posts matching the My Tags fields in your user profile. Currently this field is not set.")
            
    return models.query_by_tags(user, text=text)
Example #7
0
 def items(self, obj):
     posts = models.query_by_tags(user=None,
                                  text=obj).order_by('-creation_date')
     return posts[:25]
Example #8
0
 def items(self, obj):
     text = obj.profile.my_tags
     posts = models.query_by_tags(user=obj,
                                  text=text).order_by('-creation_date')
     return posts[:15]
Example #9
0
 def items(self, obj):
     posts = models.query_by_tags(user=None, text=obj).order_by('-creation_date')
     return posts[:25]
Example #10
0
 def items(self, obj):
     text  = obj.profile.my_tags
     posts = models.query_by_tags(user=obj, text=text).order_by('-creation_date')
     return posts[:15]
Example #11
0
def index(request, tab=""):
    "Main page"
    
    user = request.user
    
    if not tab:
        # if the user has a mytags then switch to that
        if user.is_authenticated() and user.profile.my_tags:
            tab = 'mytags'
        else:
            tab = 'questions'
    
    if tab not in VALID_TABS:
        messages.error(request, 'Unknown content type requested')
        
    params = html.Params(tab=tab)
    
    # this will fill in the query (q) and the match (m)parameters
    params.parse(request)
    
    # update with counts
    counts = request.session.get(SESSION_POST_COUNT, {})

    # returns the object manager that contains all or only visible posts
    posts = get_post_manager(request)

    # filter posts by type
    posts = filter_by_type(posts=posts, value=tab)

    # sort selected in the dropdown. by default lists cannot be sorted
    sort = request.GET.get('sort', '').lower()
    
    # attempts to remeber the last sorting
    sort = get_last_sort(request, sort)
    
    # override sort in the recent tab
    if tab == 'recent':
        sort = 'creation'
        posts = posts.order_by('-creation_date')
    else:
        posts = apply_sort(posts, value=sort, request=request)
    
    if tab == 'planet':
        models.decorate_posts(posts, user)
    
    if tab == 'mytags':
        if user.is_authenticated():
            text  = user.profile.my_tags
            if not text:
                messages.warning(request, "This Tab will show posts matching the My Tags fields in your user profile.")
            else:
                messages.info(request, "Filtering by %s" % text)
            posts = models.query_by_tags(user,text=text)
            posts = apply_sort(posts, value=sort, request=request)
        else:
            messages.warning(request, "This Tab is populated only for registered users based on the My Tags field in their user profile")
            posts = []
    
    sort_choices = "rank,views,votes,answers,bookmarks,creation,edit".split(',')
    
    # put sort options in params so they can be displayed
    params.update(dict(sort=sort, sort_choices=sort_choices))
    
    # reset the counts
    update_counts(request, tab, 0)
    page = get_page(request, posts, per_page=POSTS_PER_PAGE)
    return html.template(request, name='index.html', page=page, params=params, counts=counts)
Example #12
0
def index(request, tab=""):
    "Main page"
    
    user = request.user
    
    if not tab:
        # if the user has a mytags then switch to that
        if user.is_authenticated() and user.profile.my_tags:
            tab = 'mytags'
        else:
            tab = 'questions'
    
    if tab not in VALID_TABS:
        messages.error(request, 'Unknown content type requested')
        
    params = html.Params(tab=tab)
    
    # this will fill in the query (q) and the match (m)parameters
    params.parse(request)
    
    # update with counts
    counts = request.session.get(SESSION_POST_COUNT, {})

    # returns the object manager that contains all or only visible posts
    posts = get_post_manager(request)
    
    # filter the posts by the tab that the user has selected
    if tab == "popular":
        posts = posts.filter(type=POST_QUESTION).order_by('-views')
    elif tab == "questions":
        posts = posts.filter(type=POST_QUESTION).order_by('-rank')
    elif tab == "unanswered":
        posts = posts.filter(type=POST_QUESTION, answer_count=0).order_by('-creation_date')
    elif tab == "recent":
        posts = posts.order_by('-creation_date')
    elif tab == 'planet':
        posts = posts.filter(type=POST_BLOG).order_by('-rank')
        models.decorate_posts(posts, user)
    elif tab == 'forum':
        posts = posts.filter(type__in=POST_FORUMLEVEL).order_by('-rank')
    elif tab == 'tutorials':
        posts = posts.filter(type=POST_TUTORIAL).order_by('-rank')
    elif tab == 'mytags':
        if user.is_authenticated():
            text  = user.profile.my_tags
            if not text:
                messages.warning(request, "This Tab will show posts matching the My Tags fields in your user profile.")
            else:
                messages.info(request, "Filtering by %s" % text)
            #posts = posts.filter(type__in=POST_TOPLEVEL,tag_set__name__in=tags).order_by('-rank')
            posts = models.query_by_tags(user,text=text)
            
        else:
            messages.warning(request, "This Tab is populated only for registered users based on the My Tags field in their user profile")
            posts = []
    else:
        posts = posts.order_by('-rank')
    
    # reset the counts
    update_counts(request, tab, 0)
    page = get_page(request, posts, per_page=20)
    return html.template(request, name='index.html', page=page, params=params, counts=counts)