def index(): user = users.get_current_user() if user: if not UserSettings.has_seen_example() and GqlQuery('SELECT __key__ FROM Site WHERE owner=:1 AND example=true', user).count(1) == 0: _create_example_site(user) UserSettings.mark_example_as_seen() sites = Site.gql('WHERE users=:1 ORDER BY name', user) site_form = PageForm() page_form = PageForm() return render_template('index.html', sites=sites, new_site_form=site_form, page_form=page_form) else: return home()
def _whois(): key = request.args.get('key', None) email = request.args.get('email', None) page = None user_sites = None if key: page = Page.get_or_404(key) if email: user_sites = Site.gql('WHERE users = :1', User(email)) if key or email: return render_template('_whois_result.html', key=key, page=page, email=email, user_sites=user_sites) return render_template('_whois.html')
def delete(self, name): "Delete the named resource" # check the resource exists try: # if it does then delete it site = Site.gql("WHERE name=:1", name)[0] site.delete() except IndexError: # site didn't exist return self.error(404) except: # something else went wrong return self.error(500)
def get(self, slug): site = Site.gql("WHERE slug=:1", slug)[0] context = { 'site': site, } # prepare the context for the template # calculate the template path path = os.path.join(os.path.dirname(__file__), 'templates', 'site.html') # render the template with the provided context self.response.out.write(template.render(path, context))
def get(self, name): # get the site we're going to ping try: # retrieve the site based on its name value site = Site.gql("WHERE name=:1", name)[0] except IndexError: # if we don't find a site then throw a Not Found error return self.error(404) # ping the site and store the response ping_site(site) # back to the home page self.redirect("/")
def index(): user = users.get_current_user() if user: if not UserSettings.has_seen_example() and GqlQuery( 'SELECT __key__ FROM Site WHERE owner=:1 AND example=true', user).count(1) == 0: _create_example_site(user) UserSettings.mark_example_as_seen() sites = Site.gql('WHERE users=:1 ORDER BY name', user) site_form = PageForm() page_form = PageForm() return render_template('index.html', sites=sites, new_site_form=site_form, page_form=page_form) else: return home()
def get(self, name): "Show the JSON representing the site" try: # retrieve the site based on its name value site = Site.gql("WHERE name=:1", name)[0] except IndexError: # if we don't find a site then throw a Not Found error return self.error(404) # creat the object to represent the JSON object site_for_output = {"name": site.name, "url": site.url, "email": site.email} # create the JSON from our object json = simplejson.dumps(site_for_output, sort_keys=False, indent=4) # serve the response with the correct content type # self.response.headers['Content-Type'] = 'application/json' # write the json to the response self.response.out.write(json)
def get(self): query = self.request.get("q") if not query: sites = Site.all() else: sites = Site.gql("WHERE url=:1", "http://%s" % query) context = { 'sites': sites, 'query': query, } # prepare the context for the template # calculate the template path path = os.path.join(os.path.dirname(__file__), 'templates', 'index.html') # render the template with the provided context self.response.out.write(template.render(path, context))
def put(self, name): "Updates or Creates are managed through put on the name" # get the json from the body of the request json = self.request.body # convert the JSON to a Python object representation = simplejson.loads(json) # set the properties url = representation["url"] email = representation["email"] # we need to check whether this is an update try: site = Site.gql("WHERE name=:1", name)[0] site.url = url site.email = email except IndexError: # or a create site = Site(name=name, url=db.Link(url), email=db.Email(email)) # either way we need to save the new object site.put()
def post(self): """ site = Site( name = 'name', url = 'http://url.com', slug = 'slug', ) site.put() issue = Issue( title = 'title', description = 'description', site = site, ) issue.put() """ # get url and then decide if we have a site already or # need to create one name = self.request.get("name") url = self.request.get("url") try: site = Site.gql("WHERE url=:1", url)[0] except IndexError: """ import sys import pdb for attr in ('stdin', 'stdout', 'stderr'): setattr(sys, attr, getattr(sys, '__%s__' % attr)) pdb.set_trace() """ site = Site( name = name, url = url, slug = slugify(name), ) site.put() title = self.request.get("title") description = self.request.get("description") issue = Issue( title = title, description = description, site = site, ) issue.put() context = { 'issue': issue, 'sites': Site.all(), } # prepare the context for the template # calculate the template path path = os.path.join(os.path.dirname(__file__), 'templates', 'index.html') # render the template with the provided context self.response.out.write(template.render(path, context))