def sources_from_args(cls, request, asset=None): ''' utilized by add_view to help create a new asset returns a dict of sources represented in GET/POST args ''' sources = {} args = request.POST if request.method == 'POST' else request.GET for key, val in args.items(): if cls.good_asset_arg(key) and val != '' and len(val) < 4096: source = Source(label=key, url=val) # UGLY non-functional programming for url_processing if asset: source.asset = asset src_metadata = args.get(key + '-metadata', None) cls.add_metadata(source, src_metadata) sources[key] = source # iterate the primary labels in order of priority # pickup the first matching one & use that for lbl in Asset.primary_labels: if lbl in sources: sources[lbl].primary = True return sources # no primary source found, return no sources return {}
def sources_from_args(cls, request, asset=None): ''' utilized by add_view to help create a new asset returns a dict of sources represented in GET/POST args ''' sources = {} args = request.POST if request.method == 'POST' else request.GET for key, val in args.items(): if cls.good_asset_arg(key) and val != '' and len(val) < 4096: source = Source(label=key, url=val) # UGLY non-functional programming for url_processing if asset: source.asset = asset src_metadata = args.get(key + '-metadata', None) cls.add_metadata(source, src_metadata) sources[key] = source # iterate the primary labels in order of priority # pickup the first matching one & use that for lbl in Asset.primary_labels: if lbl in sources: sources[lbl].primary = True return sources # no primary source found, return no sources return {}
def sources_from_args(request, asset=None): ''' utilized by add_view to help create a new asset returns a dict of sources represented in GET/POST args ''' sources = {} args = request.REQUEST for key, val in args.items(): if good_asset_arg(key) and val != '': source = Source(label=key, url=val) # UGLY non-functional programming for url_processing source.request = request if asset: source.asset = asset src_metadata = args.get(key + '-metadata', None) if src_metadata: # w{width}h{height};{mimetype} (with mimetype and w+h optional) m = re.match('(w(\d+)h(\d+))?(;(\w+/[\w+]+))?', src_metadata).groups() if m[1]: source.width = int(m[1]) source.height = int(m[2]) if m[4]: source.media_type = m[4] sources[key] = source for lbl in Asset.primary_labels: if lbl in args: sources[lbl].primary = True break return sources
def sources_from_args(request, asset=None): ''' utilized by add_view to help create a new asset returns a dict of sources represented in GET/POST args ''' sources = {} args = request.REQUEST for key, val in args.items(): if good_asset_arg(key) and val != '': source = Source(label=key, url=val) # UGLY non-functional programming for url_processing source.request = request if asset: source.asset = asset src_metadata = args.get(key + '-metadata', None) if src_metadata: # w{width}h{height};{mimetype} (with mimetype and w+h optional) the_match = re.match('(w(\d+)h(\d+))?(;(\w+/[\w+]+))?', src_metadata).groups() if the_match[1]: source.width = int(the_match[1]) source.height = int(the_match[2]) if the_match[4]: source.media_type = the_match[4] sources[key] = source for lbl in Asset.primary_labels: if lbl in args: sources[lbl].primary = True break return sources