Commit 21f61095 authored by cynddl's avatar cynddl

Force lowercase for language option in newspaper

parent de6e90a8
...@@ -14,6 +14,12 @@ STATUS_CHOICES = ( ...@@ -14,6 +14,12 @@ STATUS_CHOICES = (
("REJECTED", _("Rejected")) ("REJECTED", _("Rejected"))
) )
LANG_CHOICES = (
("FR", _("French")),
("EN", _("English")),
("NA", _("Other"))
)
URL_HELP_TEXT = """The URL should not contain any marketing tags. We URL_HELP_TEXT = """The URL should not contain any marketing tags. We
automatically strip the most known tags.""" automatically strip the most known tags."""
...@@ -27,7 +33,8 @@ article content. You should aim at around 500 characters. Use bracket ellipsis ...@@ -27,7 +33,8 @@ article content. You should aim at around 500 characters. Use bracket ellipsis
class Article(VoteMixin): class Article(VoteMixin):
url = models.URLField("URL", help_text=URL_HELP_TEXT) url = models.URLField("URL", help_text=URL_HELP_TEXT)
lang = models.CharField(_("Language"), max_length=50, null=True) lang = models.CharField(
_("Language"), choices=LANG_CHOICES, default="NA", max_length=50)
metadata = models.TextField( metadata = models.TextField(
_("Opengraph metadata"), blank=True, null=True) _("Opengraph metadata"), blank=True, null=True)
screenshot = models.ImageField( screenshot = models.ImageField(
...@@ -72,7 +79,8 @@ class Article(VoteMixin): ...@@ -72,7 +79,8 @@ class Article(VoteMixin):
self.save() self.save()
def parse(self): def parse(self):
article = ArticleParser(url=self.url, language=self.lang) lang_lower = self.lang.lower() if self.lang != "NA" else None
article = ArticleParser(url=self.url, language=lang_lower)
article.download() article.download()
article.parse() article.parse()
self.title = article.title self.title = article.title
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment