Example #1
0
 def to_python(self, value: str) -> Optional[Link]:
     if value == "":
         abort(404)
     link = Link.by_id(value)
     if link is None:
         abort(404)
     return link
Example #2
0
File: vote.py Project: matoous/newz
    def link(self) -> "Link":
        """
        Return the link that was voted on
        :return: link
        """
        from news.models.link import Link

        if "link" not in self._relations:
            self._relations["link"] = Link.by_id(self.link_id)
        return self._relations["link"]
Example #3
0
    def link(self):
        """
        Get link to which this comments belongs
        :return: Parent Link of Comment
        """
        from news.models.link import Link

        if not "link" in self._relations:
            self._relations["link"] = Link.by_id(self.link_id)
        return self._relations["link"]
Example #4
0
    def thing(self):
        if "thing" not in self._relations:
            if self.reportable_type == "comments":
                from news.models.comment import Comment

                self._relations["thing"] = Comment.by_id(self.reportable_id)
            if self.reportable_type == "links":
                from news.models.link import Link

                self._relations["thing"] = Link.by_id(self.reportable_id)
        return self._relations["thing"]
Example #5
0
def remove_link(feed, link_id):
    """
    Removes link from given feed
    This is a hard delete, so be careful
    :param feed: feed
    :param link_slug: link slug
    :return:
    """
    link = Link.by_id(link_id)
    if link is None:
        abort(404)
    link.delete()
    return redirect(redirect_back(feed.route))