Commit de047352 authored by Okhin's avatar Okhin
Browse files

Fixing the Factory for tags

parent 80cd52d3
import datetime import datetime
from random import choice from random import choice, randint
import pytz import pytz
import factory import factory
from factory.fuzzy import FuzzyDateTime, FuzzyChoice from factory.fuzzy import FuzzyDateTime, FuzzyChoice
from taggit.models import Tag
from .models import Article, STATUS_CHOICES from .models import Article, STATUS_CHOICES
class TagFactory(factory.django.DjangoModelFactory):
class Meta:
model = Tag
name = factory.Faker("word")
class ArticleFactory(factory.django.DjangoModelFactory): class ArticleFactory(factory.django.DjangoModelFactory):
class Meta: class Meta:
model = Article model = Article
......
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.core import files from django.core import files
from django.contrib.auth.decorators import permission_required
from taggit.managers import TaggableManager from taggit.managers import TaggableManager
from newspaper import Article as ArticleParser, ArticleException from newspaper import Article as ArticleParser, ArticleException
...@@ -104,7 +103,7 @@ class Article(models.Model): ...@@ -104,7 +103,7 @@ class Article(models.Model):
#: If the article is quoting something LQDN said or wrote #: If the article is quoting something LQDN said or wrote
quote = models.BooleanField(_("Article directly quotes us"), quote = models.BooleanField(_("Article directly quotes us"),
default=False) default=False)
#: If the article speaks about something LQDN did or wrote #: If the article speaks about something LQDN did or wrote
speak = models.BooleanField(_("Article speaks of us"), default=False) speak = models.BooleanField(_("Article speaks of us"), default=False)
...@@ -239,7 +238,8 @@ class Article(models.Model): ...@@ -239,7 +238,8 @@ class Article(models.Model):
# Let's add the tags # Let's add the tags
if tags: if tags:
article.tags.add(','.join([t['name'] for t in tags if len(t) > 0])) article.tags.set(*tags)
article.save()
try: try:
r = requests.get(url, timeout=0.5) r = requests.get(url, timeout=0.5)
article.original_status = r.status_code article.original_status = r.status_code
......
...@@ -20,6 +20,7 @@ CONTRIB_APPS = [ ...@@ -20,6 +20,7 @@ CONTRIB_APPS = [
"rest_framework.authtoken", "rest_framework.authtoken",
"taggit", "taggit",
"taggit_serializer",
"crispy_forms", "crispy_forms",
"django_markdown2", "django_markdown2",
"sorl.thumbnail", "sorl.thumbnail",
......
Supports Markdown
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