def get(self): self.enforce_admin() name = self.request.get("name") if name is None or "" == name: self.jsonout(status="error", msg="No name specified", ) return name = name.strip() sq = Site.gql("WHERE name = :1",name) s = sq.get() if s is None: s = Site(name=name) s.put() increment("Site") msg = "site %s added with id %d" format = (s.name,s.key().id()) self.jsonout(status="ok",msg=msg,format=format, key=str(s.key()), id=s.key().id() ) else: self.jsonout(status="dup", msg="%s already existed as site with id %d", format=(name,s.key().id()), id=s.key().id(), key=str(s.key()) )
def _get_site(self): site = ndb.Key(Site, '_site').get() if not site: logging.error('Saving site') site = Site(id='_site') site.github_token = '' site.put() return site
def post(self): url = self.request.POST.get('url') try: result = urllib2.urlopen(url) content = result.read() site = Site() site.url = url site.count = self.__count_imgs(content) site.put() self.__grab_urls(content) except: pass