def efetch(req, id): logger.info("Asked to fetch Id: %s", id) session = entrez.EntrezSession(library_root()) abspath = session.fetch_id(id) path = getrelpath(abspath) try: parsing.initial(abspath) except: messages.error(req, "There was a problem loading file '%s', " "please try again or try a different record." % path) return re_search(req) path = getrelpath(abspath) remaining_args = dict(req.REQUEST.items()) action = remaining_args.pop('action', 'run') if action in ['run', 'config']: return HttpResponseRedirect( reverse(action, args=[path]) + dict_to_querystring(remaining_args)) else: logger.error("Unknown action %r", action) messages.error(req, "Unknown action.") return re_search(req)
def mksavefile(prefix): """Wrapper around creating the file to save uploaded files in. Returns the (fd, abspath, relpath) """ # we're using tempfile to ensure the file we get is unique and # aren't overwriting another. fd, abspath = tempfile.mkstemp( dir=settings.MEDIA_ROOT, prefix=prefix) relpath = getrelpath(abspath) return (fd, abspath, relpath)
def clean_entrez_search_term(self): cleaned_data = self.cleaned_data if cleaned_data.get('entrez_search_term'): self.active = 'entrez_search_term' self.session = entrez.CachedEntrezSession(library_root()) self.session.search(cleaned_data['entrez_search_term']) logger.debug( "Search finished, found %d matches", self.session.result_count) if self.session.result_count == 1: cleaned_data['path'] = getrelpath(self.session.fetch()) elif self.session.result_count > 1: raise forms.ValidationError( "Too many results (%d) found, need 1." " Try refining the search or searching for a RefSeq id." % (self.session.result_count)) else: raise forms.ValidationError("No results found.")
def addgetrelpath(request): return {'getrelpath': lambda p: p and getrelpath(p)}
def get_result_link(path): if path.startswith('/'): path = getrelpath(path) return reverse('raw', args=[path])
def get_raw_url(request, path): # return request.build_absolute_uri(reverse('raw', path)) # TODO: DEPRECATE in favor of get_result_link if path.startswith('/'): path = getrelpath(path) return reverse('raw', args=[path])