def get(self): user = users.get_current_user() total = TotalAmount.all().filter('user = '******'page', 1)) if page > 0: offset = limit * (page - 1) else: self.redirect('/') return chart_labels, chart_values = mk_chart_data(total) total_status = Status.all().filter('user = '******'user = '******'-updated_at').fetch(limit, offset) if len(statuses): self.render_response('index.html', { 'statuses': statuses, 'total_amount': total.amount, 'chart_labels': chart_labels, 'chart_values': chart_values, 'is_paginated': limit < total_status, 'has_previous': page > 1, 'has_next': (offset + limit) < total_status, 'previous_page': page - 1, 'next_page': page + 1, }) else: self.render_response('index.html', { 'statuses': [], }) else: self.render_response('index.html', {})
def data(self): services = [] default_status = Status.get_default() query = Service.all().filter("list =", self.list).order("name") for service in query.fetch(100): event = service.current_event() if event is not None: status = event.status else: status = default_status today = date.today() + timedelta(days=1) current, = service.history(1, default_status, start=today) has_issues = (current["information"] and status.key() == default_status.key()) service_dict = { "slug": service.slug, "name": service.name, "url": service.url(), "status": status, "has_issues": has_issues, "history": service.history(5, default_status), } services.append(service_dict) return { "days": get_past_days(5), "statuses": Status.all().fetch(100), "services": services, }
def update(self, somekey=''): """ statusから抜き出してついーと """ """適当""" stasu = Status.all().order('status_id').fetch(1) self.post(status)
def update(self, somekey=""): """ statusから抜き出してついーと """ """適当""" stasu = Status.all().order("status_id").fetch(1) self.post(status)
def data(self): services = [] dstatus = Status.default() for s in Service.all().order("name").fetch(100): event = s.current_event() if event is not None: status = event.status else: status = dstatus service = { "slug": s.slug, "name": s.name, "url": s.url(), "status": status, "history": s.history(5, dstatus) } services.append(service) return { "days": get_past_days(5), "statuses": Status.all().fetch(100), "services": services, }
def get(self): statuses = Status.all() amounts = {} users = {} for status in statuses: nickname = status.user.nickname() amount = amounts.get(nickname, { 'nama_cup': 0, 'nama_small': 0, 'nama_middle': 0, 'nama_big': 0, 'kan_350': 0, 'kan_500': 0, }) amount[status.beer] += status.amount amounts[nickname] = amount if not users.has_key(nickname): users[nickname] = status.user for nickname, amount in amounts.items(): total = TotalAmount.all().filter('user = ', users[nickname]).get() if total: for beer, value in amount.items(): setattr(total, beer, value) self.response.out.write("%s: %s(%s)<br>\n" % (nickname, beer, value)) total.put() self.response.out.write("done.")
def data(self): services = [] default_status = Status.get_default() lists = [] for list in self.lists: l = List.get_by_slug(list) if l is not None: lists.append(l) for service in Service.all().filter("list IN", lists).order("name").fetch(100): event = service.current_event() if event is not None: status = event.status else: status = default_status if len(self.statuses) and not status.slug in self.statuses: continue today = date.today() + timedelta(days=1) current, = service.history(1, default_status, start=today) has_issues = current["information"] and status.key() == default_status.key() service_dict = { "slug": service.slug, "name": service.name, "url": service.url(), "status": status, "has_issues": has_issues, "history": service.history(5, default_status), } services.append(service_dict) return {"days": get_past_days(5), "statuses": Status.all().fetch(100), "services": services}
def get(self, version): if not self.valid_version(version): self.error(404, "API Version %s not supported" % version) return query = Status.all().order('name') data = [s.rest(self.base_url(version)) for s in query] self.json({"statuses": data})
def get(self, slug): service = Service.get_by_slug(slug) if not service: self.not_found() return td = { "services_selected": True, "service": service, "statuses": Status.all().fetch(100), } td.update(site.default_template_data()) self.render(td, 'admin/events_create.html')
def post(self, version, status_slug): if not self.valid_version(version): self.error(404, "API Version %s not supported" % version) return status = Status.get_by_slug(status_slug) if not status: self.error(404, "No status with the slug %s found" % status_slug) return name = self.request.get('name', default_value=None) image_slug = self.request.get('image', default_value=None) image = None default = self.request.get('default', default_value=None) description = self.request.get('description', default_value=None) if image_slug is not None: image = Image.get_by_slug(image_slug) if image is None: self.error( 400, "An Image with the " "slug %s doesn't exist" % image_slug) return status.image = image.path if description is not None: status.description = description if default is not None and default in ["false", "true"]: # Reset default status if default == "true": for stat in Status.all().filter("default", True): stat.default = False stat.put() status.default = default == "true" if name is not None: status.name = name if description or name or image or default: status.put() invalidate_cache() self.json(status.rest(self.base_url(version)))
def get(self): # get all the statuses query = Status.all() # pass all the statuses and the sitetitle to the template template_values = { 'sitetitle': SITE_TITLE, 'statuses': query, } # find the template path = os.path.join(os.path.dirname(__file__), 'index.html') # render the template self.response.out.write(template.render(path, template_values))
def post(self, version, status_slug): if not self.valid_version(version): self.error(404, "API Version %s not supported" % version) return status = Status.get_by_slug(status_slug) if not status: self.error(404, "No status with the slug %s found" % status_slug) return name = self.request.get('name', default_value=None) image_slug = self.request.get('image', default_value=None) image = None default = self.request.get('default', default_value=None) description = self.request.get('description', default_value=None) if image_slug is not None: image = Image.get_by_slug(image_slug) if image is None: self.error(400, "An Image with the " "slug %s doesn't exist" % image_slug) return status.image = image.path if description is not None: status.description = description if default is not None and default in ["false", "true"]: # Reset default status if default == "true": for stat in Status.all().filter("default", True): stat.default = False stat.put() status.default = default == "true" if name is not None: status.name = name if description or name or image or default: status.put() invalidate_cache() self.json(status.rest(self.base_url(version)))
def post(self, version): if not self.valid_version(version): self.error(404, "API Version %s not supported" % version) return name = self.request.get('name', default_value=None) description = self.request.get('description', default_value=None) image_slug = self.request.get('image', default_value=None) default = self.request.get('default', default_value="false") if default not in ["true", "false"]: self.error(400, "Default must be true or false") return if not name or not description or not image_slug: self.error(400, "Bad Data") return slug = slugify.slugify(name) status = Status.get_by_slug(slug) image = Image.get_by_slug(image_slug) if status is not None: self.error(400, "A Status with the slug %s already exists" % slug) return if image is None: msg = "An Image with the slug %s doesn't exist" % image_slug self.error(400, msg) return # Reset default status if default == "true": for stat in Status.all().filter("default", True): stat.default = False stat.put() default = default == "true" status = Status(name=name, slug=slug, description=description, image=image.path, default=default) status.put() invalidate_cache() self.response.set_status(201) self.json(status.rest(self.base_url(version)))
def get(self): # get all the statuses query = Status.all() if query.count() != 0: for result in query: # if there are already some, then update them update(result) else: # create an example status and put it in the datastore test = Status(description='google', comment='the acclaimed search engine', link_url='http://www.google.com', link_text='www.google.com', update_type='status', update_url='http://www.google.com') test.put()
def get(self, version): logging.debug("StatusesListHandler#get") if (self.valid_version(version)): query = Status.all().order('severity') if (query): data = [] for s in query: data.append(s.rest(self.base_url(version))) self.json({"statuses": data}) else: self.error(404, "No statuses") else: self.error(404, "API Version %s not supported" % version)
def data(self): lists = {} default_status = Status.get_default() for service in Service.all().order("list").fetch(100): event = service.current_event() if event is not None: status = event.status else: status = default_status if service.list and not lists.has_key(service.list.slug) or \ lists[service.list.slug]["status"].name < status.name: lists[service.list.slug] = {"list": service.list, "status": status} return { "lists": lists.items(), "statuses": Status.all().fetch(100), }
def get(self): user = users.get_current_user() logging.debug("BasicRootHandler#get") q = Service.all() q.order("name") services = q.fetch(100) p = Status.all() p.order("severity") past = get_past_days(5) td = default_template_data() td["services"] = q.fetch(100) td["statuses"] = p.fetch(100) td["past"] = past td["default"] = Status.default() self.render(td, 'basic','index.html')
def get(self): services = Service.all().fetch(50) statuses = Status.all().fetch(10) now = datetime.datetime.now() for loop_no, service in enumerate(services): if service.serviceurl == None: continue query = Event.all().filter('service =', service).order("-start").fetch(1) if len(query) > 0 and (now - query.pop().start < timedelta(minutes=service.freq)): continue res = None for i in range(3): try: # TODO: move to using async, so we can handle lots of pings... res = urlfetch.fetch(service.serviceurl) break except: logging.error('fetch num %d failed', i) sleep(1) if not res: event = Event(service = service, status = statuses[0], message = "Failed page load.") event.put() continue if res.status_code == 200: if service.pattern: result = re.search(service.pattern, res.content) if result: event = Event(service = service, status = statuses[1], message = "Passed. Page loaded. Regex found.") event.put() else: event = Event(service = service, status = statuses[0], message = "Failed regex.") event.put() else: event = Event(service = service, status = statuses[1], message = "Passed. Page loaded.") event.put() else: event = Event(service = service, status = statuses[0], message = "Failed page load.") event.put()
def data(self): services = [] default_status = Status.get_default() lists = [] for list in self.lists: l = List.get_by_slug(list) if l is not None: lists.append(l) for service in Service.all().filter("list IN", lists).order("name").fetch(100): event = service.current_event() if event is not None: status = event.status else: status = default_status if len(self.statuses) and not status.slug in self.statuses: continue today = date.today() + timedelta(days=1) current, = service.history(1, default_status, start=today) has_issues = (current["information"] and status.key() == default_status.key()) service_dict = { "slug": service.slug, "name": service.name, "url": service.url(), "status": status, "has_issues": has_issues, "history": service.history(5, default_status), } services.append(service_dict) return { "days": get_past_days(5), "statuses": Status.all().fetch(100), "services": services, }
def get(self): user = users.get_current_user() logging.debug("BasicRootHandler#get") today = datetime.datetime.today() end = today start = end - timedelta(days=+5) start_date = dateparser.parse(self.request.get('start', default_value=str(start))) end_date = dateparser.parse(self.request.get('end', default_value=str(end))) history_size = config.SITE['history_size'] if end_date > today or start_date > end_date or \ today.toordinal() - history_size > start_date.toordinal(): end_date = today start_date = end_date - timedelta(days=5) q = Service.all() q.order("name") services = [] for service in q.fetch(100): events = service.events_for_days(start_date, end_date) services.append((service, events)) p = Status.all() p.order("severity") past = get_past_days(5, end_date) td = default_template_data() td["start_date"] = start_date td["end_date"] = end_date td["services"] = services td["statuses"] = p.fetch(100) td["past"] = past td["default"] = Status.default() self.render(td, 'basic','index.html')
def get(self, service_slug, year=None, month=None, day=None): service = Service.get_by_slug(service_slug) if not service: self.not_found() return try: if day: start_date = date(int(year), int(month), int(day)) end_date = start_date + timedelta(days=1) elif month: start_date = date(int(year), int(month), 1) days = calendar.monthrange(start_date.year, start_date.month)[1] end_date = start_date + timedelta(days=days) elif year: start_date = date(int(year), 1, 1) end_date = start_date + timedelta(days=365) else: start_date = None end_date = None except ValueError: self.not_found(404) return events = service.events if start_date and end_date: events.filter('start >= ', start_date).filter('start <', end_date) td = default_template_data() td["statuses"] = Status.all().fetch(100) td["service"] = service td["events"] = events.order("-start").fetch(500) self.render(td, 'service.html')
def run(self): logging.info("Update each status") # For each status for status in Status.all().fetch(100): # Set the status to default status.default = False # Update the status url status.image = "icons/fugue/" + status.image + ".png" # Save the status status.put() # Get the up status and make it default default_status = Status.get_by_slug("up") if default_status is None: logging.error("Could not find the up status") return default_status.default = True default_status.put() logging.info("Set up status as the default")
def _isCached(self, status): q = Status.all() q.filter('status_id =', status.id) print q.count() > 0 return q.count() > 0
def _isCached(self, status): q = Status.all() q.filter("status_id =", status.id) print q.count() > 0 return q.count() > 0
def get(self): td = default_template_data() td["statuses_selected"] = True td["statuses"] = Status.all().order("name").fetch(1000) self.render(td, 'admin/status.html')