Esempio n. 1
0
def index(request, tab='all'):
    user = request.user
    auth = user.is_authenticated()
    
    # asking for an invalid tab
    if tab not in VALID_TABS:
        msg = html.sanitize('Unknown content type "%s"' % tab)
        messages.error(request, msg)
        return html.redirect("/")
        
    # populate the session data
    sess = middleware.Session(request)
    
    # get the sort order
    sort_type = sess.sort_order()
    
    # set the last active tab
    sess.set_tab(tab)
    
    # get the numerical value for these posts
    post_type = POST_TYPE_MAP.get(tab, tab)
    
    # override the sort order if the content so requires
    sort_type = 'creation' if tab=='recent' else sort_type
        
    # 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
    show_type = post_type in ('all', 'recent')
    
    if tab in VALID_PILLS:
        tab, pill = "posts", tab
    else:
        tab, pill = tab, ""
    params  = html.Params(tab=tab, pill=pill, sort=sort_type, sort_choices=SORT_CHOICES, layout=layout, show_type=show_type, title="Bioinformatics Answers")
    
    # this will fill in the query (q) and the match (m)parameters
    params.parse(request)
    
    # returns the object manager that contains all or only visible posts
    posts = get_post_manager(request)
    
    # filter posts by type
    posts = filter_by_type(request=request, posts=posts, post_type=post_type)
        
    # sticky is not active on recent and all pages
    sticky = (tab != 'recent') and (pill != 'all')
    
    # order may change if it is invalid search
    posts = apply_sort(request=request, posts=posts, order=sort_type, sticky=sticky)
    
    # this is necessary because the planet posts require more attributes
    if tab == 'planet':
        models.decorate_posts(posts, request.user)
        
    # get the counts for the session
    counts = sess.get_counts(post_type)
    page = get_page(request, posts, per_page=POSTS_PER_PAGE)
    
    # save the session
    sess.save()
   
    # try to set a more informative title
    title_map = dict(
            questions="Bioinformatics Questions", unanswered="Unanswered Questions", tutorials="Bioinformatics Tutorials",
            jobs="Bioinformatics Jobs", videos="Bioinformatics Videos", news='Bioinformatics News', tools="Bioinformatics Tools",
            recent="Recent bioinformatics posts", planet="Bioinformatics Planet"
    )
    params.title = title_map.get(tab, params.title)
    
    return html.template(request, name='index.html', page=page, params=params, counts=counts)
Esempio n. 2
0
        counts = sess.get_counts()
    
    except models.Post.DoesNotExist, exc:
        messages.warning(request, 'The post that you are looking for does not exists. Perhaps it was deleted!')
        return html.redirect("/")
    
    # get all answers to the root
    children = models.Post.objects.filter(root=root).exclude(type=POST_COMMENT, id=root.id).select_related('author', 'author__profile').order_by('-accepted', '-score', 'creation_date')
    
    # comments need to be displayed by creation date
    comments = models.Post.objects.filter(root=root, type=POST_COMMENT).select_related('author', 'author__profile').order_by('creation_date')

    all = [ root ] + list(children) + list(comments)
    # add the various decorators
    
    models.decorate_posts(all, user)
    
    # may this user accept answers on this root
    accept_flag = (user == root.author)
    
    # these are all the answers
    answers = [ o for o in children if o.type == POST_ANSWER ]
    for a in answers:
        a.accept_flag = accept_flag
        
    # get all the comments
    tree = defaultdict(list)
    for comment in comments:  
        tree[comment.parent_id].append(comment)
   
    # generate the tag cloud
Esempio n. 3
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)
Esempio n. 4
0
        # update the views for the question
        models.update_post_views(post=root, request=request, hours=settings.POST_VIEW_RANK_GAIN)
    except models.Post.DoesNotExist, exc:
        messages.warning(request, 'The post that you are looking for does not exists. Perhaps it was deleted!')
        return html.redirect("/")
    
    # get all answers to the root
    children = models.Post.objects.filter(root=root).exclude(type=POST_COMMENT, id=root.id).select_related('author', 'author__profile').order_by('-accepted', '-score', 'creation_date')
    
    # comments need to be displayed by creation date
    comments = models.Post.objects.filter(root=root, type=POST_COMMENT).select_related('author', 'author__profile').order_by('creation_date')

    all = [ root ] + list(children) + list(comments)
    # add the various decorators
    
    models.decorate_posts(all, user)
    
    # may this user accept answers on this root
    accept_flag = (user == root.author)
    
    # these are all the answers
    answers = [ o for o in children if o.type == POST_ANSWER ]
    for a in answers:
        a.accept_flag = accept_flag
        
    # get all the comments
    tree = defaultdict(list)
    for comment in comments:  
        tree[comment.parent_id].append(comment)
   
    # generate the tag cloud
Esempio n. 5
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)
Esempio n. 6
0
def index(request, tab='all'):
    user = request.user
    auth = user.is_authenticated()

    # asking for an invalid tab
    if tab not in VALID_TABS:
        msg = html.sanitize('Unknown content type "%s"' % tab)
        messages.error(request, msg)
        return html.redirect("/")

    # populate the session data
    sess = middleware.Session(request)

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

    # set the last active tab
    sess.set_tab(tab)

    # get the numerical value for these posts
    post_type = POST_TYPE_MAP.get(tab, tab)

    # override the sort order if the content so requires
    sort_type = 'creation' if tab == 'recent' else sort_type

    # 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
    show_type = post_type in ('all', 'recent')

    if tab in VALID_PILLS:
        tab, pill = "posts", tab
    else:
        tab, pill = tab, ""
    params = html.Params(tab=tab,
                         pill=pill,
                         sort=sort_type,
                         sort_choices=SORT_CHOICES,
                         layout=layout,
                         show_type=show_type,
                         title="Bioinformatics Answers")

    # this will fill in the query (q) and the match (m)parameters
    params.parse(request)

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

    # filter posts by type
    posts = filter_by_type(request=request, posts=posts, post_type=post_type)

    # sticky is not active on recent and all pages
    sticky = (tab != 'recent') and (pill != 'all')

    # order may change if it is invalid search
    posts = apply_sort(request=request,
                       posts=posts,
                       order=sort_type,
                       sticky=sticky)

    # this is necessary because the planet posts require more attributes
    if tab == 'planet':
        models.decorate_posts(posts, request.user)

    # get the counts for the session
    counts = sess.get_counts(post_type)
    page = get_page(request, posts, per_page=POSTS_PER_PAGE)

    # save the session
    sess.save()

    # try to set a more informative title
    title_map = dict(questions="Bioinformatics Questions",
                     unanswered="Unanswered Questions",
                     tutorials="Bioinformatics Tutorials",
                     jobs="Bioinformatics Jobs",
                     videos="Bioinformatics Videos",
                     news='Bioinformatics News',
                     tools="Bioinformatics Tools",
                     recent="Recent bioinformatics posts",
                     planet="Bioinformatics Planet")
    params.title = title_map.get(tab, params.title)

    return html.template(request,
                         name='index.html',
                         page=page,
                         params=params,
                         counts=counts)