示例#1
0
    def testSlugifyFunction(self):

        text = slugify("this text is a slug")

        self.assertEqual("this-text-is-a-slug", text)

        # test for no charactes

        text = slugify("")
        self.assertEqual("", text)

        # text for non-ascii characters  characters

        text = slugify("grzęgżóką")
        self.assertEqual("grzegzoka", text)

        # text for more than one space

        text = slugify(u"lorem     ipsum")
        self.assertEqual("lorem-ipsum", text)

        # test for tabs

        text = slugify("lorem\tipsum")
        self.assertEqual("lorem-ipsum", text)
示例#2
0
    def create_article(title, body, author, draft=True, **kwargs):

        """
        Creates new article
        Returns instance of the created article

        Arguments:
            :title  (string/unicode)(required) - title of the article
            :body   (string/unicode)(required) - body of the article
            :author (object) - Users object containing author\'s info
            :draft  (bool) (optional)- whether article is published
            :categories (list/tuple) (optional) - list containing
            names of article categories
            :series (string/unicode) (optional) - article series
            :article_image (string) - url to be used as title
            image for article
            :article_thumbnail (string) - url for articles thumbnail
        """

        if len(title) > 255:
            raise ValueError("Title must be at most 255 characters")
        try:
            series = kwargs.get("series", None)
            article_image = kwargs.get("article_image", None)
            article_thumbnail = kwargs.get("article_thumbnail", None)
            article = Articles.create(
                title=title,
                slug=slugify(title),
                body=body,
                author=author,
                draft=draft,
                series=series,
                article_image=article_image,
                article_thumbnail=article_thumbnail,
            )
            article_categories = kwargs.get("categories", None)
            if article_categories:
                try:
                    article.save_article_categories(article_categories)
                except:
                    raise
            return article
        except Exception as e:
            handle_errors("Error creating article")
            raise
示例#3
0
    def create_article(title, body, author, draft=True, **kwargs):
        """
        Creates new article
        Returns instance of the created article

        Arguments:
            :title  (string/unicode)(required) - title of the article
            :body   (string/unicode)(required) - body of the article
            :author (object) - Users object containing author\'s info
            :draft  (bool) (optional)- whether article is published
            :categories (list/tuple) (optional) - list containing
            names of article categories
            :series (string/unicode) (optional) - article series
            :article_image (string) - url to be used as title
            image for article
            :article_thumbnail (string) - url for articles thumbnail
        """

        if len(title) > 255:
            raise ValueError("Title must be at most 255 characters")
        try:
            series = kwargs.get("series", None)
            article_image = kwargs.get("article_image", None)
            article_thumbnail = kwargs.get("article_thumbnail", None)
            article = Articles.create(title=title,
                                      slug=slugify(title),
                                      body=body,
                                      author=author,
                                      draft=draft,
                                      series=series,
                                      article_image=article_image,
                                      article_thumbnail=article_thumbnail)
            article_categories = kwargs.get("categories", None)
            if article_categories:
                try:
                    article.save_article_categories(article_categories)
                except:
                    raise
            return article
        except Exception as e:
            handle_errors("Error creating article")
            raise