def render(self, template_name, data={}): """Renders the template in the site wide manner. Retrieves the template data needed for the base template (login URL and text, user information, etc.) and merges it with the data passed to the method. Templates are retrieved from the template directory specified in the settings and appended with the suffix ".html" Arguments: template_name: the name of the template. this is the file name of the template without the .html extension. data: a dictionary containing data to be passed to the template. """ (login_text, login_url) = auth.login_logout(self.request) if auth.logged_in(): data['user'] = auth.User(auth.current_user()) data['admin'] = auth.user_is_admin() data['login_url'] = login_url data['login_text'] = login_text data['messages'] = Messages.get() path = os.path.join(settings.BASE_DIR, settings.TEMPLATE_DIR, "%s.html" % template_name) return self.response.out.write(template.render(path, data))
def render(self, template_name, data={}): """Renders the template in the site wide manner. Retrieves the template data needed for the base template (login URL and text, user information, etc.) and merges it with the data passed to the method. Templates are retrieved from the template directory specified in the settings and appended with the suffix ".html" Arguments: template_name: the name of the template. this is the file name of the template without the .html extension. data: a dictionary containing data to be passed to the template. """ (login_text, login_url) = auth.login_logout(self.request) data['uri_for'] = webapp2.uri_for data['user'] = auth.current_user() data['admin'] = auth.user_is_admin() data['login_url'] = login_url data['login_text'] = login_text template = jinja.get_template(template_name + '.html') return self.response.out.write(template.render(data))
def ideas(request): if request.method == "GET": (login_text, login_url) = auth.login_logout(request) idea_list = Idea.objects.all().order_by("-post_time") return basic_response( "apps/ideas.html", request, {"admin": auth.user_is_admin(), "ideas": idea_list, "login_url": login_url, "login_text": login_text}, ) elif request.method == "POST": idea = Idea() idea.name = request.POST["name"] idea.description = request.POST["description"] idea.author = auth.current_user() idea.save() return HttpResponseRedirect(reverse("apps.views.ideas")) else: raise Http404