本文整理汇总了Python中models.Service.slugify方法的典型用法代码示例。如果您正苦于以下问题:Python Service.slugify方法的具体用法?Python Service.slugify怎么用?Python Service.slugify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Service
的用法示例。
在下文中一共展示了Service.slugify方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Service [as 别名]
# 或者: from models.Service import slugify [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)
region = self.request.get('region', default_value=None)
if name and description and region:
slug = Service.slugify(name, region)
existing_s = Service.get_by_slug(slug)
# Update existing resource
if existing_s:
existing_s.description = description
if region:
existing_s.region = Region.get_by_name(region)
existing_s.slug = Service.slugify(name, region)
existing_s.put()
self.json(existing_s.rest(self.base_url(version)))
# Create new service
else:
region = Region.get_by_name(region)
s = Service(name=name, slug=slug, description=description, region=region)
s.put()
self.json(s.rest(self.base_url(version)))
else:
self.error(400, "Bad Data: Name: %s, Description: %s, Region: %s" % (name, description, region))
else:
self.error(404, "API Version %s not supported" % version)
示例2: Region
# 需要导入模块: from models import Service [as 别名]
# 或者: from models.Service import slugify [as 别名]
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from google.appengine.ext import db
from models import Status, Service, Event, Region
from datetime import datetime, timedelta, date
na = Region(name="North America")
na.put()
emea = Region(name="EMEA")
emea.put()
foo = Service(name="Service Foo", slug="service-foo", region=na,
description="Scalable and reliable foo service across the globe")
foo.slug = Service.slugify(foo.name, foo.region.name)
foo.put()
bar = Service(name="Service Bar", slug="service-bar", region=emea,
description="Scalable and reliable foo service")
bar.slug = Service.slugify(bar.name, bar.region.name)
bar.put()
delete = Service(name="Delete Me", slug="delete", region=na,
description="Delete Me Please")
delete.slug = Service.slugify(delete.name, delete.region.name)
delete.put()
bar = Service.get_by_slug("emea-service-bar")
cat = Status.get_by_slug("down")