Example #1
0
def update(limit):
    blogs = models.Blog.objects.all()
    for blog in blogs:
        posts = models.Post.objects.filter(author=blog.author)
        seen = set(p.title for p in posts)
        fname = get_datapath(blog)
        try:
            print '*** reading %s, %s' % (blog.id, blog.url)
            now = datetime.datetime.now()
            models.UserProfile.objects.filter(user=blog.author).update(
                last_visited=now)
            doc = feedparser.parse(fname)

            ent = [e for e in doc.entries if title(e) not in seen]
            ent = ent[:limit]
            for r in ent:
                r.title = unicode_or_bust(r.title)
                r.title = r.title[:200]
                r.description = unicode_or_bust(r.description)
                if not r.title:
                    continue
                date = r.date_parsed
                date = datetime.datetime(date[0], date[1], date[2])
                content = html.sanitize(r.description)
                post = models.Post(title=title(r),
                                   url=r.link,
                                   author=blog.author,
                                   type=POST_BLOG,
                                   content=content,
                                   creation_date=date)
                post.save()
                print '*** added post %s' % post.title.encode(
                    "ascii", 'replace')
        except KeyError, exc:
            print '(!) error %s' % exc
Example #2
0
def update(limit):
    blogs = models.Blog.objects.all()
    for blog in blogs:
        posts = models.Post.objects.filter(author=blog.author)
        seen  = set( p.title for p in posts )
        fname = get_datapath(blog)
        try:
            print '*** reading %s, %s' % (blog.id, blog.url)
            now = datetime.datetime.now()
            models.UserProfile.objects.filter(user=blog.author).update(last_visited=now)
            doc = feedparser.parse(fname)
            
            ent = [ e for e in doc.entries if title(e) not in seen ]
            ent = ent[:limit]
            for r in ent:
                r.title = unicode_or_bust(r.title)
                r.description = unicode_or_bust(r.description)
                if not r.title:
                    continue;
                date = r.date_parsed
                date = datetime.datetime(date[0], date[1], date[2])
                content = html.sanitize(r.description)                
                post = models.Post(title=title(r), url=r.link, author=blog.author,  type=POST_BLOG, content=content, creation_date=date)
                post.save()
                print '*** added post %s' % post.title.encode("ascii", 'replace')
        except KeyError, exc:
            print '(!) error %s' % exc
Example #3
0
def private_message(request, uid):
    "General moderation function"
    user   = request.user
    target = models.User.objects.get(id=uid)

    # TODO allow users to opt out from getting messages

    # get the message from the body
    text  = request.POST.get("message","").strip()[:1500]
    text  = html.generate(text)
    text  = html.sanitize(text)
    if not text:
        messages.error(request, 'Empty message')
    else:
        content = "PM to %s: %s" % (notegen.userlink(target), text)
        models.send_note(target=user, content=content, sender=user, both=False, unread=False, type=NOTE_PRIVATE, url=user.profile.get_absolute_url() )

        content = "PM from %s: %s" % (notegen.userlink(user), text)
        models.send_note(target=target, content=content, sender=user, both=False, type=NOTE_PRIVATE, url=user.profile.get_absolute_url() )

        tasks.send_test_email()

        messages.info(request, 'Your private message to <b>%s</b> has been sent!' % target.profile.display_name)

    return html.redirect( target.profile.get_absolute_url() )
Example #4
0
def private_message(request, uid):
    "General moderation function"
    user   = request.user
    target = models.User.objects.get(id=uid)

    # TODO allow users to opt out from getting messages

    # get the message from the body
    text  = request.POST.get("message","").strip()[:1500]
    text  = html.generate(text)
    text  = html.sanitize(text)
    if not text:
        messages.error(request, 'Empty message')
    else:
        content = "PM to %s: %s" % (notegen.userlink(target), text)
        models.send_note(target=user, content=content, sender=user, both=False, unread=False, type=NOTE_PRIVATE, url=user.profile.get_absolute_url() )

        content = "PM from %s: %s" % (notegen.userlink(user), text)
        models.send_note(target=target, content=content, sender=user, both=False, type=NOTE_PRIVATE, url=user.profile.get_absolute_url() )

        messages.info(request, 'Your private message to <b>%s</b> has been sent!' % target.profile.display_name)

    return html.redirect( target.profile.get_absolute_url() )
Example #5
0
 def get_tag_names(self):
     "Returns the post's tag values as a list of tag names"
     tag_val = html.sanitize(self.tag_val)
     names = re.split("[ ,]+", tag_val)
     names = filter(None, names)
     return map(unicode, names)
Example #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)
Example #7
0
 def get_tag_names(self):
     "Returns the post's tag values as a list of tag names"
     tag_val = html.sanitize(self.tag_val)
     names = re.split('[ ,]+', tag_val)
     names = filter(None, names)
     return map(unicode, names)
Example #8
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()

    # 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)
Example #9
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)
Example #10
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()

    # 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)