def save_media_obj(self, name, email, title, description, tags, uploaded_file, url): # create our media object as a status-less placeholder initially media_obj = Media() media_obj.author = Author(name, email) media_obj.title = title media_obj.slug = get_available_slug(Media, title) media_obj.description = description if request.settings['wording_display_administrative_notes']: media_obj.notes = request.settings['wording_administrative_notes'] media_obj.set_tags(tags) # Give the Media object an ID. DBSession.add(media_obj) DBSession.flush() # Create a MediaFile object, add it to the media_obj, and store the file permanently. media_file = add_new_media_file(media_obj, file=uploaded_file, url=url) # The thumbs may have been created already by add_new_media_file if not has_thumbs(media_obj): create_default_thumbs_for(media_obj) media_obj.update_status() DBSession.flush() return media_obj
def save(self, id, slug, title, author_name, author_email, description, notes, podcast, tags, categories, delete=None, **kwargs): """Save changes or create a new :class:`~mediadrop.model.media.Media` instance. Form handler the :meth:`edit` action and the :class:`~mediadrop.forms.admin.media.MediaForm`. Redirects back to :meth:`edit` after successful editing and :meth:`index` after successful deletion. """ media = fetch_row(Media, id) if delete: self._delete_media(media) redirect(action='index', id=None) if not slug: slug = slugify(title) elif slug.startswith('_stub_'): slug = slug[len('_stub_'):] if slug != media.slug: media.slug = get_available_slug(Media, slug, media) media.title = title media.author = Author(author_name, author_email) media.description = description media.notes = notes media.podcast_id = podcast media.set_tags(tags) media.set_categories(categories) media.update_status() DBSession.add(media) DBSession.flush() if id == 'new' and not has_thumbs(media): create_default_thumbs_for(media) if request.is_xhr: status_form_xhtml = unicode(update_status_form.display( action=url_for(action='update_status', id=media.id), media=media)) return dict( media_id = media.id, values = {'slug': slug}, link = url_for(action='edit', id=media.id), status_form = status_form_xhtml, ) else: redirect(action='edit', id=media.id)
def save(self, id, slug, title, subtitle, author_name, author_email, description, details, feed, delete=None, **kwargs): """Save changes or create a new :class:`~mediadrop.model.podcasts.Podcast` instance. Form handler the :meth:`edit` action and the :class:`~mediadrop.forms.admin.podcasts.PodcastForm`. Redirects back to :meth:`edit` after successful editing and :meth:`index` after successful deletion. """ podcast = fetch_row(Podcast, id) if delete: DBSession.delete(podcast) DBSession.commit() delete_thumbs(podcast) redirect(action='index', id=None) if not slug: slug = title if slug != podcast.slug: podcast.slug = get_available_slug(Podcast, slug, podcast) podcast.title = title podcast.subtitle = subtitle podcast.author = Author(author_name, author_email) podcast.description = description podcast.copyright = details['copyright'] podcast.category = details['category'] podcast.itunes_url = feed['itunes_url'] podcast.feedburner_url = feed['feedburner_url'] podcast.explicit = { 'yes': True, 'clean': False }.get(details['explicit'], None) if id == 'new': DBSession.add(podcast) DBSession.flush() create_default_thumbs_for(podcast) redirect(action='edit', id=podcast.id)
def save(self, name, email, title, description, tags, uploaded_file, url, publish=False): # Update media object metadata self.author = Author(name, email) self.title = title self.slug = get_available_slug(Media, title) self.description = description self.set_tags(tags) # Give the Media object an ID. DBSession.add(self) DBSession.flush() # Create a MediaFile object, add it to the media_obj, and store the file permanently. media_file = add_new_media_file(self, file=uploaded_file, url=url) # The thumbs may have been created already by add_new_media_file if not has_thumbs(self): create_default_thumbs_for(self) self.update_status() ## Save to database DBSession.add(self) DBSession.commit() ## Optional publish if publish: self.reviewed = True self.publishable = True self.publish_on = datetime.now() self.update_popularity() self.update_status() DBSession.add(self) DBSession.commit() return self
def save( self, id, slug, title, subtitle, author_name, author_email, description, details, feed, delete=None, **kwargs ): """Save changes or create a new :class:`~mediadrop.model.podcasts.Podcast` instance. Form handler the :meth:`edit` action and the :class:`~mediadrop.forms.admin.podcasts.PodcastForm`. Redirects back to :meth:`edit` after successful editing and :meth:`index` after successful deletion. """ podcast = fetch_row(Podcast, id) if delete: DBSession.delete(podcast) DBSession.commit() delete_thumbs(podcast) redirect(action="index", id=None) if not slug: slug = title if slug != podcast.slug: podcast.slug = get_available_slug(Podcast, slug, podcast) podcast.title = title podcast.subtitle = subtitle podcast.author = Author(author_name, author_email) podcast.description = description podcast.copyright = details["copyright"] podcast.category = details["category"] podcast.itunes_url = feed["itunes_url"] podcast.feedburner_url = feed["feedburner_url"] podcast.explicit = {"yes": True, "clean": False}.get(details["explicit"], None) if id == "new": DBSession.add(podcast) DBSession.flush() create_default_thumbs_for(podcast) redirect(action="edit", id=podcast.id)
def add_file(self, id, file=None, url=None, **kwargs): """Save action for the :class:`~mediadrop.forms.admin.media.AddFileForm`. Creates a new :class:`~mediadrop.model.media.MediaFile` from the uploaded file or the local or remote URL. :param id: Media ID. If ``"new"`` a new Media stub is created. :type id: :class:`int` or ``"new"`` :param file: The uploaded file :type file: :class:`cgi.FieldStorage` or ``None`` :param url: A URL to a recognizable audio or video file :type url: :class:`unicode` or ``None`` :rtype: JSON dict :returns: success bool message Error message, if unsuccessful media_id The :attr:`~mediadrop.model.media.Media.id` which is important if new media has just been created. file_id The :attr:`~mediadrop.model.media.MediaFile.id` for the newly created file. edit_form The rendered XHTML :class:`~mediadrop.forms.admin.media.EditFileForm` for this file. status_form The rendered XHTML :class:`~mediadrop.forms.admin.media.UpdateStatusForm` """ if id == 'new': media = Media() user = request.perm.user media.author = Author(user.display_name, user.email_address) # Create a temp stub until we can set it to something meaningful timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') media.title = u'Temporary stub %s' % timestamp media.slug = get_available_slug(Media, '_stub_' + timestamp) media.reviewed = True DBSession.add(media) DBSession.flush() else: media = fetch_row(Media, id) try: media_file = add_new_media_file(media, file, url) except UserStorageError as e: return dict(success=False, message=e.message) if media.slug.startswith('_stub_'): media.title = media_file.display_name media.slug = get_available_slug(Media, '_stub_' + media.title) # The thumbs may have been created already by add_new_media_file if id == 'new' and not has_thumbs(media): create_default_thumbs_for(media) media.update_status() # Render some widgets so the XHTML can be injected into the page edit_form_xhtml = unicode(edit_file_form.display( action=url_for(action='edit_file', id=media.id), file=media_file)) status_form_xhtml = unicode(update_status_form.display( action=url_for(action='update_status', id=media.id), media=media)) data = dict( success = True, media_id = media.id, file_id = media_file.id, file_type = media_file.type, edit_form = edit_form_xhtml, status_form = status_form_xhtml, title = media.title, slug = media.slug, description = media.description, link = url_for(action='edit', id=media.id), duration = helpers.duration_from_seconds(media.duration), ) return data
def add_file(self, id, file=None, url=None, **kwargs): """Save action for the :class:`~mediadrop.forms.admin.media.AddFileForm`. Creates a new :class:`~mediadrop.model.media.MediaFile` from the uploaded file or the local or remote URL. :param id: Media ID. If ``"new"`` a new Media stub is created. :type id: :class:`int` or ``"new"`` :param file: The uploaded file :type file: :class:`cgi.FieldStorage` or ``None`` :param url: A URL to a recognizable audio or video file :type url: :class:`unicode` or ``None`` :rtype: JSON dict :returns: success bool message Error message, if unsuccessful media_id The :attr:`~mediadrop.model.media.Media.id` which is important if new media has just been created. file_id The :attr:`~mediadrop.model.media.MediaFile.id` for the newly created file. edit_form The rendered XHTML :class:`~mediadrop.forms.admin.media.EditFileForm` for this file. status_form The rendered XHTML :class:`~mediadrop.forms.admin.media.UpdateStatusForm` """ if id == 'new': media = Media() user = request.perm.user media.author = Author(user.display_name, user.email_address) # Create a temp stub until we can set it to something meaningful timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') media.title = u'Temporary stub %s' % timestamp media.slug = get_available_slug(Media, '_stub_' + timestamp) media.reviewed = True DBSession.add(media) DBSession.flush() else: media = fetch_row(Media, id) try: media_file = add_new_media_file(media, file, url) except UserStorageError as e: return dict(success=False, message=e.message) if media.slug.startswith('_stub_'): media.title = media_file.display_name media.slug = get_available_slug(Media, '_stub_' + media.title) # The thumbs may have been created already by add_new_media_file if id == 'new' and not has_thumbs(media): create_default_thumbs_for(media) media.update_status() # Render some widgets so the XHTML can be injected into the page edit_form_xhtml = unicode( edit_file_form.display(action=url_for(action='edit_file', id=media.id), file=media_file)) status_form_xhtml = unicode( update_status_form.display(action=url_for(action='update_status', id=media.id), media=media)) data = dict( success=True, media_id=media.id, file_id=media_file.id, file_type=media_file.type, edit_form=edit_form_xhtml, status_form=status_form_xhtml, title=media.title, slug=media.slug, description=media.description, link=url_for(action='edit', id=media.id), duration=helpers.duration_from_seconds(media.duration), ) return data