How to use the dispatch.apps.content.models.Article.objects function in dispatch

To help you get started, we’ve selected a few dispatch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ubyssey / dispatch / dispatch / themes / ubyssey / scripts / import.py View on Github external
def save_article(self, data):

        slug = data['url'].rsplit('/',2)[1]

        try:
            Article.objects.filter(slug=slug).delete()
        except:
            pass

        try:
            author = Person.objects.get(full_name=data['author'])
        except:
            author = Person.objects.create(full_name=data['author'])

        article = Article()

        title = str(BeautifulSoup(data['title'], 'html.parser'))
        article.headline = title

        article.slug = slug
        article.snippet = data['description']
        article.seo_keyword = data['keyword']
github ubyssey / dispatch / dispatch / apps / frontend / themes / default / views.py View on Github external
def _find_article(slug, section=None):
            if section is not None:
                return Article.objects.get(slug=slug, section__name=section, head=True)
            else:
                return Article.objects.get(slug=slug, head=True)
github ubyssey / dispatch / dispatch / modules / auth / actions.py View on Github external
def recent_articles(person, count=5):

    time = datetime.datetime.now() - datetime.timedelta(days=7)

    actions = Action.objects.filter(person=person, object_type='article', timestamp__gt=time).order_by('-timestamp')
    articles = []

    for action in actions:

        try:
            article = Article.objects.get(parent_id=action.object_id, head=True)
            if article not in articles:
                articles.append(article)
        except:
            pass

    return articles
github ubyssey / dispatch / dispatch / themes / ubyssey / views.py View on Github external
def topic(self, request, pk=None):

        try:
            topic = Topic.objects.get(id=pk)
        except Topic.DoesNotExist:
            raise Http404("Topic does not exist.")

        articles = Article.objects.filter(topic=topic, is_published=True).order_by('-published_at')

        context = {
            'meta': {
                'title': topic.name
            },
            'section': topic,
            'type': 'topic',
            'articles': {
                'first': articles[0] if articles else None,
                'rest': articles[1:9]
            }
        }

        return render(request, 'section.html', context)
github ubyssey / dispatch / dispatch / themes / ubyssey / scripts / import.py View on Github external
def save(self, count=None):

        Article.objects.filter(section__slug=self.articles[0]['post_type']).delete()

        n = 0
        for article in self.articles:
            self.save_article(article)
            n += 1
            if count is not None and n >= count:
                return
github ubyssey / dispatch / dispatch / apps / frontend / themes / default / views.py View on Github external
def _find_article(slug, section=None):
            if section is not None:
                return Article.objects.get(slug=slug, section__name=section, head=True)
            else:
                return Article.objects.get(slug=slug, head=True)
github ubyssey / dispatch / dispatch / apps / manager / views.py View on Github external
def article_delete(request, id):
    article = Article.objects.get(pk=id)
    section_slug = article.section.slug
    article.is_active = False
    article.save(update_fields=['is_active'])
    return redirect(section, section_slug)
github ubyssey / dispatch / dispatch / themes / ubyssey / views.py View on Github external
def home(self, request):

        frontpage = Article.objects.get_frontpage()

        frontpage_ids = [int(a.id) for a in frontpage[:2]]

        sections = Article.objects.get_sections(exclude=('blog',),frontpage=frontpage_ids)

        articles = {
              'primary': frontpage[0],
              'secondary': frontpage[1],
              'thumbs': frontpage[2:4],
              'bullets': frontpage[4:6],
         }

        #page = Homepage()

        popular = Article.objects.get_most_popular(5)
github ubyssey / dispatch / dispatch / themes / ubyssey / views.py View on Github external
def home(self, request):

        frontpage = Article.objects.get_frontpage(sections=('news', 'culture', 'opinion', 'sports', 'features', 'science'))

        frontpage_ids = [int(a.id) for a in frontpage[:2]]

        sections = Article.objects.get_sections(exclude=('blog',),frontpage=frontpage_ids)

        try:
            articles = {
                'primary': frontpage[0],
                'secondary': frontpage[1],
                'thumbs': frontpage[2:4],
                'bullets': frontpage[4:6],
             }
        except IndexError:
            raise Exception("Not enough articles to populate the frontpage!")

        component_set = Homepage()
github ubyssey / dispatch / dispatch / themes / ubyssey / views.py View on Github external
def home(self, request):

        frontpage = Article.objects.get_frontpage()

        frontpage_ids = [int(a.id) for a in frontpage[:2]]

        sections = Article.objects.get_sections(exclude=('blog',),frontpage=frontpage_ids)

        articles = {
              'primary': frontpage[0],
              'secondary': frontpage[1],
              'thumbs': frontpage[2:4],
              'bullets': frontpage[4:6],
         }

        #page = Homepage()

        popular = Article.objects.get_most_popular(5)

        context = {
            'articles': articles,
            'sections': sections,
            'popular':  popular,