Ejemplo n.º 1
0
    def podcast(self, request, slug=None):
        try:
            podcast = Podcast.objects.all()[:1].get()
        except:
            raise Http404('We could not find the podcast')

        episode_list = PodcastEpisode.objects.filter(
            podcast_id=podcast.id).order_by('-published_at')

        episode_urls = []
        for episode in episode_list:
            episode_urls += [
                PodcastHelper.get_podcast_episode_url(episode.podcast_id,
                                                      episode.id)
            ]

        episodes = zip(episode_list, episode_urls)

        url = PodcastHelper.get_podcast_url(id=podcast.id)
        context = {'podcast': podcast, 'url': url, 'episodes': episodes}

        return render(request, 'podcasts/podcast.html', context)
Ejemplo n.º 2
0
    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)

        try:
            podcast = Podcast.objects.all()[:1].get()
            podcast_url = PodcastHelper.get_podcast_url(podcast.id)
        except:
            podcast = None
            podcast_url = None

        episode_list = None
        episode_urls = []
        episodes = None

        if (podcast):
            try:
                episode_list = PodcastEpisode.objects.filter(
                    podcast_id=podcast.id).order_by('-published_at')
            except:
                episode_list = None
            if episode_list:
                for episode in episode_list:
                    episode_urls += [
                        PodcastHelper.get_podcast_episode_url(
                            episode.podcast_id, episode.id)
                    ]

            episodes = zip(episode_list, episode_urls)

        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

        podcast_obj = None
        if podcast and episode_list:
            podcast_obj = {
                'title': podcast.title,
                'url': podcast_url,
                'episodes': {
                    'first': episodes[0],
                    'rest': episodes[1:4]
                }
            }

        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,
            'podcast': podcast_obj,
            '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)