コード例 #1
0
ファイル: user.py プロジェクト: matoous/newz
    def links(self):
        """
        Users posted links
        :return: links
        """
        from news.models.link import Link

        return Link.where("user_id", self.id).get()
コード例 #2
0
ファイル: archive_links.py プロジェクト: matoous/newz
def archive_links():
    old_links = (
        Link.where("archived", False)
        .where_raw("created_at < NOW() - INTERVAL '30 days'")
        .get()
    )
    for link in old_links:
        link.archive()
コード例 #3
0
ファイル: query.py プロジェクト: matoous/newz
    def _rebuild(self):
        """
        Rebuild link query from database
        """
        from news.models.link import Link

        q = (Link.where("feed_id", self.feed_id).order_by_raw(
            sorts[self.sort]).limit(1000))

        # cache needs array of objects, not a orator collection
        res = [self._tupler(l) for l in q.get()]
        self._data = sort_tuples(res)
        self._fetched = True
        self._save()
コード例 #4
0
def users_profile(username):
    user = User.by_username(username)
    if user is None:
        abort(404)
    if user.id == 12345:
        return render_template("autoposter_profile.html", user=user)
    links = (Link.where(
        "user_id", user.id).order_by_raw("ups - downs DESC").limit(9).get())
    comments = (Comment.where(
        "user_id", user.id).order_by_raw("ups - downs DESC").limit(6).get())
    administrations = FeedAdmin.by_user_id(user.id)
    return render_template(
        "profile.html",
        user=user,
        links=links[:min(len(links), 8)],
        has_more_links=len(links) > 8,
        comments=comments[:min(len(comments), 5)],
        has_more_comments=len(comments) > 5,
        administrations=administrations,
        active_section="about",
    )