def get(self, path, feature_id=None): user = users.get_current_user() if user is None: if feature_id: # Redirect to public URL for unauthenticated users. return self.redirect(self.DEFAULT_URL + '/' + feature_id) else: return self.redirect(users.create_login_url(self.request.uri)) # Remove trailing slash from URL and redirect. e.g. /metrics/ -> /metrics if path[-1] == '/': return self.redirect(self.request.path.rstrip('/')) # TODO(ericbidelman): This creates a additional call to # _is_user_whitelisted() (also called in common.py), resulting in another # db query. if not self._is_user_whitelisted(user): #TODO(ericbidelman): Use render(status=401) instead. #self.render(data={}, template_path=os.path.join(path + '.html'), status=401) common.handle_401(self.request, self.response, Exception) return if not feature_id and not 'new' in path: # /features/edit|launch -> /features/new return self.redirect(self.ADD_NEW_URL) elif feature_id and 'new' in path: return self.redirect(self.ADD_NEW_URL) template_data = {'feature_form': models.FeatureForm()} if feature_id: f = models.Feature.get_by_id(long(feature_id)) if f is None: return self.redirect(self.ADD_NEW_URL) # Provide new or populated form to template. template_data.update({ 'feature': f.format_for_template(), 'feature_form': models.FeatureForm(f.format_for_edit()), 'default_url': '%s://%s%s/%s' % (self.request.scheme, self.request.host, self.DEFAULT_URL, feature_id), 'edit_url': '%s://%s%s/%s' % (self.request.scheme, self.request.host, self.EDIT_URL, feature_id) }) if self.LAUNCH_PARAM in self.request.params: template_data[self.LAUNCH_PARAM] = True if self.INTENT_PARAM in self.request.params: template_data[self.INTENT_PARAM] = True self._add_common_template_values(template_data) self.render(data=template_data, template_path=os.path.join(path + '.html'))
def get(self): # feature = models.Feature( # type=models.Resource.Type.ARTICLE, #TODO: use correct type for content. # title=doc.title(), # text=doc.summary(),#.decode('utf-8').decode('ascii','ignore'), # publication_date=datetime.datetime.today(), #TODO: save real date. # url=db.Link(result.final_url or url), # #fetch_date=datetime.date.today(), # #sharers # ) template_data = {'feature_form': models.FeatureForm()} self.render(data=template_data, template_path=os.path.join('newfeature.html'))