def overview(request): collections = filter_by_access(request.user, Collection.objects.exclude(hidden=True)) collections = apply_collection_visibility_preferences( request.user, collections) collections = collections.annotate(num_records=Count('records')) children = dict() overview_thumbs = dict() for coll in collections: c = filter_by_access(request.user, coll.children.exclude(hidden=True)) c = apply_collection_visibility_preferences(request.user, c) children[coll.id] = c for record in Record.objects.filter(id__in=FieldValue.objects.filter( field=get_system_field(), value='overview', index_value='overview', ).values('record'), ): for coll in record.collection_set.all().values_list('id', flat=True): overview_thumbs[coll] = record return render_to_response('overview.html', { 'collections': [(coll, children[coll.id], overview_thumbs.get(coll.id)) for coll in collections] }, context_instance=RequestContext(request))
def get_image(media): logging.debug('get_image: %s (%s)' % (media.get_absolute_file_path(), media.mimetype)) image = None if media.mimetype.startswith('image/'): image = media.load_file() elif media.mimetype.startswith('video/'): # retrieve offset if available try: offset = int( media.record.fieldvalue_set.filter( field=get_system_field(), label='thumbnail-offset', )[0].value) except (IndexError, ValueError): offset = 5 image = capture_video_frame(media.get_absolute_file_path(), offset=offset) elif media.mimetype.startswith('audio/'): image = render_audio_waveform_by_mimetype( media.get_absolute_file_path(), media.mimetype) elif media.mimetype == 'application/pdf': image = render_pdf(media.get_absolute_file_path()) elif media.url.endswith('.pptx'): image = thumbnail_from_pptx(media.get_absolute_file_path()) return image
def get_image(media): logging.debug('get_image: %s (%s)' % ( media.get_absolute_file_path(), media.mimetype)) image = None if media.mimetype.startswith('image/'): image = media.load_file() elif media.mimetype.startswith('video/'): # retrieve offset if available try: offset = int(media.record.fieldvalue_set.filter( field=get_system_field(), label='thumbnail-offset', )[0].value) except (IndexError, ValueError): offset = 5 image = capture_video_frame( media.get_absolute_file_path(), offset=offset) elif media.mimetype.startswith('audio/'): image = render_audio_waveform_by_mimetype( media.get_absolute_file_path(), media.mimetype) elif media.mimetype == 'application/pdf': image = render_pdf(media.get_absolute_file_path()) elif media.url.endswith('.pptx'): image = thumbnail_from_pptx(media.get_absolute_file_path()) return image
def get_markers(record): markers, created = record.fieldvalue_set.get_or_create( field=get_system_field(), label='audio-text-sync-markers', defaults=dict( hidden=True, ) ) return markers
def get_image(media): if media.mimetype.startswith('image/'): return media.load_file() if media.mimetype.startswith('video/'): # retrieve offset if available try: offset = int(media.record.fieldvalue_set.filter( field=get_system_field(), label='thumbnail-offset', )[0].value) except IndexError, ValueError: offset = 5 return capture_video_frame(media.get_absolute_file_path(), offset=offset)
def get_image(media): print 'media.mimetype = %s' % media.mimetype if media.mimetype.lower().startswith('image/'): return media.load_file() if media.mimetype.lower().startswith('video/'): # retrieve offset if available try: offset = int(media.record.fieldvalue_set.filter( field=get_system_field(), label='thumbnail-offset', )[0].value) except IndexError, ValueError: offset = 5 return capture_video_frame(media.get_absolute_file_path(), offset=offset)
def get_image(media): logging.debug('get_image: %s (%s)' % (media.get_absolute_file_path(), media.mimetype)) image = None if media.mimetype.startswith('image/'): image = media.load_file() elif media.mimetype.startswith('video/'): # retrieve offset if available try: offset = int(media.record.fieldvalue_set.filter( field=get_system_field(), label='thumbnail-offset', )[0].value) except IndexError, ValueError: offset = 5 image = capture_video_frame(media.get_absolute_file_path(), offset=offset)
def get_image(media): logging.debug('get_image: %s (%s)' % (media.get_absolute_file_path(), media.mimetype)) image = None if media.mimetype.startswith('image/'): image = media.load_file() elif media.mimetype.startswith('video/'): # retrieve offset if available try: offset = int( media.record.fieldvalue_set.filter( field=get_system_field(), label='thumbnail-offset', )[0].value) except IndexError, ValueError: offset = 5 image = capture_video_frame(media.get_absolute_file_path(), offset=offset)
def _fetch_works_with_primary_records(self): if self._works_with_primary_records is not None: return records = FieldValue.objects.filter( field=get_system_field(), label='primary-work-record', ).values('record') # works that have primary records self._works_with_primary_records = set( FieldValue.objects.filter( field__standard__prefix='dc', field__name='relation', refinement='IsPartOf', record__in=records, ).distinct().order_by().values_list('value', flat=True) )
def overview(request): collections = filter_by_access( request.user, Collection.objects.exclude(hidden=True)) collections = apply_collection_visibility_preferences( request.user, collections) collections = collections.annotate( num_records=Count('records')) children = dict() overview_thumbs = dict() for coll in collections: c = filter_by_access(request.user, coll.children.exclude(hidden=True)) c = apply_collection_visibility_preferences( request.user, c ) children[coll.id] = c for record in Record.objects.filter( id__in=FieldValue.objects.filter( field=get_system_field(), value='overview', index_value='overview', ).values('record'), ): for coll in record.collection_set.all().values_list('id', flat=True): overview_thumbs[coll] = record return render_to_response( 'overview.html', { 'collections': [ (coll, children[coll.id], overview_thumbs.get(coll.id)) for coll in collections ] }, context_instance=RequestContext(request))
def handle(self, *args, **kwargs): system_field = get_system_field() collections = map(int, kwargs.get('collections') or list()) mapping_file = kwargs.get('mapping_file') if not collections: print "--collection is a required parameter" return if not mapping_file: print "--mapping is a required parameter" return mappings = dict() with open(mapping_file, 'r') as csvfile: reader = csv.DictReader(csvfile) for row in reader: mappings[row['Identifier']] = (row['Work'], row['Primary']) related_field = Field.objects.get( standard__prefix='dc', name='relation', ) existing_works = FieldValue.objects.filter( record__collection__in=collections, field=related_field, refinement='IsPartOf', ) # Clean out old relations print "Deleting old works info" existing_works.delete() id_fields = standardfield_ids('identifier', equiv=True) print "Fetching records" identifiers = FieldValue.objects.select_related('record').filter( record__collection__in=collections, field__in=id_fields, ) pb = ProgressBar(identifiers.count()) # Insert new relations for count, identifier in enumerate(identifiers): work, isprimary = mappings.get(identifier.value, (None, False)) isprimary = isprimary == 'True' if not work: print "Warning: no entry found for identifier '%s'" % \ identifier.value continue FieldValue.objects.create(record=identifier.record, field=related_field, refinement='IsPartOf', value=work, hidden=True) fv = list( FieldValue.objects.filter(record=identifier.record, field=system_field, label='primary-work-record')) if len(fv) > 0: if not isprimary: for f in fv: f.delete() elif isprimary: FieldValue.objects.create( record=identifier.record, field=system_field, label='primary-work-record', value=work, hidden=True, ) pb.update(count) pb.done()
def __init__(self): self._clean_string_re = re.compile('[\x00-\x08\x0b\x0c\x0e-\x1f]') self._record_type = int(ContentType.objects.get_for_model(Record).id) self.system_field = get_system_field()
def handle(self, *args, **kwargs): system_field = get_system_field() collections = map(int, kwargs.get('collections') or list()) mapping_file = kwargs.get('mapping_file') if not collections: print "--collection is a required parameter" return if not mapping_file: print "--mapping is a required parameter" return mappings = dict() with open(mapping_file, 'r') as csvfile: reader = csv.DictReader(csvfile) for row in reader: mappings[row['Identifier']] = (row['Work'], row['Primary']) related_field = Field.objects.get( standard__prefix='dc', name='relation', ) existing_works = FieldValue.objects.filter( record__collection__in=collections, field=related_field, refinement='IsPartOf', ) # Clean out old relations print "Deleting old works info" existing_works.delete() id_fields = standardfield_ids('identifier', equiv=True) print "Fetching records" identifiers = FieldValue.objects.select_related('record').filter( record__collection__in=collections, field__in=id_fields, ) pb = ProgressBar(identifiers.count()) # Insert new relations for count, identifier in enumerate(identifiers): work, isprimary = mappings.get(identifier.value, (None, False)) isprimary = isprimary == 'True' if not work: print "Warning: no entry found for identifier '%s'" % \ identifier.value continue FieldValue.objects.create( record=identifier.record, field=related_field, refinement='IsPartOf', value=work, hidden=True ) fv = list(FieldValue.objects.filter( record=identifier.record, field=system_field, label='primary-work-record' )) if len(fv) > 0: if not isprimary: for f in fv: f.delete() elif isprimary: FieldValue.objects.create( record=identifier.record, field=system_field, label='primary-work-record', value=work, hidden=True, ) pb.update(count) pb.done()