当前位置: 首页>>代码示例>>Python>>正文


Python Service.get_by_slug方法代码示例

本文整理汇总了Python中models.Service.get_by_slug方法的典型用法代码示例。如果您正苦于以下问题:Python Service.get_by_slug方法的具体用法?Python Service.get_by_slug怎么用?Python Service.get_by_slug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Service的用法示例。


在下文中一共展示了Service.get_by_slug方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from models import Service [as 别名]
# 或者: from models.Service import get_by_slug [as 别名]
    def post(self, version, service_slug):
        logging.debug("ServiceInstanceHandler#post")
        name = self.request.get('name', default_value=None)
        description = self.request.get('description', default_value=None)
        region = self.request.get('region', default_value=None)
        
        if (self.valid_version(version)):
            service = Service.get_by_slug(service_slug)
            if service:
                if description:
                    service.description = description
                
                if name:
                    service.name = name

                if region:
                    service.region = Region.get_by_name(region)
                
                if name or description or region:
                    service.slug = Service.slugify(service.name, service.region.name)
                    service.put()
                    
                self.json(service.rest(self.base_url(version)))   
            else:
                self.error(404, "Service %s does not exist" % service_slug)
        else:
            self.error(404, "API Version %s not supported" % version)
开发者ID:samn,项目名称:stashboard,代码行数:29,代码来源:api.py

示例2: serverisup

# 需要导入模块: from models import Service [as 别名]
# 或者: from models.Service import get_by_slug [as 别名]
def serverisup (service):
	# Create a new event with the given status and given service
	service = Service.get_by_slug(service)
	status = Status.get_by_slug("up")        

	e = Event(service=service, status=status, message="The server is responding.")
	e.put()
开发者ID:StrataLabs,项目名称:status.justbooksclc.com,代码行数:9,代码来源:stashboard.py

示例3: serverisdown

# 需要导入模块: from models import Service [as 别名]
# 或者: from models.Service import get_by_slug [as 别名]
def serverisdown (service):
	# Create a new event with the given status and given service
	service = Service.get_by_slug(service)
	status = Status.get_by_slug("down")        

	e = Event(service=service, status=status, message="The server could not be reached")
	e.put()
开发者ID:StrataLabs,项目名称:status.justbooksclc.com,代码行数:9,代码来源:stashboard.py

示例4: post

# 需要导入模块: from models import Service [as 别名]
# 或者: from models.Service import get_by_slug [as 别名]
    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)

        if not name or not description:
            self.error(400, "Bad Data: Name: %s, Description: %s" \
                           % (name, description))
            return

        slug = slugify.slugify(name)
        existing_s = Service.get_by_slug(slug)

        if existing_s:
            self.error(404, "A sevice with this name already exists")
            return

        s = Service(name=name, slug=slug, description=description)
        s.put()

        invalidate_cache()

        self.response.set_status(201)
        self.json(s.rest(self.base_url(version)))
开发者ID:BillTheBest,项目名称:stashboard,代码行数:29,代码来源:api.py

示例5: post

# 需要导入模块: from models import Service [as 别名]
# 或者: from models.Service import get_by_slug [as 别名]
    def post(self, version):
        logging.debug("ServicesListHandler#post")

        if (self.valid_version(version)):
            
            name = self.request.get('name', default_value=None)
            description = self.request.get('description', default_value=None)
            serviceurl = self.request.get('serviceurl', default_value=None)
            pattern = self.request.get('pattern', default_value=None)
            freq = self.request.get('freq', default_value=None)
            
            if name and description:
                slug = slugify.slugify(name)
                existing_s = Service.get_by_slug(slug)

                # Update existing resource
                if existing_s:
                    existing_s.description = description
                    existing_s.serviceurl = serviceurl
                    existing_s.pattern = pattern
                    existing_s.freq = freq
                    existing_s.put()
                    self.json(existing_s.rest(self.base_url(version)))
                # Create new service
                else:
                    s = Service(name=name, slug=slug, description=description, serviceurl=serviceurl)
                    s.put()
                    self.json(s.rest(self.base_url(version)))
            else:
                self.error(400, "Bad Data: Name: %s, Description: %s" % (name, description))
        else:
            self.error(404, "API Version %s not supported" % version)
开发者ID:johnclarkemills,项目名称:stashboard,代码行数:34,代码来源:api.py

示例6: delete

# 需要导入模块: from models import Service [as 别名]
# 或者: from models.Service import get_by_slug [as 别名]
    def delete(self, version, service_slug, sid):
        if not self.valid_version(version):
            self.error(404, "API Version %s not supported" % version)
            return

        service = Service.get_by_slug(service_slug)

        if not service:
            self.error(404, "Service %s not found" % service_slug)
            return

 
        try:
            event = Event.get(db.Key(sid))
        except datastore_errors.BadKeyError:
            self.error(404, "Event %s not found" % sid)
            return

        if not event or service.key() != event.service.key():
            self.error(404, "No event for Service %s with sid = %s" \
                           % (service_slug, sid))
            return

        event.delete()
        invalidate_cache()

        # Why not JSON?
        self.success(event.rest(self.base_url(version)))
开发者ID:Tradeshift,项目名称:stashboard,代码行数:30,代码来源:api.py

示例7: call_api

# 需要导入模块: from models import Service [as 别名]
# 或者: from models.Service import get_by_slug [as 别名]
def call_api(service, data):
    '''Submit service status to API'''
    service = Service.get_by_slug(service)
    status = Status.get_by_slug(data['status'])
    e = Event(service=service, status=status, message=data['message'])
    print json.dumps(data, sort_keys=True, skipkeys=True)
    e.put()
开发者ID:OnePaaS,项目名称:docker-status,代码行数:9,代码来源:prodtool.py

示例8: get

# 需要导入模块: from models import Service [as 别名]
# 或者: from models.Service import get_by_slug [as 别名]
    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["service"] = service
        td["events"] = events.order("-start").fetch(500)

        self.render(td, 'service.html')
开发者ID:kyleconroy,项目名称:stashboard,代码行数:37,代码来源:site.py

示例9: get

# 需要导入模块: from models import Service [as 别名]
# 或者: from models.Service import get_by_slug [as 别名]
    def get(self):
        self.response.headers['Content-Type'] = "application/rss+xml; charset=utf-8"

        host = self.request.headers.get('host', 'nohost')
        base_url = self.request.scheme + "://" + host

        events = []
        query = Event.query().order(-Event.start)

        # Filter query by requested services, if specified in the 'service' URL parameter.
        service_list = []
        for service_arg in self.request.get_all('services'):
            service_list.extend(service_arg.split(','))
        service_list = map(lambda serv_slug: Service.get_by_slug(serv_slug), service_list)
        # filter out any non-existent services
        service_list = filter(lambda service: not service is None, service_list)

        service_string = 'all services'
        if len(service_list) > 0:
            query.filter('service IN', service_list)
            if len(service_list) == 1:
                service_string = 'the %s service' % service_list[0].name
            elif len(service_list) == 2:
                service_string = 'the %s and %s services' % (service_list[0].name, service_list[1].name)
            else:
                service_string = 'the %s, and %s services' % (', '.join([service.name for service in service_list[:-1]]), service_list[-1].name)

        # Create the root 'rss' element
        rss_xml = et.Element('rss')
        rss_xml.set('version', '2.0')

        # Create the channel element and its metadata elements
        channel = et.SubElement(rss_xml, 'channel')
        title = et.SubElement(channel, 'title')
        title.text = '%s Service Events' % settings.SITE_NAME
        description = et.SubElement(channel, 'description')
        description.text = 'This feed shows the last %d events on %s on %s.' % (settings.RSS_NUM_EVENTS_TO_FETCH, service_string, settings.SITE_NAME)
        link = et.SubElement(channel, 'link')
        link.text = base_url

        # Create each of the feed events.
        item_subelements = {
            'title': lambda(event): '[%s - %s] %s' % (event.service.name, event.status.name, unicode(event.message)),
            'description': lambda(event): '%s' % unicode(event.message),
            'link': lambda(event): '%s/services/%s' % (base_url, event.service.slug),
            'category': lambda(event): event.service.name,
            'pubDate': lambda(event): format_date_time(mktime(event.start.timetuple())),
            'guid': lambda(event): '%s/api/v1/services/%s/events/%s' % (base_url, event.service.slug, unicode(event.key))
        }

        for event in query.fetch(settings.RSS_NUM_EVENTS_TO_FETCH):
            item = et.SubElement(channel, 'item')
            for tag, text_func in item_subelements.iteritems():
                subelement = et.SubElement(item, tag)
                subelement.text = text_func(event)

        self.response.out.write('<?xml version="1.0" encoding="UTF-8"?>\n')
        self.response.out.write(et.tostring(rss_xml))
开发者ID:Labgoo,项目名称:stashboard,代码行数:60,代码来源:site.py

示例10: get

# 需要导入模块: from models import Service [as 别名]
# 或者: from models.Service import get_by_slug [as 别名]
 def get(self, slug):
     service = Service.get_by_slug(slug)
     if service:
         td = default_template_data()
         td["services_selected"] = True
         td["service"] = service
         td["events"] = service.events.order("-start").fetch(1000)
         self.render(td, 'admin/services_instance.html')
     else:
         self.not_found()
开发者ID:kyleconroy,项目名称:stashboard,代码行数:12,代码来源:admin.py

示例11: get

# 需要导入模块: from models import Service [as 别名]
# 或者: from models.Service import get_by_slug [as 别名]
    def get(self, version, service_slug):
        logging.debug("StatusesListHandler#get")
        
        if (self.valid_version(version)):
            service = Service.get_by_slug(service_slug)

            if service:
                history_size = config.SITE['history_size']
                start = self.request.get('start', default_value=None)
                end = self.request.get('end', default_value=None)
                                 
                query = Event.all()
                query.filter('service =', service)
                        
                if start:
                    try:
                        _start = aware_to_naive(parse(start))
                        # clip the start date to now - history_size
                        if datetime.now() - _start > timedelta(days=history_size):
                            _start = _start - timedelta(days=history_size)

                    except:
                        self.error(400, "Invalid Date: %s" % start)
                        return
                else:
                    _start = datetime.now() - timedelta(days=history_size)

                query.filter("start >= ", _start)

                if end:
                    try:
                        _end  = aware_to_naive(parse(end))
                        query.filter("start <=", _end)
                    except:
                        self.error(400, "Invalid Date: %s" % end)
                        return
                        
                query.order('-start')
                        
                if query:
                    data = []

                    for s in query:
                        data.append(s.rest(self.base_url(version)))

                    data = { "events": data }

                    self.json(data) 
                else:
                    self.error(404, "No events for Service %s" % service_slug)
            else:
                self.error(404, "Service %s not found" % service_slug)
        else:
            self.error(404, "API Version %s not supported" % version)
开发者ID:samn,项目名称:stashboard,代码行数:56,代码来源:api.py

示例12: post

# 需要导入模块: from models import Service [as 别名]
# 或者: from models.Service import get_by_slug [as 别名]
    def post(self, service_slug=None, options={}):
        service_slug = self.request.get("service-slug")
        tries_count = self.request.get("tries-count", 0)
        last_status_slug = self.request.get("last-status", "")
        options = settings.CHECK_SERVICES_TO_CHECK[service_slug]

        service = Service.get_by_slug(service_slug)
        if not service:
            self.error(404)
            self.log("Service %(service_name)s not found" % {"service_name": service_slug})

        self.check_service(service, tries_count, last_status_slug, options)
开发者ID:tucknet,项目名称:status.tucksaun.net,代码行数:14,代码来源:serviceChecks.py

示例13: update_status

# 需要导入模块: from models import Service [as 别名]
# 或者: from models.Service import get_by_slug [as 别名]
def update_status(service_slug, status_type, message):
    service = Service.get_by_slug(service_slug)
    status = Status.get_by_slug(status_type)

    cur_event = service.events.order('-start').fetch(1)

    if cur_event and cur_event[0].status.slug != status.slug:
        e = Event(service=service, status=status,
                  message=message)
        e.put()

        invalidate_cache()
开发者ID:beanbaginc,项目名称:stashboard,代码行数:14,代码来源:serverchecks.py

示例14: get

# 需要导入模块: from models import Service [as 别名]
# 或者: from models.Service import get_by_slug [as 别名]
    def get(self, version, service_slug):
        if not self.valid_version(version):
            self.error(404, "API Version %s not supported" % version)
            return

        service = Service.get_by_slug(service_slug)

        if not service:
            self.error(404, "Service %s does not exist" % service_slug)
            return

        self.json(service.rest(self.base_url(version)))
开发者ID:Tradeshift,项目名称:stashboard,代码行数:14,代码来源:api.py

示例15: get

# 需要导入模块: from models import Service [as 别名]
# 或者: from models.Service import get_by_slug [as 别名]
    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.query().fetch(100),
            }

        td.update(site.default_template_data())
        self.render(td, 'admin/events_create.html')
开发者ID:Labgoo,项目名称:stashboard,代码行数:16,代码来源:admin.py


注:本文中的models.Service.get_by_slug方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。