class MainPage(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
tasks_query = Task.all()
tasks = tasks_query.fetch(1000)
if user:
url = users.create_logout_url(self.request.uri)
else:
url = users.create_login_url(self.request.uri)
template_values = {
'tasks': tasks,
'url': url
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
class Gadget(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
tasks_query = Task.all()
tasks = tasks_query.fetch(1000)
if user:
url = users.create_logout_url(self.request.uri)
else:
url = users.create_login_url(self.request.uri)
template_values = {
'tasks': tasks,
'url': url
}
path = os.path.join(os.path.dirname(__file__), 'gadget.xml')
self.response.out.write(template.render(path, template_values))
class MainPage(webapp.RequestHandler): def get(self): user = users.get_current_user() tasks_query = Task.all() tasks = tasks_query.fetch(1000) if
Share
Really it depends on what you expect to be common between the two classes in future. The purpose of refactoring is to identify common abstractions, not to minimise the number of lines of code.
That said, assuming the two requests are expected to differ only in the template: