本文整理汇总了Python中models.package.Package类的典型用法代码示例。如果您正苦于以下问题:Python Package类的具体用法?Python Package怎么用?Python Package使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Package类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
def index(self, page=1, format='html'):
"""Retrieve a paginated list of uploaded packages.
Arguments:
page: The page of packages to get. Each page contains 10 packages.
"""
if format == 'json':
pager = QueryPager(int(page), "/packages.json?page=%d",
Package.all().order('-updated'),
per_page=50)
return json.dumps({
"packages": [
handlers.request().url(action='show', id=package.name)
for package in pager.get_items()
],
"prev": pager.prev_url,
"next": pager.next_url,
"pages": pager.page_count
})
else:
pager = QueryPager(int(page), "/packages?page=%d",
Package.all().order('-updated'))
title = 'All Packages'
if page != 1: title = 'Page %s | %s' % (page, title)
return handlers.render("packages/index",
packages=pager.get_items(),
pagination=pager.render_pagination(),
layout={'title': title})
示例2: post
def post(self):
p = Package()
p._id = self.get_argument('package_name')
package = Package.lookup(p._id)
p.avail_timelong = int(self.get_argument('avail_timelong', package['avail_timelong']))
p.avail_begintime = int(self.get_argument("avail_begintime", package['avail_begintime']))
p.avail_endtime = int(self.get_argument("avail_endtime1", package['avail_endtime']))
#p.avail_begintime = datetime.datetime.strptime(avail_begintime+':00', "%H:%M")
#p.avail_endtime = datetime.datetime.strptime(avail_endtime+':00',"%H:%M")
'''
p.pname = self.get_argument('package_name')
p.avail_timelong = int(self.get_argument('avail_timelong'))
p.avail_begintime = datetime.datetime.strptime(self.get_argument("avail_begintime"), "%H:%M")
p.avail_endtime = datetime.datetime.strptime(self.get_argument("avail_endtime"), "%H:%M")
avail_beginhourstr = self.get_argument("avail_begintime", None)
nPos1 =avail_beginhourstr.index(':')
avail_beginhour = int(avail_beginhourstr[0:nPos1])
avail_endhourstr = self.get_argument("avail_endtime", None)
nPos2 =avail_endhourstr.index(':')
avail_endhour = int(avail_endhourstr[0:nPos2])
if avail_endhour <= avail_beginhour:
p.effective_length = avail_endhour+24 - avail_beginhour
else:
p.effective_length = avail_endhour - avail_beginhour
'''
p.is_weekday= int(self.get_argument("is_weekday", package['is_weekday']))
p.created_at = datetime.datetime.now()
Package.updatePackage(p)
self.redirect("/get_packages")
示例3: job_package
def job_package():
# Log.info("请异步发送")
need_do = ''
orders = Order.get_working_orders()
for order in orders:
product = Product.lookup(order['p_id'])
exchange = Exchange.get_exchange(order['e_id'])
packages = Package.getPackageByName(order['package_id'])
for package in packages:
need_do = need_do+json.dumps({'port':product['port'],'bandwidth':order['bandwidth'],\
'status':order['status'],'port_name':product['port'], 'ipAddress':exchange['ipAddress'], \
'package_id':package['package_name']})
# Order.finish_order(order['_id'])
need_back=''
orders = Order.get_back_orders()
for order in orders:
custom_time = order['custom_time']
product = Product.lookup(order['p_id'])
exchange = Exchange.look(order['e_id'])
packages = Package.getPackageByName(order['package_id'])
for package in packages:
need_back = need_back+json.dumps({'port':product['port'],'ex_bandwidth':order['bandwidth'],\
'status':order['status'],'port_name':product['port'], 'ipAddress':exchange['ipAddress'], \
'package_id':package['package_name']})
# Order.back_order(order['_id'])
print 'set_package_job end at ',datetime.datetime.now()
示例4: test_create_requires_uploader
def test_create_requires_uploader(self):
Package.new(name='owned-package',
uploaders=[self.normal_user('owner')]).put()
self.be_normal_oauth_user()
response = self.testapp.get(
'/packages/owned-package/versions/abcd/create.json', status=403)
self.assert_json_error(response)
示例5: test_get_package_json_without_versions
def test_get_package_json_without_versions(self):
admin = self.admin_user()
Package.new(name='test-package', uploaders=[admin]).put()
response = self.testapp.get('/packages/test-package.json')
self.assertEqual(response.headers['Content-Type'], 'application/json')
self.assertEqual(json.loads(response.body), {
"name": "test-package",
"uploaders": [admin.email()],
"versions": []
})
示例6: test_api_get_package_without_versions
def test_api_get_package_without_versions(self):
admin = self.admin_user()
Package.new(name='test-package', uploaders=[admin]).put()
self.be_normal_user()
response = self.testapp.get('/api/packages/test-package')
self.assertEqual(response.headers['Content-Type'], 'application/json')
result = json.loads(response.body)
self.assertEqual(result["name"], "test-package")
self.assertEqual(result["versions"], [])
self.assertEqual(result["latest"], None)
示例7: test_uploadership_is_case_insensitive
def test_uploadership_is_case_insensitive(self):
self.be_normal_oauth_user('NAme')
self.post_package_version(name='new-package', version='0.0.1')
version = Package.get_by_key_name('new-package').latest_version
self.assertIsNotNone(version)
self.assertEqual(version.version, SemanticVersion('0.0.1'))
self.be_normal_oauth_user('naME')
self.post_package_version(name='new-package', version='0.0.2')
version = Package.get_by_key_name('new-package').latest_version
self.assertIsNotNone(version)
self.assertEqual(version.version, SemanticVersion('0.0.2'))
示例8: generate_feed
def generate_feed(page=1):
feed = FeedGenerator()
feed.id("https://pub.dartlang.org/feed.atom")
feed.title("Pub Packages for Dart")
feed.link(href="https://pub.dartlang.org/", rel="alternate")
feed.link(href="https://pub.dartlang.org/feed.atom", rel="self")
feed.description("Last Updated Packages")
feed.author({"name": "Dart Team"})
i = 1
pager = QueryPager(int(page), "/feed.atom?page=%d",
Package.all().order('-updated'),
per_page=10)
for item in pager.get_items():
i += 1
entry = feed.add_entry()
for author in item.latest_version.pubspec.authors:
entry.author({"name": author[0]})
entry.title("v" + item.latest_version.pubspec.get("version") +\
" of " + item.name)
entry.link(link={"href": item.url, "rel": "alternate",
"title": item.name})
entry.id(
"https://pub.dartlang.org/packages/" + item.name + "#" +\
item.latest_version.pubspec.get("version"))
entry.description(
item.latest_version.pubspec
.get("description", "Not Available"))
readme = item.latest_version.readme
if not readme is None:
entry.content(item.latest_version.readme.render(), type='html')
else:
entry.content("<p>No README Found</p>", type='html')
return feed
示例9: test_api_get_package_with_versions
def test_api_get_package_with_versions(self):
self.be_admin_user()
self.create_package('test-package', '1.1.0')
self.create_package('test-package', '1.1.1')
self.create_package('test-package', '1.2.0')
self.be_normal_user()
package = Package.get_by_key_name('test-package')
response = self.testapp.get('/api/packages/test-package')
self.assertEqual(response.headers['Content-Type'], 'application/json')
self.assertEqual(json.loads(response.body), {
"name": "test-package",
"url": "http://localhost:80/api/packages/test-package",
"uploaders_url": "http://localhost:80/api/packages/test-package/" +
"uploaders",
"version_url": "http://localhost:80/api/packages/test-package/" +
"versions/{version}",
"new_version_url":
"http://localhost:80/api/packages/test-package/versions/new",
"downloads": 0,
"uploaders": [self.admin_user().email()],
"created": package.created.isoformat(),
"versions": [
self.package_version_dict("test-package", "1.1.0"),
self.package_version_dict("test-package", "1.1.1"),
self.package_version_dict("test-package", "1.2.0"),
],
"latest": self.package_version_dict("test-package", "1.2.0")
})
示例10: setUp
def setUp(self):
super(PackageVersionsTest, self).setUp()
self.package = Package.new(
name='test-package',
uploaders=[self.admin_user(),
self.normal_user('other-uploader')])
self.package.put()
示例11: setUp
def setUp(self):
super(PackageUploadersTest, self).setUp()
self.package = Package.new(
name='test-package',
uploaders=[self.normal_user('uploader1'),
self.normal_user('uploader2')])
self.package.put()
示例12: _get_result
def _get_result(self, resource_item):
"""Convert a Custom Search API result into a map of package metadata
that can be rendered.
If the result does not reference a valid package, return None.
Arguments:
resource_item: The API result. It is expected to be a map containing
a "link" key which will likely be a package URL.
"""
link = resource_item["link"]
match = PACKAGE_URL_PATTERN.match(link)
if not match:
logging.warning('could not parse search result URL "%s"' % link)
return None
package = Package.get_by_key_name(match.group(1))
if not package:
logging.warning('could not find search result package "%s"' %
match.group(1))
return None
return {
"name": package.name,
"version": package.latest_version.version,
"desc": package.ellipsized_description,
"url": "/packages/" + package.name,
"last_uploaded": package.latest_version.relative_created
}
示例13: _compute_version_order
def _compute_version_order(self, name):
"""Compute the sort order for all versions of a given package."""
versions = list(Package.get_by_key_name(name).version_set.run())
versions.sort(key=lambda version: version.version)
for i, version in enumerate(versions):
version.sort_order = i
with models.transaction():
for version in versions: version.put()
示例14: test_has_version
def test_has_version(self):
package = Package.new(name='test-package',
uploaders=[self.admin_user()])
package.put()
self.package_version(package, '1.2.3').put()
self.assertTrue(package.has_version('1.2.3'))
self.assertFalse(package.has_version('1.2.4'))
示例15: test_delete_is_case_insensitive
def test_delete_is_case_insensitive(self):
self.be_normal_oauth_user('uploader1')
response = self.testapp.delete(
'/api/packages/test-package/uploaders/' +
self.normal_user('UpLoAdEr1').email())
self.assert_json_success(response)
package = Package.get_by_key_name('test-package')
self.assertEquals(
package.uploaders, [self.normal_user('uploader2')])