def add_site(self): self.template_path = 'site_add.html' # get the site code site_code = self.request.get('site_code').strip() self.vars['site_code'] = site_code # return if there is no site_code, or we are not a post if (not site_code) or self.request.method != 'POST' : return # check that the site_code is valid if not Site.is_code_valid( site_code ): self.vars['site_code_error'] = "site code is not valid" return # check that the site_code is valid if Site.is_code_taken( site_code ): self.vars['site_code_error'] = "site code already exists" return # ok to create site = Site( site_code=site_code, owner=self.person ) site.put() # create the first shared secret SharedSecret.new_for_site( site ) self.redirect('/site/' + site_code )
def add_site(self): self.template_path = 'site_add.html' # get the site code site_code = self.request.get('site_code').strip() self.vars['site_code'] = site_code # return if there is no site_code, or we are not a post if (not site_code) or self.request.method != 'POST': return # check that the site_code is valid if not Site.is_code_valid(site_code): self.vars['site_code_error'] = "site code is not valid" return # check that the site_code is valid if Site.is_code_taken(site_code): self.vars['site_code_error'] = "site code already exists" return # ok to create site = Site(site_code=site_code, owner=self.person) site.put() # create the first shared secret SharedSecret.new_for_site(site) self.redirect('/site/' + site_code)
def _create_example_site(user): site = Site( name='Example Site', owner = user, users = [user], admins = [user], example = True, ) site.put() for v in [4, 5]: name = 'Html%d Example' % v style = Style(site=site, name=name) style.put() rev = StyleRevision(parent=style, rev=0) rev.put() rev.update(render_template('examples/blog-html%d.css' % v)) style.published_rev = rev rev = StyleRevision(parent=style, rev=1) rev.put() rev.update(render_template('examples/blog-html%d-preview.css' % v)) style.preview_rev = rev style.put() page = Page(site=site, name=name, url=url_for('example%d' % v, page_key=0, _external=True), _styles=[style.key()]) page.put() page.url = url_for('example%d' % v, page_key=page.key(), _external=True) page.put() page.queue_refresh()
def rename_usergroup_site(): for group in UserGroup.all(): site = Site(name=group.name.replace(' - User Group', ''), users=group.users, admins=group.admins) site.put() for style in group.style_set: style.site = site style.put()
def _create_example_site(user): site = Site( name='Example Site', owner=user, users=[user], admins=[user], example=True, ) site.put() for v in [4, 5]: name = 'Html%d Example' % v style = Style(site=site, name=name) style.put() rev = StyleRevision(parent=style, rev=0) rev.put() rev.update(render_template('examples/blog-html%d.css' % v)) style.published_rev = rev rev = StyleRevision(parent=style, rev=1) rev.put() rev.update(render_template('examples/blog-html%d-preview.css' % v)) style.preview_rev = rev style.put() page = Page(site=site, name=name, url=url_for('example%d' % v, page_key=0, _external=True), _styles=[style.key()]) page.put() page.url = url_for('example%d' % v, page_key=page.key(), _external=True) page.put() page.queue_refresh()
def new_site(): user = users.get_current_user() form = PageForm(request.form) if request.method == 'POST': if form.validate(): site = Site( name=form.name.data, owner=user, users=[user], admins=[user], ) site.put() page = Page.new_page(site, form.name.data, form.url.data) new_url = url_for('editor', page_id=page.key().id()) if request.is_xhr: return jsonify(dict(type='success', redirect=new_url)) else: return redirect(new_url) elif request.is_xhr: return jsonify( dict(type='error', errors=render_template('form_errors.html', form=form))) if request.is_xhr: return render_template('site_creator.html', form=form) return render_template('new_site.html', form=form)
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 new_site(): user = users.get_current_user() form = PageForm(request.form) if request.method == 'POST': if form.validate(): site = Site( name = form.name.data, owner = user, users = [user], admins = [user], ) site.put() page = Page.new_page(site, form.name.data, form.url.data) new_url = url_for('editor', page_id=page.key().id()) if request.is_xhr: return jsonify(dict(type='success', redirect=new_url)) else: return redirect(new_url) elif request.is_xhr: return jsonify(dict(type='error', errors=render_template('form_errors.html', form=form))) if request.is_xhr: return render_template('site_creator.html', form=form) return render_template('new_site.html', form=form)
def sites(): if request.method == 'GET': query = Site.query() compact_sites = [] for site in query: report = Report.query().filter( Report.site == site.key).order(-Report.created_on).fetch(1) compact_site = Site.to_compact(site) compact_site.update(Report.to_dict(report[0])) compact_sites.append(compact_site) return jsonify({'siteList': compact_sites}), 200 elif request.method == 'POST': request_body = request.get_json() name = request_body.get('name', '') url = request_body.get('url', '') id_info = get_user_id_info(request) email = id_info['email'] try: report_results = PageSpeedInights.run(url) user_key = User.query().filter(User.email == email).fetch( keys_only=True)[0] site = Site(name=name, url=url) site.created_by = user_key site.last_edited_by = user_key site_key = site.put() report = Report( site=site_key, accessibility_score=report_results['accessibility_score'], best_practices_score=report_results['best_practices_score'], desktop_performance_score=report_results[ 'desktop_performance_score'], mobile_performance_score=report_results[ 'mobile_performance_score'], seo_score=report_results['seo_score'], pwa_score=report_results['pwa_score'], ) report.put() return jsonify({'success': True}), 200 except: raise Exception('Page Speed Insights API returned an error') else: raise Exception('Method not supported')
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))
import urllib2 import httplib from BeautifulSoup import BeautifulStoneSoup as bs import logging from titlecase import titlecase from random import randint import __init__ as zeep import time from qlsearch import QLSearch from lyricsscrape import androidSearch, scrapeSongID SECRET_ACCESS_KEY = '8c52658c67d395ae2a7f40ccbe76f4353b648c09' API_KEY = '920dc163-c83c-4d50-9e09-c24b2b6b568d' s = Site(name ='lyricsfreak', type='lyrics',tag = 'a', div='a', siteName='lyricsfreak') s.put() # s.commit() class getLyricsHandler( webapp.RequestHandler ): def get( self ): try: city = self.request.get( 'city' ) state = self.request.get( 'state' ) country = self.request.get( 'country' ) songID = self.request.get('songid') type_ = self.request.get('contenttype') term = self.request.get('songTitle') if not type_: type_ = 'lyrics' if songID: