def __init__(self, *args, **kwargs): """ Dynamically generate help text. """ source = kwargs.pop('source') super(ImageUploadOptionsForm, self).__init__(*args, **kwargs) # Dynamically generate help text. # Show the filename format that should be used, # and an example of a filename adhering to that format. filenameFormatArgs = dict(year='YYYY', month='MM', day='DD') filenameExampleArgs = dict(year='2010', month='08', day='23') sourceKeys = source.get_key_list() exampleSuffixes = ['A', ' 7', ' 2-2', 'C', '1'][0 : len(sourceKeys)] filenameFormatArgs['values'] = sourceKeys filenameExampleArgs['values'] = [a+b for a,b in zip(sourceKeys, exampleSuffixes)] filenameFormatStr = metadata_to_filename(**filenameFormatArgs) filenameExampleStr = metadata_to_filename(**filenameExampleArgs) + ".jpg" self.fields['specify_metadata'].help_text = \ "Required filename format: %s" % filenameFormatStr # Use JavaScript to show/hide this additional help text self.metadata_extra_help_text = ( "\n" "For example, let's say your source has the following location keys: " "Site, Depth, Transect Line and Quadrant. " "If you want to upload a .jpg image that was taken at " "Site: sharkPoint, Depth: 10m, Transect Line: 3, and Quadrant: qu4, " "on 14 January 2010, the filename for upload should be:\n\n" "sharkPoint_10m_3_qu4_2010-01-14.jpg\n\n" "Alternatively, if you also want to store the original filename - say it's " "IMG_0032.jpg - you can use:\n\n" "sharkPoint_10m_3_qu4_2010-01-14_IMG_0032.jpg\n\n" "The original file name is not used by CoralNet, but could be " "useful for your own reference." ) self.additional_details = [ """Annotation points will be automatically generated for your images. Your Source's point generation settings: %s Your Source's annotation area settings: %s""" % ( PointGen.db_to_readable_format(source.default_point_generation_method), AnnotationAreaUtils.db_format_to_display(source.image_annotation_area) ) ]
def image_upload(request, source_id): """ This view serves the image upload page. It doesn't actually do any upload processing, though; that's left to the Ajax views. """ source = get_object_or_404(Source, id=source_id) images_form = MultiImageUploadForm() options_form = ImageUploadOptionsForm(source=source) csv_import_form = CSVImportForm() annotation_import_form = AnnotationImportForm() annotation_import_options_form = AnnotationImportOptionsForm(source=source) proceed_to_manage_metadata_form = ImageSpecifyForm( initial=dict(specify_method='image_ids'), source=source, ) auto_generate_points_message = ( "We will generate points for the images you upload.\n" "Your Source's point generation settings: {pointgen}\n" "Your Source's annotation area settings: {annoarea}").format( pointgen=PointGen.db_to_readable_format(source.default_point_generation_method), annoarea=AnnotationAreaUtils.db_format_to_display(source.image_annotation_area, ), ) return render_to_response('upload/image_upload.html', { 'source': source, 'images_form': images_form, 'options_form': options_form, 'csv_import_form': csv_import_form, 'annotation_import_form': annotation_import_form, 'annotation_import_options_form': annotation_import_options_form, 'proceed_to_manage_metadata_form': proceed_to_manage_metadata_form, 'auto_generate_points_message': auto_generate_points_message, }, context_instance=RequestContext(request) )
def point_gen_method_display(self): """ Display the point generation method in templates. Usage: {{ myimage.point_gen_method_display }} """ return PointGen.db_to_readable_format(self.point_generation_method)