def view(self, slug, podcast_slug=None, **kwargs): """Display the media player, info and comments. :param slug: The :attr:`~mediadrop.models.media.Media.slug` to lookup :param podcast_slug: The :attr:`~mediadrop.models.podcasts.Podcast.slug` for podcast this media belongs to. Although not necessary for looking up the media, it tells us that the podcast slug was specified in the URL and therefore we reached this action by the preferred route. :rtype dict: :returns: media The :class:`~mediadrop.model.media.Media` instance for display. related_media A list of :class:`~mediadrop.model.media.Media` instances that rank as topically related to the given media item. comments A list of :class:`~mediadrop.model.comments.Comment` instances associated with the selected media item. comment_form_action ``str`` comment form action comment_form_values ``dict`` form values next_episode The next episode in the podcast series, if this media belongs to a podcast, another :class:`~mediadrop.model.media.Media` instance. """ media = fetch_row(Media, slug=slug) request.perm.assert_permission(u'view', media.resource) if media.podcast_id is not None: # Always view podcast media from a URL that shows the context of the podcast if url_for() != url_for(podcast_slug=media.podcast.slug): redirect(podcast_slug=media.podcast.slug) try: media.increment_views() DBSession.commit() except OperationalError: DBSession.rollback() if request.settings['comments_engine'] == 'facebook': response.facebook = Facebook(request.settings['facebook_appid']) related_media = viewable_media(Media.query.related(media))[:6] # TODO: finish implementation of different 'likes' buttons # e.g. the default one, plus a setting to use facebook. return dict( media = media, related_media = related_media, comments = media.comments.published().all(), comment_form_action = url_for(action='comment'), comment_form_values = kwargs, )
def view(self, slug, podcast_slug=None, **kwargs): """Display the media player, info and comments. :param slug: The :attr:`~mediadrop.models.media.Media.slug` to lookup :param podcast_slug: The :attr:`~mediadrop.models.podcasts.Podcast.slug` for podcast this media belongs to. Although not necessary for looking up the media, it tells us that the podcast slug was specified in the URL and therefore we reached this action by the preferred route. :rtype dict: :returns: media The :class:`~mediadrop.model.media.Media` instance for display. related_media A list of :class:`~mediadrop.model.media.Media` instances that rank as topically related to the given media item. comments A list of :class:`~mediadrop.model.comments.Comment` instances associated with the selected media item. comment_form_action ``str`` comment form action comment_form_values ``dict`` form values next_episode The next episode in the podcast series, if this media belongs to a podcast, another :class:`~mediadrop.model.media.Media` instance. """ media = fetch_row(Media, slug=slug) request.perm.assert_permission(u'view', media.resource) if media.podcast_id is not None: # Always view podcast media from a URL that shows the context of the podcast if url_for() != url_for(podcast_slug=media.podcast.slug): redirect(podcast_slug=media.podcast.slug) try: media.increment_views() DBSession.commit() except OperationalError: DBSession.rollback() if request.settings['comments_engine'] == 'facebook': response.facebook = Facebook(request.settings['facebook_appid']) related_media = viewable_media(Media.query.related(media))[:6] # TODO: finish implementation of different 'likes' buttons # e.g. the default one, plus a setting to use facebook. return dict( media=media, related_media=related_media, comments=media.comments.published().all(), comment_form_action=url_for(action='comment'), comment_form_values=kwargs, )
def test_add_file_url(self): slug = u'test-add-file-url' title = u'Test Adding File by URL on Media Edit Page.' try: media = self._new_publishable_media(slug, title) media.publishable = False media.reviewed = False DBSession.add(media) DBSession.commit() media_id = media.id except SQLAlchemyError, e: DBSession.rollback() raise e
def test_edit_media(self): title = u'Edit Existing Media Test' slug = u'edit-existing-media-test' # this should be unique # Values that we will change during the edit process name = u'Frederick Awesomeson' email = u'*****@*****.**' description = u'This media item was created to test the "admin/media/edit/someID" method' htmlized_description = '<p>This media item was created to test the "admin/media/edit/someID" method</p>' notes = u'Some Notes!' try: media = self._new_publishable_media(slug, title) media.publishable = False media.reviewed = False DBSession.add(media) DBSession.commit() media_id = media.id except SQLAlchemyError, e: DBSession.rollback() raise e
def final_view(self, id, **kwargs): print('hello') try: csrf = kwargs['environ']['paste.cookies'][0]['csrftoken'].value # .filter(Views_Counter.csrftoken==csrf)\ temp = Views_Counter.query.filter(Views_Counter.media_id==id)\ .filter(Views_Counter.validated==False) print(csrf) if temp: temp = temp.one() media = fetch_row(Media, id=id) try: media.increment_views3() media.increment_views() DBSession.commit() except OperationalError: DBSession.rollback() return dict(success=False) temp.validated = True DBSession.flush() except: return dict(success=False) return dict(success=True)