예제 #1
0
    def article(self, request, slug=None):
        """Magazine article page view."""

        try:
            article = ArticleHelper.get_article(request, slug)
        except:
            raise Http404('Article could not be found.')

        article.add_view()

        context = {
            'title':
            '%s - %s' % (article.headline, self.SITE_TITLE),
            'meta':
            ArticleHelper.get_meta(
                article,
                default_image=static('images/magazine/cover-social.png')),
            'article':
            article,
            'suggested':
            ArticleHelper.get_random_articles(2,
                                              'magazine',
                                              exclude=article.id),
            'base_template':
            'magazine/base.html'
        }

        t = loader.select_template([
            '%s/%s' % (article.section.slug, article.get_template_path()),
            article.get_template_path()
        ])

        return HttpResponse(t.render(context))
예제 #2
0
    def article(self, request, slug=None):
        """Guide article page."""
        try:
            article = ArticleHelper.get_article(request, slug)
        except Http404:
            raise Http404('Article could not be found.')

        template_fields = article.template_fields

        try:
            next_a = ArticleHelper.get_article(request,
                                               template_fields['next_a'])
        except:
            next_a = None

        try:
            next_b = ArticleHelper.get_article(request,
                                               template_fields['next_b'])
        except:
            next_b = None

        article.add_view()

        context = {
            'title': article.headline,
            'meta': ArticleHelper.get_meta(article),
            'article': article,
            'next': [next_a, next_b]
        }

        return render(request, 'guide/article.html', context)
예제 #3
0
파일: main.py 프로젝트: sungk44/ubyssey.ca
    def article(self, request, section=None, slug=None):
        try:
            article = ArticleHelper.get_article(request, slug)
        except:
            raise Http404('Article could not be found.')

        article.add_view()

        breaking = ArticleHelper.get_breaking_news().exclude(id=article.id).first()

        # determine if user is viewing from mobile
        article_type = 'desktop'
        user_agent = get_user_agent(request)
        if user_agent.is_mobile:
            article_type = 'mobile'


        if article.template == 'timeline':
            timeline_tag = article.tags.filter(name__icontains='timeline-')
            timelineArticles = Article.objects.filter(tags__in=timeline_tag, is_published=True)
            temp = list(timelineArticles.values('parent_id', 'template_data', 'slug', 'headline', 'featured_image'))
            try:
                temp = sorted(temp, key=lambda article: json.loads(article['template_data'])['timeline_date'])
            except:
                pass
            for i, a in enumerate(timelineArticles) :
                try:
                    temp[i]['featured_image'] = a.featured_image.image.get_thumbnail_url()
                except:
                    temp[i]['featured_image'] = None
            article.timeline_articles = json.dumps(temp)
            article.timeline_title = list(timeline_tag)[0].name.replace('timeline-', '').replace('-', ' ')


        ref = request.GET.get('ref', None)
        dur = request.GET.get('dur', None)

        if not ArticleHelper.is_explicit(article):
            article.content = ArticleHelper.insert_ads(article.content, article_type)

        popular = ArticleHelper.get_popular()[:5]

        context = {
            'title': '%s - %s' % (article.headline, self.SITE_TITLE),
            'meta': ArticleHelper.get_meta(article),
            'article': article,
            'reading_list': ArticleHelper.get_reading_list(article, ref=ref, dur=dur),
            # 'suggested': lambda: ArticleHelper.get_random_articles(2, section, exclude=article.id),
            'base_template': 'base.html',
            'popular': popular,
            'reading_time': ArticleHelper.get_reading_time(article),
            'explicit': ArticleHelper.is_explicit(article),
            'breaking': breaking,
        }

        template = article.get_template_path()
        t = loader.select_template(['%s/%s' % (article.section.slug, template), template, 'article/default.html'])
        return HttpResponse(t.render(context))
예제 #4
0
파일: main.py 프로젝트: sungk44/ubyssey.ca
    def home(self, request):
        frontpage = ArticleHelper.get_frontpage(
            sections=('news', 'culture', 'opinion', 'sports', 'features', 'science'),
            max_days=7
        )

        trending_article = ArticleHelper.get_trending()

        elections = ArticleHelper.get_topic('AMS Elections').order_by('-published_at')

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

        sections = ArticleHelper.get_frontpage_sections(exclude=frontpage_ids)

        breaking = ArticleHelper.get_breaking_news().first()

        # determine if user is viewing from mobile
        user_agent = get_user_agent(request)

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

        popular = ArticleHelper.get_popular()[:5]

        blog = ArticleHelper.get_frontpage(section='blog', limit=5)

        title = '%s - UBC\'s official student newspaper' % self.SITE_TITLE

        context = {
            'title': title,
            'meta': {
                'title': title,
                'description': 'Weekly student newspaper of the University of British Columbia.',
                'url': self.SITE_URL
            },
            'title': '%s - UBC\'s official student newspaper' % self.SITE_TITLE,
            'articles': articles,
            'sections': sections,
            'popular': popular,
            'breaking': breaking,
            'blog': blog,
            'day_of_week': datetime.now().weekday(),
            'is_mobile': user_agent.is_mobile
        }

        return render(request, 'homepage/base.html', context)
예제 #5
0
    def article(self, request, slug=None):
        """Magazine article page view."""

        try:
            article = ArticleHelper.get_article(request, slug)
        except:
            raise Http404('Article could not be found.')

        article.add_view()
        year = article.tags.get(name__icontains="20").name

        magazine_title = self.mag_titles[year]

        subsection = article.subsection.name.lower() if article.subsection else ""

        # determine if user is viewing from mobile
        article_type = 'desktop'
        user_agent = get_user_agent(request)
        if user_agent.is_mobile:
            article_type = 'mobile'

        if not ArticleHelper.is_explicit(article):
            article.content = ArticleHelper.insert_ads(article.content, article_type)

        context = {
            'title': '%s - %s' % (article.headline, self.SITE_TITLE),
            'meta': ArticleHelper.get_meta(article, default_image=static('images/magazine/cover-social.png')),
            'article': article,
            'subsection': subsection,
            'specific_css': 'css/magazine-' + year + '.css',
            'suggested': ArticleHelper.get_random_articles(2, 'magazine', exclude=article.id),
            'base_template': 'magazine/base.html',
            'magazine_title': magazine_title
        }

        t = loader.select_template(['%s/%s' % (article.section.slug, article.get_template_path()), article.get_template_path()])

        return HttpResponse(t.render(context))
예제 #6
0
    def article(self, request, section=None, slug=None):
        try:
            article = ArticleHelper.get_article(request, slug)
        except:
            raise Http404('Article could not be found.')

        article.add_view()

        ref = request.GET.get('ref', None)
        dur = request.GET.get('dur', None)

        authors_json_name = json.dumps(
            [a.person.full_name for a in article.authors.all()])

        context = {
            'title':
            '%s - %s' % (article.headline, self.SITE_TITLE),
            'meta':
            ArticleHelper.get_meta(article),
            'article':
            article,
            'reading_list':
            ArticleHelper.get_reading_list(article, ref=ref, dur=dur),
            'suggested':
            lambda: ArticleHelper.get_random_articles(
                2, section, exclude=article.id),
            'base_template':
            'base.html',
            'reading_time':
            ArticleHelper.get_reading_time(article)
        }

        template = article.get_template_path()
        t = loader.select_template([
            '%s/%s' % (article.section.slug, template), template,
            'article/default.html'
        ])
        return HttpResponse(t.render(context))
예제 #7
0
파일: main.py 프로젝트: sungk44/ubyssey.ca
    def elections(self, request):
        articles = ArticleHelper.get_topic('AMS Elections').order_by('-published_at')

        topic = Topic.objects.filter(name='AMS Elections')[0]

        context = {
            'meta': {
                'title': '2017 AMS Elections'
            },
            'section': {
                'name': '2017 AMS Elections',
                'slug': 'elections',
                'id': topic.id
            },
            'type': 'topic',
            'articles': {
                'first': articles[0],
                'rest': articles[1:9]
            }
        }

        return render(request, 'section.html', context)
예제 #8
0
파일: main.py 프로젝트: petal07/ubyssey.ca
    def archive(self, request):
        years = ArticleHelper.get_years()

        sections = Section.objects.all()

        order = request.GET.get('order')
        if order != 'oldest':
            order = 'newest'

        filters = []

        if order == 'oldest':
            filters.append('order=%s' % order)

        order_by = '-published_at' if order == 'newest' else 'published_at'

        context = {'sections': sections, 'years': years, 'order': order}

        query = request.GET.get('q', '').strip() or None
        section_id = parse_int_or_none(request.GET.get('section_id'))

        year = parse_int_or_none(request.GET.get('year'))

        article_list = Article.objects.filter(
            is_published=True).order_by(order_by)

        try:
            person = Person.objects.get(full_name__icontains=query)
        except:
            person = None

        if year:
            context['year'] = year
            article_list = article_list.filter(
                published_at__icontains=str(year))
            filters.append('year=%s' % year)

        if query:
            article_list = article_list.filter(
                headline__icontains=query) | article_list.filter(
                    authors__person=person)
            context['q'] = query
            filters.append('q=%s' % query)

        if section_id:
            article_list = article_list.filter(section=section_id)
            context['section_id'] = section_id
            context['section_name'] = Section.objects.get(id=section_id)
            filters.append('section_id=%s' % section_id)

        if filters:
            query_string = '?' + '&'.join(filters)
        else:
            query_string = ''

        paginator = Paginator(article_list, 15)  # Show 15 articles per page
        page = request.GET.get('page')

        try:
            articles = paginator.page(page)
        except PageNotAnInteger:
            articles = paginator.page(1)
        except EmptyPage:
            articles = paginator.page(paginator.num_pages)

        meta = {'title': 'Archive'}

        context['articles'] = articles
        context['count'] = paginator.count
        context['meta'] = meta
        context['query_string'] = query_string

        return render(request, 'archive.html', context)
예제 #9
0
 def items(self, section):
     return ArticleHelper.get_frontpage(limit=self.max_items)