class EventOptions( ArchiveOptions ):
    urlname_prefix = "events"

    #title = ugettext_noop("Events and Meetings")

    detail_views = (
        { 'url_pattern': 'api/(?P<serializer>json)/', 'view': SerializationDetailView( serializer=EventSerializer, emitters=[JSONEmitter] ), 'urlname_suffix': 'serialization', },
    )

    search_fields = (
        'location__name', 'series__name', 'title', 'speaker', 'affiliation', 'abstract',
    )

    class Queries(object):
        default = AllEventsQuery( browsers=( 'html', 'json', 'ical' ), verbose_name = "Seminars and Colloquia" )
        site = SiteQuery( browsers=( 'html', 'json', 'ical' ), verbose_name = "Seminars and Colloquia" )
        conf = AllEventsQuery( browsers=( 'html', 'json', 'ical' ), verbose_name = "Conferences and Workshops" )
        year = YearQuery( browsers=( 'html', 'json', 'ical' ), datetime_feature='start_date', verbose_name = "Seminars and Colloquia %d")
        site_embed = SiteQuery( browsers=( 'html_embed', 'json', 'ical' ), verbose_name = "Seminars and Colloquia" )
        conf_embed = AllEventsQuery( browsers=( 'html_conf_embed', 'json', 'ical' ), verbose_name = "Conferences and Workshops" )
        industry = IndustryEventsQuery( browsers=( 'html_industry', 'json', 'ical' ), verbose_name = "Industry Events" )

    class Browsers(object):
        html = ListBrowser( verbose_name='HTML', paginate_by=1000 )
        html_embed = ListBrowser( verbose_name='HTML', paginate_by=1000, index_template='index_list_embed.html' )
        html_conf_embed = ListBrowser( verbose_name='HTML', paginate_by=1000, index_template='index_list_embed.html' )
        html_industry = ListBrowser( verbose_name='HTML', paginate_by=1000, index_template='index_list_industry.html' )
        json = SerializationBrowser( serializer=EventSerializer, emitter=JSONEmitter, paginate_by=100, display=False, verbose_name=_( "JSON" ) )
        ical = SerializationBrowser( serializer=ICalEventSerializer, emitter=ICalEmitter, paginate_by=100, display=True, verbose_name=_( "iCal" ) )
Exemple #2
0
class PictureOfTheWeekOptions( ArchiveOptions ):
    urlname_prefix = "potw"

    detail_views = (
        { 'url_pattern': 'api/(?P<serializer>json)/', 'view': SerializationDetailView( serializer=PictureOfTheWeekSerializer, emitters=[JSONEmitter] ), 'urlname_suffix': 'serialization', },
    )

    search_fields = (
        'image__id', 'image__title', 'image__headline', 'image__description', 'image__subject_name__name', 'image__subject_name__alias', 'image__credit', 'image__type',
        'video__id', 'video__title', 'video__headline', 'video__description', 'video__subject_name__name', 'video__subject_name__alias', 'video__facility__name', 'video__credit', 'video__type',
    )

    class Queries( object ):
        default = PotwAllPublicQuery( browsers=( 'normal', 'viewall', 'json', 'ical' ), verbose_name=ugettext_noop("Picture of the Week"), feed_name="default" )
        embargo = EmbargoQuery( browsers=( 'normal', 'viewall', 'json', 'ical' ), verbose_name=ugettext_noop("Picture of the Week (embargoed)") )
        staging = StagingQuery( browsers=( 'normal', 'viewall', 'json', 'ical' ), verbose_name=ugettext_noop("Picture of the Week (staging)") )
        year = YearQuery( browsers=( 'normal', 'viewall', 'json', 'ical' ), verbose_name=ugettext_noop("Picture of the Week %d"), feed_name="default" )

    class Browsers( object ):
        normal = ListBrowser( paginate_by=20 )
        viewall = ListBrowser( paginate_by=100 )
        json = SerializationBrowser( serializer=PictureOfTheWeekSerializer, emitter=JSONEmitter, paginate_by=20, display=False, verbose_name=ugettext_noop( "JSON" ) )
        ical = SerializationBrowser( serializer=ICalPictureOfTheWeekSerializer, emitter=ICalEmitter, paginate_by=100, display=False, verbose_name=ugettext_noop( "iCal" ) )

    class Display( object ):
        multiple_potw = DisplayTemplate( 'template', '{%block org_prefix %}ESO{% endblock %} Picture of the Week: {{obj.image.title}}<br/><a href="{{site_url_prefix}}{{obj.get_absolute_url}}">{{site_url_prefix}}{{obj.get_absolute_url}}</a>', name='Multiple POTW list' )
        multiple_potw_text = DisplayTemplate( 'template', '{%block org_prefix %}ESO{% endblock %} Picture of the Week: {{obj.image.title}}<br/>{{site_url_prefix}}{{obj.get_absolute_url}}', name='Multiple POTW list (plaintext)' )
        potw_available_announcement = DisplayTemplate( 'file', 'archives/pictureoftheweek/email/translations_available_potw.html', name='Picture of the week available for translation' )

    @staticmethod
    def feeds():
        from djangoplicity.media.feeds import PictureOfTheWeekFeed
        feeds = {
            '': PictureOfTheWeekFeed,
        }
        return feeds
class ReleaseOptions( ArchiveOptions ):

    description_template = 'archives/release/object_description.html'

    title = ugettext_noop("Press Releases")

    urlname_prefix = "releases"

    downloads = ( ( ugettext_noop( 'Text' ), {'resources': ( 'pdf', 'text', 'doc', ), 'icons': { 'pdf': 'pdf', 'text': 'txt', 'doc': 'word' } } ), )

    info = (
        ( ugettext_noop( 'About the Release' ), { 'fields': ( releaseid, oldreleaseids, subject_name, subject_category, facility, instruments, telbib, ) } ),
    )

    admin = (
        ( ugettext_noop( 'Admin' ), { 'links': (
            admin_edit_for_site( 'admin_site', translation_proxy=ReleaseProxy ),
            admin_add_translation( 'admin_site', translation_proxy=ReleaseProxy ),
            ), 'fields': ( published, 'last_modified', 'created', 'meltwater_keywords', ), } ),
    )

    detail_views = (
        { 'url_pattern': 'api/(?P<serializer>json)/', 'view': SerializationDetailView( serializer=ReleaseSerializer, emitters=[JSONEmitter] ), 'urlname_suffix': 'serialization', },
        { 'url_pattern': 'kids/', 'view': views.KidsDetailView(), 'urlname_suffix': 'kids' },
    )

    search_fields = (
        'id', 'old_ids', 'release_type__name', 'title', 'release_city', 'headline',
        'description', 'notes', 'more_information', 'links', 'subject_name__name', 'subject_name__alias', 'facility__name',
        'releasecontact__name'
    )
    # Warning: prefetching releasecontact_set makes them disappear from the
    # archive_detail view and translations. Prefetch probably doesn't
    # work as it uses the translation contacts (which is empty) instead of the
    # source ones
    prefetch_related = (
        'facility', 'subject_name', 'publications',
        'subject_category', 'related_images', 'related_videos',
    )

    class Queries( object ):
        default = AllPublicQuery( browsers=( 'normal', 'viewall', 'json', 'minijson', 'ical' ), verbose_name=ugettext_noop("Press Releases"), feed_name="default", select_related='release_type' )
        embargo = EmbargoQuery( browsers=( 'normal', 'viewall', 'json', 'minijson', 'ical'  ), verbose_name=ugettext_noop("Embargoed Press Releases"), select_related='release_type' )
        staging = StagingQuery( browsers=( 'normal', 'viewall', 'json', 'minijson', 'ical'  ), verbose_name=ugettext_noop("Press Releases (staging)"), select_related='release_type' )
        year = YearQuery( browsers=( 'normal', 'viewall', 'json', 'minijson', 'ical' ), verbose_name=ugettext_noop("Press Releases %d"), feed_name="default", select_related='release_type' )
        search = AdvancedSearchQuery( browsers=( 'normal', 'viewall', 'json' ), verbose_name=ugettext_noop("Advanced press release search"), searchable=False )

    class Browsers( object ):
        normal = ListBrowser()
        viewall = ListBrowser( verbose_name=ugettext_noop('View all'), paginate_by=100 )
        json = SerializationBrowser( serializer=ReleaseSerializer, emitter=JSONEmitter, paginate_by=20, display=False, verbose_name=_( "JSON" ) )
        minijson = SerializationBrowser( serializer=MiniReleaseSerializer, emitter=JSONEmitter, paginate_by=10, display=False, verbose_name=_( "JSON" ) )
        ical = SerializationBrowser( serializer=ICalReleaseSerializer, emitter=ICalEmitter, paginate_by=100, display=False, verbose_name=_( "iCal" ) )

    class ResourceProtection( object ):
        unpublished = ( UnpublishedQuery, security.UNPUBLISHED_PERMS )
        staging = ( StagingQuery, security.STAGING_PERMS )
        embargo = ( EmbargoQuery, security.EMBARGO )

    class Display():
        #default = DisplayTemplate('template','{{obj}} - {{obj.id}}',name='ID')
        #sender = DisplayTemplate( 'template', settings.ARCHIVE_EMAIL_SENDER if hasattr( settings, 'ARCHIVE_EMAIL_SENDER' ) else '', name = 'From' )
        #subject = DisplayTemplate( 'file', 'archives/release/email/subject.txt', name = 'Subject' )
        #subject_embargo = DisplayTemplate('file','archives/release/email/subject.txt',name='Subject (Embargo)',embargo=True)
        esonews_from = DisplayTemplate( 'file', 'archives/release/email/from.txt', name='esonews or hubblenews or iaunews/eaae-list/all-users from' )
        esonews_subject = DisplayTemplate( 'file', 'archives/release/email/subject.txt', name='esonews or hubblenews or iaunews/eaae-list/all-users subject' )
        esonews = DisplayTemplate( 'file', 'archives/release/email/html_eso.html', name='esonews or hubblenews or iaunews/eaae-list/all-users' )
        epodpress_sender = DisplayTemplate( 'file', 'archives/release/email/from.txt', name='epodpress from' )
        epodpress_subject_embargo = DisplayTemplate( 'file', 'archives/release/email/subject.txt', name='epodpress subject (embargo)', embargo=True )
        epodpress_embargo = DisplayTemplate( 'file', 'archives/release/email/html.html', name='epodpress (embargo)', embargo=True )
        epodpress_subject = DisplayTemplate( 'file', 'archives/release/email/subject.txt', name='epodpress subject (immediate release)' )
        epodpress_immediate = DisplayTemplate( 'file', 'archives/release/email/html.html', name='epodpress (immediate release)' )
        #epodpress_embargo_plaintext = DisplayTemplate( 'file', 'archives/release/email/plaintext.txt', name = "epodpress (embargo txt)", embargo = True )
        #epodpress_immediate_plaintext = DisplayTemplate( 'file', 'archives/release/email/plaintext.txt', name = "epodpress (embargo txt)" )
        aas_from = DisplayTemplate('template', '{{request.user.get_full_name}} <{{request.user.email}}>', name='[email protected] from')
        aas_subject_embargo = DisplayTemplate( 'file', 'archives/release/email/subject.txt', name='[email protected] subject (embargo)', embargo=True )
        aas_embargo = DisplayTemplate( 'file', 'archives/release/email/aas.txt', name='[email protected] (embargo)', embargo=True )
        aas_subject = DisplayTemplate( 'file', 'archives/release/email/subject.txt', name='[email protected] subject')
        aas = DisplayTemplate( 'file', 'archives/release/email/aas.txt', name='*****@*****.**', )
        if settings.USE_I18N:
            translations_embargo_subject = DisplayTemplate( 'file', 'archives/release/email/translations_subject_embargo.html', name='Translations availability subject (before embargo)' )
            translations_embargo = DisplayTemplate( 'file', 'archives/release/email/translations_embargo.html', name='Translations availability (before embargo)' )
            translations_release_subject = DisplayTemplate( 'file', 'archives/release/email/translations_subject_base.html', name='Translations availability subject (before release)' )
            translations_release = DisplayTemplate( 'file', 'archives/release/email/translations_release.html', name='Translations availability (before release)' )
            translation_available_release = DisplayTemplate( 'file', 'archives/release/email/translations_available_release.html', name='Release available for translation' )
        meltwater = DisplayTemplate( 'file', 'archives/release/email/meltwater.html', name='Meltwater Keywords' )

    class AdvancedSearch (object):
        facility = AVMFacilitySearchField( label=_( "Facility used" ) )
        instruments = ManyToManySearchField( label=_( "Instruments" ), model_field='instruments__id', choices_func=lambda: [( i.id, _( i.name ) ) for i in Instrument.objects.all() ] )
        additional_search_items = SeparatorField( label=_("Additional search terms") )
        id = IdSearchField( label=_('Release ID') )
        published_since = DateSinceSearchField( label=_( "Published since" ), model_field='release_date' )
        published_until = DateUntilSearchField( label=_( "Published until" ), model_field='release_date' )
        title = TextSearchField( label=_( "Title" ), model_field='title' )
        subject_name = AVMSubjectNameSearchField( label=_( "Subject name" ) )
        category = AVMSubjectCategorySearchField( label=_( "Category" ), )
        description = TextSearchField( label=_( "Description" ), model_field='description' )

        class Meta:
            verbose_name = ugettext_noop("Advanced press release search")

    @staticmethod
    def feeds():
        """
        Feeds for press releases archive
        """
        from djangoplicity.releases.feeds import ReleaseFeed
        return {
            '': ReleaseFeed,
        }

    @staticmethod
    def process_object_list( object_list ):
        """
        Preprocess a list of releases to fetch the main images for all of them.
        """
        Release.store_main_visuals( object_list )

    @staticmethod
    def extra_context( obj, lang=None ):
        """
        Extra context variables for detail view
        """
        #
        # Visuals
        #
        images = related_archive_items( Release.related_images, obj )
        videos = related_archive_items( Release.related_videos, obj, has_main_visual=False )
        comparisons = related_archive_items( Release.related_comparisons, obj, has_main_visual=False )
        stock_images = related_archive_items( Release.stock_images, obj, has_main_visual=False )

        # Get main_visual
        main_image = main_visual_translated(obj.main_image, images)
        main_video = main_visual_translated(obj.main_video, videos)

        #
        # Translations
        #
        return {
            'main_image': main_image,
            'main_video': main_video,
            'images': images,
            'videos': videos,
            'comparisons': comparisons,
            'stock_images': stock_images,
            'translations': obj.get_translations(),
        }
class ImageOptions(ArchiveOptions):
    description_template = 'archives/image/object_description.html'

    urlname_prefix = "images"

    info = (
        (ugettext_noop(u'About the Image'), {
            'fields': (object_id, object_language, object_type, release_date,
                       related_releases, related_announcements,
                       related_science_announcements, pixel_size, fov),
            'links': (link_field(_('NASA press release'),
                                 'press_release_link'),
                      link_field(_('NASA caption'), 'long_caption_link'))
        }),
        (ugettext_noop(u'About the Object'), {
            'fields': (subject_name, subject_category, distance, constellation,
                       web_categories),
        }),
        (ugettext_noop(u'Mounted Image'), {
            'links': (rel_shop_link, ),
        }),
    )

    admin = ((ugettext_noop(u'Admin'), {
        'links': (
            admin_edit_for_site('admin_site', translation_proxy=ImageProxy),
            admin_add_translation('admin_site', translation_proxy=ImageProxy),
        ),
        'fields': (published, featured, 'release_date_owner', 'last_modified',
                   'created', priority, zoomable, wallpapers),
    }), )

    downloads = (
        (ugettext_noop(u'Image Formats'), {
            'resources': (
                'original',
                'large',
                'publicationtiff40k',
                'publicationtiff25k',
                'publicationtiff10k',
                'publicationtiff',
                'publicationjpg',
                'screen',
            ),
            'icons': {
                'original': 'phot',
                'large': 'phot',
                'publicationtiff40k': 'phot',
                'publicationtiff25k': 'phot',
                'publicationtiff10k': 'phot',
                'publicationtiff': 'phot',
                'publicationjpg': 'phot',
                'screen': 'phot',
            }
        }),
        (
            ugettext_noop(u'Print Layout'),
            {
                'condition': lambda obj: obj.print_layout,
                'resources': (
                    'pl_original',
                    'pl_screen',
                ),
                'icons': {
                    'pl_screen': 'phot',
                    'pl_original': 'phot',
                },
                'thumbnails': {
                    'pl_thumbs': 'pl_screen'
                },
            },
        ),
        (ugettext_noop(u'Zoomable'), {
            'resources': (zoomable_link, ),
            'icons': {
                'zoomable_link': 'zoom',
            }
        }),
        (ugettext_noop(u'BitTorrent Download'), {
            'resources': (image_magnet_uri_link, ),
            'icons': {
                'image_magnet_uri_link': 'magnet',
            }
        }),
        (ugettext_noop(u'Logos'), {
            'resources': (
                'png',
                'eps',
                'illustrator',
                'illustrator_text',
            ),
            'icons': {
                'png': 'phot',
                'eps': 'phot',
                'illustrator': 'phot',
                'illustrator_text': 'phot'
            }
        }),
        (ugettext_noop(u'Wallpapers'), {
            'condition':
            lambda obj: obj.wallpapers,
            'resources': (
                'wallpaper1',
                'wallpaper2',
                'wallpaper3',
                'wallpaper4',
                'wallpaper5',
            ),
            'icons': {
                'wallpaper1': 'slides',
                'wallpaper2': 'slides',
                'wallpaper3': 'slides',
                'wallpaper4': 'slides',
                'wallpaper5': 'slides',
            }
        }),
        (ugettext_noop(u'PDF'), {
            'resources': ('pdf', ),
            'icons': {
                'pdf': 'doc',
            }
        }),
    )

    detail_views = (
        {
            'url_pattern': 'zoomable/',
            'view': views.ZoomableDetailView(),
            'urlname_suffix': 'zoomable'
        },
        {
            'url_pattern':
            'api/(?P<serializer>xmp|xml|json)/',
            'view':
            SerializationDetailView(serializer=AVMImageSerializer,
                                    emitters=[XMPEmitter, JSONEmitter]),
            'urlname_suffix':
            'serialization',
        },
    )

    search_fields = (
        'id',
        'title',
        'headline',
        'description',
        'subject_name__name',
        'subject_name__alias',
        'credit',
        'type',
    )

    prefetch_related = ('pictureoftheweek_set', )
    archive_list_only_fields = ('id', 'title', 'width', 'height', 'credit',
                                'lang', 'source', 'content_server',
                                'content_server_ready')

    class Queries(object):
        default = ImageAllPublicQuery(browsers=('normal', 'viewall', 'json'),
                                      verbose_name=ugettext_noop("Images"))
        category = WebCategoryPublicQuery(
            relation_field='web_category',
            browsers=('normal', 'viewall', 'json'),
            verbose_name=ugettext_noop("Image Archive: %(title)s"),
            category_type='Images',
            feed_name='category')
        top100 = ImageAllPublicQuery(
            browsers=('top100', 'json', 'minijson', 'fbtop100', 'fs'),
            verbose_name=ugettext_noop("Top 100 Images"),
            searchable=False,
            feed_name='top100')
        bestof = ImageAllPublicQuery(
            browsers=('viewall', 'json'),
            verbose_name=ugettext_noop("Hall Of Fame"),
            searchable=False)
        zoomable = ZoomableQuery(browsers=('normal', 'viewall', 'json'),
                                 verbose_name=ugettext_noop("Zoomable Images"))
        wallpapers = WallpaperQuery(browsers=('normal', 'viewall', 'json'),
                                    verbose_name=ugettext_noop("Wallpapers"))
        wwt = WWTQuery(browsers=('normal', 'viewall', 'json'),
                       verbose_name=ugettext_noop("WorldWide Telescope"))
        print_layouts = PrintLayoutQuery(
            browsers=('normal', 'viewall', 'json'),
            verbose_name=ugettext_noop("Print Layouts"))
        search = AdvancedSearchQuery(
            browsers=('normal', 'viewall', 'json'),
            verbose_name=ugettext_noop("Advanced Image Search"),
            searchable=False)
        staging = ImageStagingQuery(
            browsers=('normal', 'viewall', 'json'),
            verbose_name=ugettext_noop("Images (staging)"))
        embargo = ImageEmbargoQuery(
            browsers=('normal', 'viewall', 'json'),
            verbose_name=ugettext_noop("Images (embargoed)"))

    class Browsers(object):
        normal = NormalBrowser(paginate_by=50)
        viewall = ViewAllBrowser(paginate_by=250)
        top100 = ViewAllBrowser(index_template='index_top100.html',
                                paginate_by=100)
        fbtop100 = ViewAllBrowser(index_template='index_top100.html',
                                  paginate_by=5)
        fs = ViewAllBrowser(index_template='top100_fs.html', paginate_by=10)
        json = SerializationBrowser(serializer=AVMImageSerializer,
                                    emitter=JSONEmitter,
                                    paginate_by=100,
                                    display=False,
                                    verbose_name=ugettext_noop("JSON"))
        minijson = SerializationBrowser(serializer=MiniImageSerializer,
                                        emitter=JSONEmitter,
                                        paginate_by=10,
                                        display=False,
                                        verbose_name=ugettext_noop("JSON"))

    class ResourceProtection(object):
        unpublished = (UnpublishedQuery, security.UNPUBLISHED_PERMS)
        staging = (StagingQuery, security.STAGING_PERMS)
        embargo = (EmbargoQuery, security.EMBARGO)

    class AdvancedSearch(object):
        minimum_size = ImageSizeSearchField(label=_("Minimum size"))
        ranking = PrioritySearchField(label=_("Ranking"))
        instrument = AVMImageInstrumentSearchField(label=_("Instrument used"))
        facility = AVMImageFacilitySearchField(label=_("Facility used"))
        additional_search_items = SeparatorField(
            label=_("Additional search terms"))
        id = IdSearchField(label=_('Image ID'))
        release_id = RelatedIdSearchField(label=_('Release ID'),
                                          model_field='release__id')
        published_since = DateSinceSearchField(label=_("Published since"),
                                               model_field='release_date')
        published_until = DateUntilSearchField(label=_("Published until"),
                                               model_field='release_date')
        title = TextSearchField(label=_("Title"), model_field='title')
        subject_name = AVMSubjectNameSearchField(label=_("Subject name"))
        description = TextSearchField(label=_("Description"),
                                      model_field='description')
        credit = TextSearchField(label=_("Credit"), model_field='credit')
        type = AVMTypeSearchField(label=_("Type"), )
        category = AVMSubjectCategorySearchField(label=_("Category"), )
        zoomable = BooleanSearchField(model_field='zoomify',
                                      label=_("Zoomable available"))
        wallpapers = BooleanSearchField(model_field='wallpapers',
                                        label=_("Wallpaper available"))
        colours = ManyToManySearchField(
            label=_("Colours"),
            model_field='colors__id',
            choices_func=lambda: [(c.id, _(c.name))
                                  for c in Color.objects.all()])
        fov = FOVSearchField(label=_("Field of View"))

        class Meta:
            verbose_name = ugettext_noop("Advanced Image Search")

    class Import(object):
        form = ImageImportForm
        uploadable = True
        metadata = 'original'
        scan_directories = [
            ('original', ('.tif', '.psb', '.jpg')),
            ('banner1920', ('.jpg', )),
            ('newsfeature', ('.jpg', )),
        ]
        actions = [
            move_resources,
            process_image_derivatives(),
            compute_archive_checksums(),
            sync_content_server(),
        ]

    @staticmethod
    def extra_context(obj, lang=None):
        # The colors should be ordered as defined in SPECTRAL_COLOR_ASSIGNMENT_CHOICES
        args = []
        for i, (color, _name) in enumerate(SPECTRAL_COLOR_ASSIGNMENT_CHOICES):
            args.append(When(spectral_color_assignment=color, then=Value(i)))

        imageexposures = obj.imageexposure_set.all().select_related(
            'facility', 'instrument').annotate(color_order=Case(
                *args, output_field=IntegerField())).order_by('color_order')

        has_wavelength = False

        for e in imageexposures:
            if e.spectral_central_wavelength:
                has_wavelength = True
                break

        # we are being conservative about the exposure time: only display it if it is simple
        exposure_time = None
        if len(imageexposures) == 1:
            exposure_time = imageexposures[0].temporal_integration_time

        return {
            'imageexposures': imageexposures,
            'has_wavelength': has_wavelength,
            'exposure_time': exposure_time,
            'translations': obj.get_translations(),
        }

    @staticmethod
    def queryset(request, model):
        """
        Query set for detail view. Make sure we select related releases right away,
        as we need the later on.
        """
        return model._default_manager.all()

    @staticmethod
    def feeds():
        from djangoplicity.media.feeds import ImageFeed, Top100Feed, VAMPFeed
        feed_dict = {
            '': ImageFeed,
            'category': ImageFeed,
            'top100': Top100Feed,
            'vamp': VAMPFeed,
        }
        return feed_dict

    @staticmethod
    def handle_import(obj, id=None, data=None, form_values=None):
        """
        Copy values from import form to object
        """
        if data is None:
            data = {}
        if form_values is None:
            form_values = {}

        from djangoplicity.archives.importer.utils import handle_import
        obj = handle_import(obj,
                            id=id,
                            data=data,
                            form_values=form_values,
                            save=False)

        # Extra fields being handled
        if not obj.description:
            obj.description = ''
        if not obj.credit:
            obj.credit = ''

        obj.wallpapers = form_values["wallpapers"]
        obj.zoomify = form_values["zoomify"]
        if 'credit' in form_values:
            obj.credit = form_values['credit']

        # File Metadata extraction
        try:
            file_path = data["files"][data['formats'].index('original')]

            obj.file_type = get_file_type(file_path)
            obj.file_size = long(os.path.getsize(file_path)) / 1024

            try:
                obj.width, obj.height = identify_image(file_path)
            except IOError:
                pass
        except ValueError:
            pass

        obj.save()
        return obj
class AnnouncementOptions( ArchiveOptions ):
    description_template = 'archives/announcement/object_description.html'

    urlname_prefix = 'announcements'

    admin = (
        (
            ugettext_noop(u'Admin'), {
                'links': (
                    admin_edit_for_site('admin_site', translation_proxy=AnnouncementProxy),
                    admin_add_translation('admin_site', translation_proxy=AnnouncementProxy)
                ),
                'fields': ( published, 'release_date', 'last_modified', 'created' ),
            }
        ),
    )

    info = (
        ( ugettext_noop(u'About the Announcement'), { 'fields': ( object_id,)  } ),
    )

    downloads = (
        ( ugettext_noop(u'Images'), {'resources': ( 'original', 'large', 'screen'  ), 'icons': { 'original': 'phot', 'large': 'phot', 'medium': 'phot', 'screen': 'phot'  } } ),
        ( ugettext_noop(u'Downloads'), {'resources': ( 'pdf', 'pdfsm', 'sciencepaper' ), 'icons': { 'pdf': 'doc', 'pdfsm': 'doc', 'sciencepaper': 'doc' } } ),

    )

    detail_views = (
        { 'url_pattern': 'api/(?P<serializer>json)/', 'view': SerializationDetailView( serializer=AnnouncementSerializer, emitters=[JSONEmitter] ), 'urlname_suffix': 'serialization', },
    )

    search_fields = ( 'id', 'title', 'description', 'contacts', 'links', )

    class Queries( object ):
        default = AllPublicQuery( browsers=( 'normal', 'viewall', 'json', 'ical' ), verbose_name=ugettext_noop("Announcements"), feed_name="default" )
        featured = FeaturedQuery( browsers=( 'normal', 'viewall', 'json', 'ical' ), verbose_name=ugettext_noop("Featured Announcements"), feed_name="default", include_in_urlpatterns=False )
        embargo = EmbargoQuery( browsers=( 'normal', 'viewall', 'json', 'ical' ), verbose_name=ugettext_noop("Embargoed Announcements") )
        staging = StagingQuery( browsers=( 'normal', 'viewall', 'json', 'ical' ), verbose_name=ugettext_noop("Announcements (Staging)") )
        year = YearQuery( browsers=( 'normal', 'viewall' ), verbose_name=ugettext_noop("Announcements %d"), feed_name="default" )

    class Browsers( object ):
        normal = ListBrowser()
        viewall = ListBrowser( verbose_name=ugettext_noop( u'View all' ), paginate_by=100 )
        json = SerializationBrowser( serializer=AnnouncementSerializer, emitter=JSONEmitter, paginate_by=20, display=False, verbose_name=ugettext_noop( "JSON" ) )
        ical = SerializationBrowser( serializer=ICalAnnouncementSerializer, emitter=ICalEmitter, paginate_by=100, display=False, verbose_name=ugettext_noop( "iCal" ) )

    class ResourceProtection ( object ):
        unpublished = ( UnpublishedQuery, security.UNPUBLISHED_PERMS )
        staging = ( StagingQuery, security.STAGING_PERMS )
        embargo = ( EmbargoQuery, security.EMBARGO )

    class Display():
        multiple_announcements = DisplayTemplate( 'template', '{{obj.title}}<br/><a href="{{site_url_prefix}}{{obj.get_absolute_url}}">{{site_url_prefix}}{{obj.get_absolute_url}}</a>', name='Multiple Announcements list' )
        multiple_announcements_text = DisplayTemplate( 'template', '{{obj.title}}<br/>{{site_url_prefix}}{{obj.get_absolute_url}}', name='Multiple Announcements list (plaintext)' )
        targeted_email_from = DisplayTemplate( 'file', 'archives/announcement/email/from.txt', name='Targeted email from' )
        targeted_email_subject = DisplayTemplate( 'file', 'archives/announcement/email/subject.txt', name='Targeted email subject' )
        targeted_email = DisplayTemplate( 'file', 'archives/announcement/email/html.html', name='Targeted email' )
        translation_available_announcement = DisplayTemplate( 'file', 'archives/announcement/email/translations_available_announcement.html', name='Announcement available for translation' )

    @staticmethod
    def feeds():
        from djangoplicity.announcements.feeds import AnnouncementFeed, AnnouncementFeaturedFeed
        return {
            '': AnnouncementFeed,
            'featured': AnnouncementFeaturedFeed,
        }

    @staticmethod
    def process_object_list( object_list ):
        """
        Preprocess a list of Announcements to fetch the main images for all of them.
        """
        Announcement.store_main_visuals( object_list )

    @staticmethod
    def extra_context( obj, lang=None ):
        images = related_archive_items( Announcement.related_images, obj )
        videos = related_archive_items( Announcement.related_videos, obj, has_main_visual=False )
        comparisons = related_archive_items( Announcement.related_comparisons, obj, has_main_visual=False )
        main_visual = main_visual_translated(obj.main_visual, images + videos)

        # # main_visual =
        # from djangoplicity.media.models.images import Image
        # main_visual = Image.objects.language(obj.lang).get(source=obj.main_visual)
        return {
            'main_visual': main_visual,
            'images': images,
            'videos': videos,
            'comparisons': comparisons,
            'translations': obj.get_translations(),
        }
class ImageComparisonOptions(ArchiveOptions):
    """
    Archive options definitions for image comparison archive.
    """
    description_template = 'archives/imagecomparison/object_description.html'

    urlname_prefix = "imagecomparisons"

    detail_views = (
        {
            'url_pattern':
            'api/(?P<serializer>json)/',
            'view':
            SerializationDetailView(serializer=ImageComparisonSerializer,
                                    emitters=[JSONEmitter]),
            'urlname_suffix':
            'serialization',
        },
        {
            'url_pattern': 'fullscreen/',
            'view': views.ImageComparisonFullscreenDetailView(),
            'urlname_suffix': 'fullscreen',
        },
    )

    info = ((ugettext_noop(u'About the Image Comparison'), {
        'fields': (object_id, release_date, related_releases),
    }), )

    admin = ((ugettext_noop(u'Admin'), {
        'links': (
            admin_edit_for_site('admin_site',
                                translation_proxy=ImageComparisonProxy),
            admin_add_translation('admin_site',
                                  translation_proxy=ImageComparisonProxy),
        ),
        'fields': (published, 'embargo_date', 'release_date_owner',
                   'last_modified', 'created', priority),
    }), )

    downloads = ((ugettext_noop(u'Images'), {
        'resources': (
            'original',
            'large',
            'screen',
        ),
        'icons': {
            'original': 'phot',
            'large': 'phot',
            'medium': 'phot',
            'screen': 'phot'
        }
    }), )

    search_fields = (
        'id',
        'title',
        'description',
        'credit',
    )

    class Queries(object):
        default = AllPublicQuery(
            browsers=('normal', 'viewall', 'json', 'ical'),
            verbose_name=ugettext_noop("Image Comparisons"),
            feed_name="default")
        embargo = EmbargoQuery(
            browsers=('normal', 'viewall', 'json', 'ical'),
            verbose_name=ugettext_noop("Image Comparisons (embargoed)"))
        staging = StagingQuery(
            browsers=('normal', 'viewall', 'json', 'ical'),
            verbose_name=ugettext_noop("Image Comparisons (staging)"))
        year = YearQuery(browsers=('normal', 'viewall', 'json', 'ical'),
                         verbose_name=ugettext_noop("Image Comparisons %d"),
                         feed_name="default")

    class Browsers(object):
        normal = NormalBrowser(paginate_by=52)
        viewall = ViewAllBrowser(paginate_by=100)
        json = SerializationBrowser(serializer=ImageComparisonSerializer,
                                    emitter=JSONEmitter,
                                    paginate_by=20,
                                    display=False,
                                    verbose_name=ugettext_noop("JSON"))
        ical = SerializationBrowser(serializer=ICalImageComparisonSerializer,
                                    emitter=ICalEmitter,
                                    paginate_by=100,
                                    display=False,
                                    verbose_name=ugettext_noop("iCal"))

    class ResourceProtection(object):
        unpublished = (UnpublishedQuery, security.UNPUBLISHED_PERMS)
        staging = (StagingQuery, security.STAGING_PERMS)
        embargo = (EmbargoQuery, security.EMBARGO)

    class Import(object):
        form = ImageComparisonImportForm
        uploadable = True
        metadata = 'original'
        scan_directories = [
            ('original', (
                '.jpg',
                '.jpeg',
                '.tif',
                '.tiff',
                '.png',
            )),
        ]
        actions = [
            move_resources,
            process_image_derivatives(),
        ]

    @staticmethod
    def extra_context(obj, lang=None):
        return {
            'image_before':
            related_archive_item_fk(ImageComparison.image_before, obj),
            'image_after':
            related_archive_item_fk(ImageComparison.image_after, obj),
            'translations':
            obj.get_translations(),
        }

    @staticmethod
    def handle_import(obj, id=None, data={}, form_values={}):
        """
        Copy values from import form to object
        """
        from djangoplicity.archives.importer.utils import handle_import
        obj = handle_import(obj,
                            id=id,
                            data=data,
                            form_values=form_values,
                            save=False)

        obj.image_before = None
        obj.image_after = None
        obj.save()

        obj.image_before = form_values['image_before']
        obj.image_after = form_values['image_after']
        obj.save()

        return obj
class VideoOptions( ArchiveOptions ):
    description_template = 'archives/video/object_description.html'

    urlname_prefix = "videos"

    info = (
        (
            ugettext_noop(u'About the Video'), {
                'fields': (object_id, object_language, release_date,
                    related_releases, related_announcements, duration,
                    frame_rate)
            }
        ),
        (
            ugettext_noop(u'About the Object'), {
                'fields': (subject_name, subject_category, web_categories)
            }
        ),
    )

    admin = (
        (
            ugettext_noop(u'Admin'), {
                'links': (
                    admin_edit_for_site('admin_site', translation_proxy=VideoProxy),
                    admin_add_translation('admin_site', translation_proxy=VideoProxy),
                ),
                'fields': ( published, featured, 'release_date_owner', 'last_modified', 'created', priority ),
            }
        ),
    )

    downloads = (
        ( ugettext_noop('Fulldome'), {
            'resources': ( 'dome_8kmaster', 'dome_4kmaster', 'dome_2kmaster', 'dome_mov' ),
            'icons': {
                'dome_8kmaster': 'dome',
                'dome_4kmaster': 'dome',
                'dome_2kmaster': 'dome',
                'dome_mov': 'dome',
                }
        } ),
        ( ugettext_noop('Cylindrical'), {
            'resources': ( 'cylindrical_16kmaster', 'cylindrical_8kmaster', 'cylindrical_4kmaster' ),
            'icons': {
                'cylindrical_16kmaster': 'dome',
                'cylindrical_8kmaster': 'dome',
                'cylindrical_4kmaster': 'dome',
                }
        } ),
        (ugettext_noop('VR'), {
            'resources': ('vr_8k', 'vr_4k'),
            'icons': {
                'vr_8k': 'vr',
                'vr_4k': 'vr',
                }
        }),
        ( ugettext_noop('Fulldome Preview'), {
            'resources': ( 'dome_preview', ),
            'icons': {
                'dome_preview': 'dome',
                }
        } ),
        ( ugettext_noop('Ultra HD'), {
            'resources': ( 'ultra_hd', 'ultra_hd_h265', ),
            'icons': {
                'ultra_hd': 'movie',
                'ultra_hd_h265': 'movie',
                }
        } ),
        ( ugettext_noop('HD'), {
            'resources': ( shadowbox_link('hd_and_apple', 1280, 720, player='qt'), 'hd_1080p25_screen', 'ext_highres', 'ext_playback'),
            'icons': {
                'shadowbox_link': 'movie',
                'hd_1080p25_screen': 'movie',
                }
        } ),
        ( ugettext_noop( u'BitTorrent Download' ), {
            'resources': ( video_magnet_uri_link, ),
            'icons': { 'video_magnet_uri_link': 'magnet', }
        } ),
        ( ugettext_noop('Large'), {
            'resources': ( shadowbox_link('large_qt', 720, 405), ),
            'icons': { 'shadowbox_link': 'movie', }
        } ),
        ( ugettext_noop('Medium'), {
            'resources': ( shadowbox_link('medium_podcast', 640, 360), shadowbox_link('medium_mpeg1', 640, 360), shadowbox_link( 'medium_flash', 640, 360 ), ),
            'icons': {
                'shadowbox_link': 'movie',
                'medium_mpeg1': 'movie',
                'medium_podcast': 'movie',
                }
        } ),
        ( ugettext_noop(u'Small'), {
            'resources': ( shadowbox_link( 'small_flash', 320, 180 ), shadowbox_link( 'small_qt', 320, 180), ),
            'icons': {
                'shadowbox_link': 'movie',
                'small_qt': 'movie',
                }
        } ),
        ( ugettext_noop('For Broadcasters'), {
            'resources': ( 'ultra_hd_broadcast', 'hd_1080p25_broadcast', 'hd_broadcast_720p50', 'hd_broadcast_720p25', 'broadcast_sd', 'broadcast_sd_old', ),
            'icons': {
                'broadcast_sd': 'movie',
                'broadcast_sd_old': 'movie',
                'hd_broadcast_720p25': 'movie',
                'hd_broadcast_720p50': 'movie',
                'hd_1080p25_broadcast': 'movie',
                'ultra_hd_broadcast': 'movie',
                }
        } ),
        ( ugettext_noop('Script'), {
            'resources': ( 'script', ),
            'icons': {'script': 'doc' }
        } ),
        ( ugettext_noop('QuickTime VR'), {
            'resources': ( shadowbox_link('qtvr', 1280, 720, player='qt'), ),
            'icons': { 'shadowbox_link': 'movie' }
        } ),
        ( ugettext_noop(u'Legacy Videos'), {
            'resources': ( 'old_video', ),
            'icons': { 'old_video': 'movie' }
        } ),
    )

    detail_views = (
        { 'url_pattern': 'api/(?P<serializer>xml|json)/', 'view': SerializationDetailView( serializer=VideoSerializer, emitters=[JSONEmitter] ), 'urlname_suffix': 'serialization', },
    )

    search_fields = ( 'id', 'title', 'headline', 'description', 'subject_name__name', 'subject_name__alias', 'facility__name', 'credit', 'type' )
    archive_list_only_fields = (
        'id', 'title', 'credit', 'lang', 'source', 'content_server',
        'content_server_ready', 'youtube_video_id', 'use_youtube'
    )

    @staticmethod
    def feeds():
        from djangoplicity.media.feeds import VideoPodcastFeed
        feed_dict = {
            '': VideoPodcastFeed,
            'category': VideoPodcastFeed,
        }
        return feed_dict

    class Queries(object):
        default = VideoQuery( browsers=( 'normal', 'viewall', 'json' ), verbose_name=ugettext_noop("Videos") )
        category = VideoWebCategoryPublicQuery( relation_field='web_category', browsers=( 'normal', 'viewall', 'json' ), verbose_name=ugettext_noop("Video Archive: %(title)s"), category_type='Videos', feed_name="category", featured=[settings.VIDEOS_FEATURED_SUBJECT] if hasattr(settings, 'VIDEOS_FEATURED_SUBJECT') else [])
        search = AdvancedSearchQuery( browsers=( 'normal', 'viewall', 'json' ), verbose_name=ugettext_noop("Advanced Video Search"), searchable=False )
        staging = StagingQuery( browsers=( 'normal', 'viewall', 'json' ), verbose_name=ugettext_noop("Videos (staging)") )
        embargo = EmbargoQuery( browsers=( 'normal', 'viewall', 'json' ), verbose_name=ugettext_noop("Videos (embargoed)") )

    class AdvancedSearch (object):
        minimum_size = VideoSizeSearchField( label=_( "Minimum size" ) )
        ranking = PrioritySearchField( label=_( "Ranking" ) )
        additional_search_items = SeparatorField( label=_("Additional search terms") )
        id = IdSearchField( label=_('Image ID') )
        release_id = RelatedIdSearchField( label=_('Release ID'), model_field='release__id' )
        published_since = DateSinceSearchField( label=_( "Published since" ), model_field='release_date' )
        published_until = DateUntilSearchField( label=_( "Published until" ), model_field='release_date' )
        title = TextSearchField( label=_( "Title" ), model_field='title' )
        subject_name = AVMSubjectNameSearchField( label=_( "Subject name" ) )
        description = TextSearchField( label=_( "Description" ), model_field='description' )
        credit = TextSearchField( label=_( "Credit" ), model_field='credit' )
        type = AVMTypeSearchField( label=_( "Type" ), )
        category = AVMSubjectCategorySearchField( label=_( "Category" ), )

        class Meta:
            verbose_name = ugettext_noop("Advanced Video Search")

    class Browsers(object):
        normal = NormalBrowser( paginate_by=50 )
        viewall = ViewAllBrowser( paginate_by=100 )
        json = SerializationBrowser( serializer=VideoSerializer, emitter=JSONEmitter, paginate_by=100, display=False, verbose_name=ugettext_noop( "JSON" ) )

    class ResourceProtection( object ):
        unpublished = ( UnpublishedQuery, security.UNPUBLISHED_PERMS )
        staging = ( StagingQuery, security.STAGING_PERMS )
        embargo = ( EmbargoQuery, security.EMBARGO )

    class Import( object ):
        form = VideoImportForm
        metadata = 'original'
        uploadable = True
        scan_directories = [
            # Image
            ( 'original', ( '.jpg', '.jpeg', '.tif', '.png', ) ),
            # Dome
            ( 'dome_8kmaster', ( '.avi', '.zip', ) ),
            ( 'dome_4kmaster', ( '.avi', '.zip', ) ),
            ( 'dome_2kmaster', ( '.avi', '.zip', ) ),
            ( 'dome_mov', ( '.mov', '.mp4' ) ),
            ( 'vr_8k', ( '.mp4', ) ),
            ( 'vr_8k', ( '.mp4', ) ),
            ( 'dome_preview', ( '.mp4', ) ),
            # Cylindrical
            ( 'cylindrical_preview', ( '.mp4', ) ),
            ( 'cylindrical_4kmaster', ( '.zip', ) ),
            ( 'cylindrical_8kmaster', ( '.zip', ) ),
            ( 'cylindrical_16kmaster', ( '.zip', ) ),
            # Ultra HD
            ( 'ultra_hd_broadcast', ( '.avi', ) ),
            ( 'ultra_hd_h265', ( '.mkv', '.mp4' ) ),
            ( 'ultra_hd', ( '.mp4', ) ),
            # HD
            ( 'hd_and_apple', ( '.mp4', '.m4v' ) ),
            ( 'hd_1080p25_screen', ( '.mp4' ) ),
            # Broadcast
            ( 'broadcast_sd', ( '.avi', '.mxf', '.mov', '.mp4' ) ),
            ( 'hd_broadcast_720p25', ( '.mxf', '.m2t', '.mov' ) ),
            ( 'hd_broadcast_720p50', ( '.mxf', '.m2t', '.mov' ) ),
            ( 'hd_1080p25_broadcast', ( '.avi', '.mxf' ) ),
            # Large
            ( 'large_qt', ( '.mov', ) ),
            # Medium
            ( 'medium_flash', ( '.flv', ) ),
            ( 'medium_mpeg1', ( '.mpg', ) ),
            ( 'medium_podcast', ( '.m4v', '.mp4') ),
            # Small
            ( 'small_flash', ( '.flv', ) ),
            ( 'small_qt', ( '.mov', ) ),
            # Other
            ( 'ext_highres', ('.m4v', '.flv', '.mov', '.avi', '.mpeg', '.mp4', '.mpg') ),
            ( 'ext_playback', ('.m4v', '.flv', '.mov', '.avi', '.mpeg', '.mp4', '.mpg') ),
        ]
        actions = [
            remove_old_resources( [
                'broadcast',
                'broadcast_sd_old',
                'h264',
                'hd720p_broadcast',
                'hd720p_screen',
                'hd1080p_broadcast',
                'hd1080p_screen',
                'mov_medium',
                'mov_small',
                'mpg_medium',
                'mpg_small',
                'vodcast',
                'dome',
                'broadcast_sd_part1',
                'broadcast_sd_part2',
                'broadcast_sd_part3',
                'broadcast_sd_part4',
                'broadcast_sd_part5',
                'broadcast_sd_part6',
                'broadcast_sd_part7',
                'broadcast_sd_part8',
                'broadcast_sd_part9',
                'broadcast_sd_part10',
                'hd_broadcast_720p25_part1',
                'hd_broadcast_720p25_part2',
                'hd_broadcast_720p25_part3',
                'hd_broadcast_720p25_part4',
                'hd_broadcast_720p25_part5',
                'hd_broadcast_720p25_part6',
                'hd_broadcast_720p25_part7',
                'hd_broadcast_720p25_part8',
                'hd_broadcast_720p25_part9',
                'hd_broadcast_720p25_part10',
                'hd_broadcast_720p50_part1',
                'hd_broadcast_720p50_part2',
                'hd_broadcast_720p50_part3',
                'hd_broadcast_720p50_part4',
                'hd_broadcast_720p50_part5',
                'hd_broadcast_720p50_part6',
                'hd_broadcast_720p50_part7',
                'hd_broadcast_720p50_part8',
                'hd_broadcast_720p50_part9',
                'hd_broadcast_720p50_part10',
            ] + getattr( settings, 'VIDEOS_FORMATS_REMOVE', [] ) ),
            move_resources,
            rename_resource_ext( 'hd_and_apple', 'mp4', 'm4v' ),
            enable_faststart( 'hd_and_apple', 'large_qt' ),
            fragment_mp4('hd_1080p25_screen'),
            embed_subtitles( getattr( settings, 'VIDEOS_SUBTITLES_FORMATS', [] ) ),
            video_extras(),
            generate_thumbnail_action(),
            process_image_derivatives(),
            compute_archive_checksums(),
            sync_content_server(extra_formats=['videoframe']),
            upload_youtube_action()
        ]

    @staticmethod
    def queryset( request, model ):
        """
        Query set for detail view. Make sure we select related releases right away,
        as we need the later on.
        """
        return model._default_manager.all()

    @staticmethod
    def handle_import( obj, id=None, data=None, form_values=None ):
        """
        Create a video when importing an Video file.
        """
        if data is None:
            data = {}
        if form_values is None:
            form_values = {}

        from djangoplicity.archives.importer.utils import handle_import
        obj = handle_import( obj, id=id, data=data, form_values=form_values, save=True )

        if 'credit' in form_values:
            obj.credit = form_values['credit']

        # Once all videos have been re-encoded and imported, the next two lines can be removed (eso, spacetelescope, iau).
        from djangoplicity.metadata.models import TaggingStatus
        ts, _ = TaggingStatus.objects.get_or_create( slug='video_imported', name='Video imported' )
        obj.tagging_status.add( ts )

        obj.save()
        return obj