def user_profile(request, uid, tab='activity'): "User's profile page" if not models.User.objects.filter(id=uid): messages.error(request, "This user does not exist. It has perhaps been deleted.") return html.redirect("/") user = request.user target = models.User.objects.get(id=uid) awards = [] page = None # some information is only visible to the user target.writeable = auth.authorize_user_edit(target=target, user=user, strict=False) target.showall = (target == user) params = html.Params(tab=tab, sort='', title="User %s" % target.profile.display_name) # these do not actually get executed unless explicitly rendered in the page bookmarks = models.Vote.objects.filter(author=target, type=VOTE_BOOKMARK).select_related('post', 'post__author__profile').order_by('id') awards = models.Award.objects.filter(user=target).select_related('badge').order_by('-date') # we need to collate and count the awards answer_count = models.Post.objects.filter(author=target, type=POST_ANSWER).count() question_count = models.Post.objects.filter(author=target, type=POST_QUESTION).count() comment_count = models.Post.objects.filter(author=target, type=POST_COMMENT).count() post_count = models.Post.objects.filter(author=target).count() vote_count = models.Vote.objects.filter(author=target).count() award_count = models.Award.objects.filter(user=target).count() note_count = models.Note.objects.filter(target=target, unread=True).count() bookmarks_count = models.Vote.objects.filter(author=target, type=VOTE_BOOKMARK).count() if tab in [ 'activity', 'created' ]: if tab == 'created': notes = models.Note.objects.filter(sender=target, target=target, type=NOTE_USER).select_related('author', 'author__profile', 'root').order_by('-date') else: notes = models.Note.objects.filter(target=target, type=NOTE_USER).exclude(sender=target).select_related('author', 'author__profile', 'root').order_by('-date') page = get_page(request, notes, per_page=15) # we evalute it here so that subsequent status updates won't interfere page.object_list = list(page.object_list) if user == target: models.Note.objects.filter(target=target, unread=True).update(unread=False) models.UserProfile.objects.filter(user=target).update(new_messages=0) note_count = 0 elif tab == 'bookmarks': bookmarks = models.Vote.objects.filter(author=target, type=VOTE_BOOKMARK).select_related('post', 'post__author__profile').order_by('-date') page = get_page(request, bookmarks, per_page=15) elif tab =="moderator": notes = models.Note.objects.filter(target=target, type=NOTE_MODERATOR).select_related('author', 'author__profile').order_by('-date') page = get_page(request, notes, per_page=15) params.update(dict(question_count=question_count, answer_count=answer_count, note_count=note_count, bookmarks_count=bookmarks_count, comment_count=comment_count, post_count=post_count, vote_count=vote_count, award_count=award_count)) return html.template(request, name='user.profile.html', awards=awards, user=request.user,target=target, params=params, page=page)
def user_profile(request, uid, tab='activity'): "User's profile page" if not models.User.objects.filter(id=uid): messages.error(request, "This user does not exist. It has perhaps been deleted.") return html.redirect("/") user = request.user target = models.User.objects.get(id=uid) awards = [] page = None # some information is only visible to the user target.writeable = auth.authorize_user_edit(target=target, user=user, strict=False) target.showall = (target == user) params = html.Params(tab=tab, sort='') # these do not actually get executed unless explicitly rendered in the page bookmarks = models.Vote.objects.filter(author=target, type=VOTE_BOOKMARK).select_related('post', 'post__author__profile').order_by('id') awards = models.Award.objects.filter(user=target).select_related('badge').order_by('-date') # we need to collate and count the awards answer_count = models.Post.objects.filter(author=target, type=POST_ANSWER).count() question_count = models.Post.objects.filter(author=target, type=POST_QUESTION).count() comment_count = models.Post.objects.filter(author=target, type=POST_COMMENT).count() post_count = models.Post.objects.filter(author=target).count() vote_count = models.Vote.objects.filter(author=target).count() award_count = models.Award.objects.filter(user=target).count() note_count = models.Note.objects.filter(target=target, unread=True).count() bookmarks_count = models.Vote.objects.filter(author=target, type=VOTE_BOOKMARK).count() if tab == 'activity': notes = models.Note.objects.filter(target=target, type=NOTE_USER).select_related('author', 'author__profile', 'root').order_by('-date') page = get_page(request, notes, per_page=15) # we evalute it here so that subsequent status updates won't interfere page.object_list = list(page.object_list) if user==target: models.Note.objects.filter(target=target).update(unread=False) models.UserProfile.objects.filter(user=target).update(new_messages=0) note_count = 0 elif tab == 'bookmarks': bookmarks = models.Vote.objects.filter(author=target, type=VOTE_BOOKMARK).select_related('post', 'post__author__profile').order_by('-date') page = get_page(request, bookmarks, per_page=15) elif tab =="moderator": notes = models.Note.objects.filter(target=target, type=NOTE_MODERATOR).select_related('author', 'author__profile').order_by('-date') page = get_page(request, notes, per_page=15) params.update(dict(question_count=question_count, answer_count=answer_count, note_count=note_count, bookmarks_count=bookmarks_count, comment_count=comment_count, post_count=post_count, vote_count=vote_count, award_count=award_count)) return html.template(request, name='user.profile.html', awards=awards, user=request.user,target=target, params=params, page=page)
def main(request): "Main search" counts = request.session.get(SESSION_POST_COUNT, {}) q = request.GET.get('q', '') # query t = request.GET.get('t', 'all') # type params = html.Params(tab='search', q=q, sort='') subset = get_subset(t) if params.q: form = SearchForm(request.GET) res = search_results(request=request, text=params.q, subset=subset) size = len(res) messages.info( request, 'Searched results for: %s found %d results' % (params.q, size)) else: form = SearchForm() res = [] page = get_page(request, res, per_page=10) return html.template(request, name='search.html', page=page, params=params, counts=counts, form=form)
def show_user(request, uid, post_type=''): "Displays posts by a user" user = models.User.objects.filter( id=uid).select_related('profile').all()[0] params = html.Params(nav='', tab='user', sort='', title="Activity for user %s" % user.profile.display_name) # notification messages.info(request, 'Filtering by user: %s' % user.profile.display_name) post_type = POST_REV_MAP.get(post_type.lower()) if post_type: posts = get_post_manager(request).filter( type=post_type, author=user).order_by('-creation_date') else: posts = get_post_manager(request).filter( type__in=POST_TOPLEVEL, author=user).order_by('-creation_date') posts = posts.select_related('author', 'author__profile', 'root') page = get_page(request, posts, per_page=20) return html.template(request, name='index.html', page=page, params=params)
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)
def main(request): "Main search" counts = request.session.get(SESSION_POST_COUNT, {}) q = request.GET.get('q', '') # query t = request.GET.get('t', 'all') # type params = html.Params(tab='search', q=q, sort='', t=t) subset = get_subset(t) if params.q: form = SearchForm(request.GET) results = search_results(request=request, text=params.q, subset=subset) posts = Post.objects.filter(id__in=[row['pid'] for row in results]).exclude( status=POST_DELETED) for post, row in zip(posts, results): post.context = row['content'] #size = len(results) #messages.info(request, 'Searched results for: %s found %d results' % (params.q, size)) else: form = SearchForm() res = [] objects = [] page = get_page(request, posts, per_page=25) return html.template(request, name='search.html', page=page, params=params, counts=counts, form=form)
def question_unanswered(request, uid=0, post_type=None): "Lists all the questions" params = html.Params() params.setr('Filter: unanswered') qs = get_posts(request).filter(answer_count=0) page = get_page(request, qs) return html.template(request, name='post.list.html', page=page, params=params)
def badge_show(request, bid): "Shows users that have earned a certain badge" page = None badge = models.Badge.objects.get(id=bid) awards = models.Award.objects.filter(badge=badge).select_related('user', 'user_profile').order_by("-date") page = get_page(request, awards, per_page=24) return html.template(request, name='badge.show.html', page=page, badge=badge)
def user_profile(request, uid): "User's profile page" user = request.user target = models.User.objects.get(id=uid) if target == user: notes = models.Note.objects.filter(target=target).select_related('author', 'author__profile', 'root').order_by('-date') page = get_page(request, notes, per_page=10) # we evalute it here so that subsequent status updates won't interfere page.object_list = list(page.object_list) models.Note.objects.filter(target=target).update(unread=False) else: page = None # we need to collate and count the awards awards = models.Award.objects.filter(user=target).select_related('badge').order_by('-date') answer_count = models.Post.objects.filter(author=target, post_type=POST_ANSWER).count() question_count = models.Post.objects.filter(author=target, post_type=POST_QUESTION).count() comment_count = models.Post.objects.filter(author=target, post_type=POST_COMMENT).count() post_count = models.Post.objects.filter(author=target).count() vote_count = models.Vote.objects.filter(author=target).count() award_count = models.Award.objects.filter(user=target).count() params = html.Params(question_count=question_count, answer_count=answer_count, comment_count=comment_count, post_count=post_count, vote_count=vote_count, award_count=award_count) # it the target personal information writable target.editable = target.profile.editable(user) target.authorized = target.profile.authorize(user) return html.template(request, name='user.profile.html', awards=awards, user=request.user,target=target, params=params, page=page)
def more(request, pid): counts = request.session.get(SESSION_POST_COUNT, {}) form = SearchForm() params = html.Params(tab='search', q="", sort='') res = more_like_this(request=request, pid=pid) page = get_page(request, res, per_page=10) return html.template(request, name='search.html', page=page, params=params, counts=counts, form=form)
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)
def main(request): "Main search" counts = request.session.get(SESSION_POST_COUNT, {}) q = request.GET.get('q','') # query t = request.GET.get('t','all') # type params = html.Params(tab='search', q=q, sort='', t=t) subset = get_subset(t) if params.q: form = SearchForm(request.GET) results = search_results(request=request, text=params.q, subset=subset) posts = Post.objects.filter(id__in=[row['pid'] for row in results]).exclude(status=POST_DELETED) for post, row in zip(posts, results): post.context = row['content'] #size = len(results) #messages.info(request, 'Searched results for: %s found %d results' % (params.q, size)) else: form = SearchForm() res = [] objects = [] page = get_page(request, posts, per_page=25) return html.template(request, name='search.html', page=page, params=params, counts=counts, form=form)
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)
def user_list(request): search = request.GET.get('m','')[:80] # trim for sanity if search: query = Q(profile__display_name__icontains=search) users = models.User.objects.filter(query).select_related('profile').order_by("-profile__score") else: users = models.User.objects.select_related('profile').order_by("-profile__score") page = get_page(request, users, per_page=24) return html.template(request, name='user.list.html', page=page)
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)
def more(request, pid): counts = request.session.get(SESSION_POST_COUNT, {}) form = SearchForm() params = html.Params(tab='search', q="", sort='') results = more_like_this(request=request, pid=pid) posts = Post.objects.filter(id__in=[row['pid'] for row in results]).exclude(status=POST_DELETED) for post, row in zip(posts, results): post.context = row['content'] page = get_page(request, posts, per_page=10) return html.template(request, name='search.html', page=page, params=params, counts=counts, form=form)
def user_list(request): search = request.GET.get('m','')[:80] # trim for sanity params = html.Params(nav='users', sort='') if search: query = Q(profile__display_name__icontains=search) else: query = Q(id__gt=0) users = models.User.objects.filter(query).select_related('profile').order_by("-profile__score") page = get_page(request, users, per_page=24) return html.template(request, name='user.list.html', page=page, params=params)
def user_list(request): search = request.GET.get('m','')[:80] # trim for sanity params = html.Params(nav='users', sort='') if search: query = Q(profile__display_name__icontains=search) else: query = Q(id__gt=0) users = models.User.objects.filter(query).select_related('profile').order_by("-profile__score", "id") page = get_page(request, users, per_page=24) return html.template(request, name='user.list.html', page=page, params=params)
def post_list(request, uid=0, post_type=None): params = html.Params() posts = get_posts(request, post_type=post_type) if uid: user = models.User.objects.filter(id=uid).select_related('profile').all()[0] posts = posts.filter(author=user) params.setr('Filter: %s' % user.profile.display_name) posts = posts.order_by('-lastedit_date') page = get_page(request, posts, per_page=20) return html.template( request, name='post.list.html', page=page, params=params)
def tag_list(request): # remove null tags models.Tag.objects.all().filter(count=0).delete() search = request.GET.get('m','')[:80] # trim for sanity if search: query = Q(name__icontains=search) else: query = Q(id__gt=0) tags = models.Tag.objects.filter(query).order_by('-count') page = get_page(request, tags, per_page=152) params = html.Params(nav='tags', sort='') return html.template(request, name='tag.list.html', page=page, params=params)
def tag_list(request): # remove null tags models.Tag.objects.all().filter(count=0).delete() search = request.GET.get('m','')[:80] # trim for sanity if search: query = Q(name__icontains=search) else: query = Q(id__gt=0) tags = models.Tag.objects.filter(query).order_by('name') page = get_page(request, tags, per_page=152) params = html.Params(nav='tags', sort='') return html.template(request, name='tag.list.html', page=page, params=params)
def show_user(request, uid, post_type=''): "Displays posts by a user" user = models.User.objects.filter(id=uid).select_related('profile').all()[0] params = html.Params(nav='', tab='user', sort='') # notification messages.info(request, 'Filtering by user: %s' % user.profile.display_name) post_type = POST_REV_MAP.get(post_type.lower()) if post_type: posts = get_post_manager(request).filter(type=post_type, author=user).order_by('-creation_date') else: posts = get_post_manager(request).filter(type__in=POST_TOPLEVEL, author=user).order_by('-creation_date') page = get_page(request, posts, per_page=20) return html.template( request, name='index.html', page=page, params=params)
def more(request, pid): counts = request.session.get(SESSION_POST_COUNT, {}) form = SearchForm() params = html.Params(tab='search', q="", sort='') results = more_like_this(request=request, pid=pid) posts = Post.objects.filter( id__in=[row['pid'] for row in results]).exclude(status=POST_DELETED) for post, row in zip(posts, results): post.context = row['content'] page = get_page(request, posts, per_page=10) return html.template(request, name='search.html', page=page, params=params, counts=counts, form=form)
def index(request): "Main page" # this will contain the query if it was sent query = request.REQUEST.get('q','') pids = action.search(query) params = html.Params() if query: params.remind = 'Searching for: %s' % query qs = get_posts(request, post_type=None) qs = qs.filter(id__in=pids) else: qs = get_posts(request) qs = qs.order_by('-touch_date') page = get_page(request, qs, per_page=20) return html.template( request, name='index.html', page=page, params=params)
def get_context_data(self, **kwargs): context = super(MessageView, self).get_context_data(**kwargs) user = self.request.user note_types = [NOTE_USER, NOTE_PRIVATE] q = Q(target=user, type__in=note_types) e = Q(sender=user, type=NOTE_USER) notes = models.Note.objects.filter(q).exclude(e) notes = notes.select_related('author', 'author__profile').order_by('-date') page = html.get_page(request=self.request, obj_list=notes, per_page=25) # evaluate the query here so that the unread status is kept page.object_list = list(page.object_list) # reset the counts models.Note.objects.filter(target=user, unread=True).update(unread=False) models.UserProfile.objects.filter(user=user).update(new_messages=0) sess = middleware.Session(self.request) counts = sess.get_counts("message_count") sess.save() # the params object will carry layout = settings.USER_PILL_BAR params = html.Params(tab="", pill="messages", sort='', since='', layout=layout, title="Your Messages") context['page'] = page context['params'] = params context['counts'] = counts return context
def main(request): "Main search" counts = request.session.get(SESSION_POST_COUNT, {}) q = request.GET.get('q','') # query t = request.GET.get('t','all') # type params = html.Params(tab='search', q=q, sort='') subset = get_subset(t) if params.q: form = SearchForm(request.GET) res = search_results(request=request, text=params.q, subset=subset) size = len(res) messages.info(request, 'Searched results for: %s found %d results' % (params.q, size)) else: form = SearchForm() res = [] page = get_page(request, res, per_page=10) return html.template(request, name='search.html', page=page, params=params, counts=counts, form=form)
def modlog_list(request): "Lists of all moderator actions" mods = models.Note.objects.filter(type=NOTE_MODERATOR).select_related('sender', 'target', 'post', 'sender_profile').order_by('-date') page = get_page(request, mods) return html.template(request, name='modlog.list.html', page=page)
def question_tagged(request, tag_name): params = html.Params() params.setr('Tag: %s' % tag_name) qs = get_posts(request).filter(tag_set__name=tag_name) page = get_page(request, qs) return html.template(request, name='post.list.html', page=page, params=params)
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)
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)
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() # parse the date request since = request.GET.get('since', DATE_FILTER[0]).lower() # 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 # this here needs to be reworked TODO if tab == "best": sort_type = "votes" since = request.GET.get('since', 'this week') messages.info(request, "Most <b>upvoted</b> active posts of <b>%s!</b>" % since) elif tab == "bookmarked": sort_type = "bookmark" since = request.GET.get('since', 'this month') messages.info(request, "Most <b>bookmarked</b> active posts of <b>%s!</b>" % since) elif tab == "myvotes": sort_type = "votes__date" messages.info(request, "Posts created by you that have received up-votes from other users") elif tab == "mybookmarks": sort_type = "votes__date" messages.info(request, "Your bookmarked posts") elif tab == "myposts": sort_type = "creation" messages.info(request, "Posts created by you") # 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') show_search = True 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, date_filter=DATE_FILTER, since=since, layout=layout, show_type=show_type, title="Bioinformatics Answers", show_search=show_search) # 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) # apply date filtering posts = filter_by_date(request=request, posts=posts, since=since) # reduce SQL query count by preselecting data that will be displayed posts = posts.select_related('author', 'author__profile', 'lastedit_user', 'lastedit_user__profile') # sticky is not active on recent and all pages sticky = (tab != 'recent') and (pill not in ('all', "best", "bookmarked")) # hackfix sticky = False if pill.startswith("my") else sticky # order may change if it is invalid search posts = apply_sort(request=request, posts=posts, order=sort_type, sticky=sticky) # get the counts for the session counts = sess.get_counts(post_type) page = get_page(request, posts, per_page=settings.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", galaxy="Galaxy on Biostar", bookmarked="Most bookmarked", ) params.title = title_map.get(pill) or title_map.get(tab, params.title) return html.template(request, name='index.html', page=page, params=params, counts=counts)
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() # parse the date request since = request.GET.get('since', DATE_FILTER[0]).lower() # 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 # this here needs to be reworked TODO if tab == "best": sort_type = "votes" since = request.GET.get('since', 'this week') messages.info(request, "Most <b>upvoted</b> active posts of <b>%s!</b>" % since) elif tab == "bookmarked": sort_type = "bookmark" since = request.GET.get('since', 'this month') messages.info( request, "Most <b>bookmarked</b> active posts of <b>%s!</b>" % since) elif tab == "myvotes": sort_type = "votes__date" messages.info( request, "Posts created by you that have received up-votes from other users" ) elif tab == "mybookmarks": sort_type = "votes__date" messages.info(request, "Your bookmarked posts") elif tab == "myposts": sort_type = "creation" messages.info(request, "Posts created by you") # 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') show_search = True 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, date_filter=DATE_FILTER, since=since, layout=layout, show_type=show_type, title="Bioinformatics Answers", show_search=show_search) # 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) # apply date filtering posts = filter_by_date(request=request, posts=posts, since=since) # reduce SQL query count by preselecting data that will be displayed posts = posts.select_related('author', 'author__profile', 'lastedit_user', 'lastedit_user__profile') # sticky is not active on recent and all pages sticky = (tab != 'recent') and (pill not in ('all', "best", "bookmarked")) # hackfix sticky = False if pill.startswith("my") else sticky # order may change if it is invalid search posts = apply_sort(request=request, posts=posts, order=sort_type, sticky=sticky) # get the counts for the session counts = sess.get_counts(post_type) page = get_page(request, posts, per_page=settings.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", galaxy="Galaxy on Biostar", bookmarked="Most bookmarked", ) params.title = title_map.get(pill) or title_map.get(tab, params.title) return html.template(request, name='index.html', page=page, params=params, counts=counts)
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)
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)
def tag_list(request): tags = models.Tag.objects.all().order_by('-count') page = get_page(request, tags, per_page=50) params = html.Params(nav='tags') return html.template(request, name='tag.list.html', page=page, params=params)