本文整理汇总了Python中models.Box类的典型用法代码示例。如果您正苦于以下问题:Python Box类的具体用法?Python Box怎么用?Python Box使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Box类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: edit_ipv6
def edit_ipv6(self):
''' Add ipv6 addresses to a box (sorta edits the box object) '''
form = Form(box_uuid="Select a box", ipv6="Please provide a list of IPv6 addresses")
if form.validate(self.request.arguments):
errors = []
box = Box.by_uuid(self.get_argument('box_uuid'))
if box is not None:
ips_string = self.get_argument('ipv6').replace('\n', ',').lower()
ips = filter(lambda char: char in "1234567890abcdef:,", ips_string).split(",")
for ip in filter(lambda ip: 0 < len(ip), ips):
try:
box = Box.by_ip_address(ip)
if box is None:
addr = IpAddress(box_id=box.id, v6=ip)
dbsession.add(addr)
else:
errors.append(
"%s has already been assigned to %s." % (ip, box.name,)
)
except ValueError:
errors.append(
"'%s' is not a valid IPv6 address" % str(ip[:39])
)
dbsession.flush()
else:
errors.append("Box does not exist")
self.render("admin/view/game_objects.html", errors=errors)
else:
self.render("admin/view/game_objects.html", errors=form.errors)
开发者ID:mach327,项目名称:RootTheBox,代码行数:29,代码来源:AdminHandlers.py
示例2: process_request
def process_request(self, request):
""" This function sets up the user object
Depending on the value of require_login, it
can return None as 'profile'.
"""
#Get Google user_id
google_user = users.get_current_user()
account = None
is_admin = False
logging.info(request.META['HTTP_USER_AGENT'])
if google_user:
#Check if the user already has a site profile
user_id = google_user.user_id()
is_admin = users.is_current_user_admin()
q = Account.all()
q.filter('google_user =', google_user)
account = q.get()
if not account:
nickname = hashlib.md5(google_user.nickname()).hexdigest()[:10]
account = Account(user_id = user_id, nickname = nickname)
account.put()
box = Box(title='My Box')
box.put()
request.user = account
Account.current_user_account = account
request.user_is_admin = is_admin
开发者ID:noio,项目名称:Cardbox,代码行数:28,代码来源:middleware.py
示例3: test_move_contents_together
def test_move_contents_together(self):
# Make some test pages.
p1 = Page()
p1.title = 'Test Page 1'
p1.save()
p2 = Page()
p2.title = 'Test Page 2'
p2.save()
# Make two test boxes.
b1 = Box()
b1.save()
b2 = Box()
b2.save()
# Put two pages in box 1.
b1.add_content( (p1, p2) )
# Put two pages in the same box into an envelope.
e.add_content( (p1, p2) )
# Move the envelope to box 2.
e.move_to_box(b2)
self.assertFalse(b1.contains_content(p1), "Page 1 did not leave box 1.")
self.assertFalse(b1.contains_content(p2), "Page 2 did not leave box 1.")
self.assertTrue(b2.contains_content(p1), "Page 1 did not move to box 2.")
self.assertTrue(b2.contains_content(p2), "Page 2 did not move to box 2.")
开发者ID:pombredanne,项目名称:django-dogwood,代码行数:28,代码来源:tests.py
示例4: test_combine_envelope_contents
def test_combine_envelope_contents(self):
# Make some pages.
p1 = Page()
p1.save()
p2 = Page()
p2.save()
p3 = Page()
p3.save()
p4 = Page()
p4.save()
# Make a box for them.
b = Box()
b.save()
# Put them in the box.
box.add_content( (p1, p2, p3, p4) )
# Make two envelopes and put pages in them.
e1 = Envelope()
e1.add_content( (p1, p2) )
e2 = Envelope()
e2.add_content( (p3, p4) )
# Combine envelope contents.
e2.send_contents_to_envelope(e1)
self.assertEqual(len(e2.contents.all()), 0,
"Some content is still left in sending envelope.")
self.assertEqual(len(e1.contents.all()), 4,
"Content in receiving envelope is not correct.")
for page in [p1, p2, p3, p4]:
self.assertTrue(page in e1.get_content(),
"Page not found in receiving envelope.")
开发者ID:pombredanne,项目名称:django-dogwood,代码行数:34,代码来源:tests.py
示例5: addbox
def addbox(request):
request.session.set_expiry(0)
box = Box()
location_id = request.POST['sel2']
box.Location = Location.objects.get(id = location_id)
box.save()
return redirect('admin')
开发者ID:dkeske,项目名称:KutijaSajt,代码行数:8,代码来源:views.py
示例6: test_box_descriptor
def test_box_descriptor(self):
b = Box()
self.assertTrue(b.descriptor is None, "Descriptor not initialized to None.")
p = Page()
p.title = 'Testbox 1'
p.data = 'This Page is used as the descriptor for Testbox 1.'
p.save()
b.descriptor = p
b.save()
self.assertTrue(b.descriptor == p, "Descriptor not saved.")
self.assertTrue(p.describes_box == b, "Descriptor does not point back to box.")
开发者ID:pombredanne,项目名称:django-dogwood,代码行数:13,代码来源:tests.py
示例7: create_box
def create_box(self):
''' Create a box object '''
form = Form(
box_name="Enter a box name",
description="Enter a description",
difficulty="Select a difficulty",
corporation_uuid="Please select a corporation",
game_level="Please select a game level",
)
if form.validate(self.request.arguments):
try:
game_level = int(self.get_argument('game_level'))
corp_uuid = self.get_argument('corporation_uuid')
if Box.by_name(self.get_argument('box_name')) is not None:
self.render("admin/create/box.html",
errors=["Box name already exists"]
)
elif Corporation.by_uuid(corp_uuid) is None:
self.render("admin/create/box.html",
errors=["Corporation does not exist"]
)
elif GameLevel.by_number(game_level) is None:
self.render("admin/create/box.html",
errors=["Game level does not exist"]
)
else:
self.__mkbox__()
self.redirect('/admin/view/game_objects')
except ValueError:
self.render('admin/view/create.html',
errors=["Invalid level number"]
)
else:
self.render("admin/create/box.html", errors=form.errors)
开发者ID:mach327,项目名称:RootTheBox,代码行数:34,代码来源:AdminHandlers.py
示例8: scoring_round
def scoring_round():
''' Multi-threaded scoring '''
boxes = list(Box.get_all())
logging.info("Starting scoring round with %d boxes" % len(boxes))
for box in boxes:
score_box(box)
logging.info("Scoring round completed")
开发者ID:xaelek,项目名称:RootTheBox,代码行数:7,代码来源:AuthenticateReporter.py
示例9: savePaths
def savePaths(request, paths, strokeWidth, strokeColor, object_type, fillColor=None):
# if not request.user.is_authenticated():
# return simplejson.dumps({'state': 'not_logged_in'})
print "hih"
print request.user.username
pIDs = []
pks = []
for path in paths:
pID = path['pID']
points = path['points']
planet = str(path['planet']['x'])+','+str(path['planet']['y'])
lockedAreas = Box.objects(planet=planet, box__geo_intersects={"type": "LineString", "coordinates": points } )
if lockedAreas.count()>0:
return simplejson.dumps( {'state': 'error', 'message': 'Your drawing intersects with a locked area'} )
p = Path(planet=planet, points=points, owner=request.user.username, strokeColor=strokeColor, fillColor=fillColor, strokeWidth=strokeWidth, object_type=object_type, pID=pID )
p.save()
pIDs.append(pID)
pks.append(p.pk)
return simplejson.dumps( {'state': 'success', 'pIDs': pIDs, 'pk': pks} )
开发者ID:arthur-test-account,项目名称:Romanesco,代码行数:26,代码来源:ajax.py
示例10: create_flag
def create_flag(self):
''' Create a flag '''
form = Form(
box_uuid="Please select a box",
flag_name="Please enter a name",
token="Please enter a token value",
reward="Please enter a reward value",
is_file="Please select a file setting",
description="Please enter a flag description",
)
if form.validate(self.request.arguments):
try:
if Flag.by_name(self.get_argument('flag_name')) is not None:
self.render('admin/create/flag.html',
errors=["Name already exists"]
)
elif Flag.by_token(self.get_argument('token')) is not None:
self.render('admin/create/flag.html',
errors=["Token value is not unique"]
)
elif Box.by_uuid(self.get_argument('box_uuid')) is None:
self.render('admin/create/flag.html',
errors=["Box does not exist"]
)
else:
reward = int(self.get_argument('reward', 'NaN'))
self.__mkflag__(reward)
self.redirect('/admin/view/game_objects')
except ValueError:
self.render('admin/create/flag.html',
errors=["Invalid reward value"]
)
else:
self.render("admin/create/flag.html", errors=form.errors)
开发者ID:mach327,项目名称:RootTheBox,代码行数:34,代码来源:AdminHandlers.py
示例11: add_source_code
def add_source_code(self):
form = Form(
box_uuid="Please select a box",
price="Please input a price for the source code",
description="Please enter a description",
)
if form.validate(self.request.arguments):
box = Box.by_uuid(self.get_argument('box_uuid'))
if box is not None:
if not 'source_archive' in self.request.files and 0 < len(self.request.files['source_archive']):
self.render('admin/upgrades/source_code_market.html',
errors=["No file data"]
)
else:
try:
price = abs(int(self.get_argument('price', 'NaN')))
self.create_source_code(box, price)
self.render('admin/upgrades/source_code_market.html',
errors=None
)
except ValueError:
self.render('admin/upgrades/source_code_market.html',
errors=["Price must be an integer"]
)
else:
self.render('admin/upgrades/source_code_market.html',
errors=["The selected box does not exist"]
)
else:
self.render('admin/upgrades/source_code_market.html',
errors=form.errors
)
开发者ID:mach327,项目名称:RootTheBox,代码行数:32,代码来源:AdminHandlers.py
示例12: render_page
def render_page(self, errors=None):
''' Addes extra params to render() '''
user = self.get_current_user()
boxes = filter(lambda box: box.source_code is not None, Box.all())
self.render('upgrades/source_code_market.html',
user=user, boxes=boxes, errors=errors
)
开发者ID:brutalhonesty,项目名称:RootTheBox,代码行数:7,代码来源:UpgradeHandlers.py
示例13: edit_boxes
def edit_boxes(self):
''' Edit existing boxes in the database '''
form = Form(
uuid="Object not selected",
name="Missing box name",
corporation_uuid="Please select a corporation",
description="Please enter a description",
difficulty="Please enter a difficulty",
)
if form.validate(self.request.arguments):
box = Box.by_uuid(self.get_argument('uuid'))
if box is not None:
errors = []
if self.get_argument('name') != box.name:
if Box.by_name(self.get_argument('name')) is None:
logging.info("Updated box name %s -> %s" %
(box.name, self.get_argument('name'),)
)
box.name = unicode(self.get_argument('name'))
else:
errors.append("Box name already exists")
corp = Corporation.by_uuid(self.get_argument('corporation_uuid'))
if corp is not None and corp.id != box.corporation_id:
logging.info("Updated %s's corporation %s -> %s" %
(box.name, box.corporation_id, corp.id,))
box.corporation_id = corp.id
elif corp is None:
errors.append("Corporation does not exist")
if self.get_argument('description') != box.description:
logging.info("Updated %s's description %s -> %s" %
(box.name, box.description, self.get_argument('description'),)
)
box.description = unicode(self.get_argument('description'))
if self.get_argument('difficulty') != box.difficulty:
logging.info("Updated %s's difficulty %s -> %s" %
(box.name, box.difficulty, self.get_argument('difficulty'),)
)
box.difficulty = unicode(self.get_argument('difficulty'))
dbsession.add(box)
dbsession.flush()
self.render("admin/view/game_objects.html", errors=errors)
else:
self.render("admin/view/game_objects.html",
errors=["Box does not exist"]
)
else:
self.render("admin/view/game_objects.html", errors=form.errors)
开发者ID:mach327,项目名称:RootTheBox,代码行数:47,代码来源:AdminHandlers.py
示例14: test_box_timeline
def test_box_timeline(self):
if not settings.BOX_USES_TIMELINE: return
# What is the latest time, before we start?
start = self._get_latest_time()
# @ Time 1: Create empty box.
b = Box()
b.save()
box_created = self._get_latest_time()
self.assertTrue( (box_created > start),
"Timeline not advanced on box creation." )
# @ Time 2: Add pages to box.
b.add_content( [p1, p2] )
pages_added = self._get_latest_time()
self.assertTrue( (pages_added > box_created),
"Timeline not advanced on content addition." )
# @ Time 4: Remove page 1 from box.
b.remove_content(p1)
page_removed = self._get_latest_time()
self.assertTrue( (page_removed > pages_added),
"Timeline not advanced on content removal." )
# Verify that box contains one page at the present time.
self.assertEqual(len(b.contents.all()), 1,
"Box contents at present time not correct.")
# View box pages @ time 2 again.
way_back_when = b.contents.filter(added__lte=pages_added,
removed__gt=pages_added)
self.assertEqual(len(way_back_when), 2,
"Box contents at prior time not correct.")
开发者ID:pombredanne,项目名称:django-dogwood,代码行数:33,代码来源:tests.py
示例15: open
def open(self):
''' When we receive a new websocket connect '''
box = Box.by_ip_address(self.request.remote_ip)
if box is not None:
self.box = box
self.remote_ip = self.request.remote_ip
self.write_message("box ok")
else:
self.close()
开发者ID:brutalhonesty,项目名称:RootTheBox,代码行数:9,代码来源:BotHandlers.py
示例16: render_page
def render_page(self, flag, errors=[]):
''' Wrapper to .render() to avoid duplicate code '''
user = self.get_current_user()
box = Box.by_id(flag.box_id)
self.render('missions/box.html',
box=box,
team=user.team,
errors=errors,
)
开发者ID:CRYPTOlab,项目名称:RootTheBox,代码行数:9,代码来源:MissionsHandler.py
示例17: scoring_round
def scoring_round():
'''
Executed as a periodic callback for main io_loop: Iterates of all the boxes
and scores each box.
'''
boxes = list(Box.all())
logging.info("Starting scoring round with %d boxes" % len(boxes))
for box in boxes:
score_box(box)
logging.info("Scoring round completed")
开发者ID:brutalhonesty,项目名称:RootTheBox,代码行数:10,代码来源:AuthenticateReporter.py
示例18: to_dict
def to_dict(self):
''' Returns public data as a dict '''
box = Box.by_id(self.box_id)
return {
'name': self.name,
'uuid': self.uuid,
'description': self.description,
'value': self.value,
'box': box.uuid,
'token': self.token,
}
开发者ID:CRYPTOlab,项目名称:RootTheBox,代码行数:11,代码来源:Flag.py
示例19: handle_mouse
def handle_mouse(self, e, x, y, flags, param):
if self.mode == 'set_middle':
if e == cv2.EVENT_LBUTTONDOWN:
self.platform_middle = (x, y)
self.mode = None
else:
if e == cv2.EVENT_LBUTTONDOWN:
self.area = Box(x, y, None, None)
elif e == cv2.EVENT_LBUTTONUP:
self.area.x2 = x
self.area.y2 = y
开发者ID:kirberich,项目名称:3dscanner,代码行数:11,代码来源:scanner.py
示例20: open
def open(self, *args):
""" Steps 1 and 2; called when a new bot connects """
box = Box.by_ip_address(self.request.remote_ip)
self.remote_ip = self.request.remote_ip
if box is None and self.config.whitelist_box_ips:
logging.debug("Rejected bot from '%s' (not a box)" % self.request.remote_ip)
self.write_message({"opcode": "error", "message": "Invalid IP address."})
self.close()
else:
logging.debug("Interrogating bot on %s" % self.request.remote_ip)
self.write_message({"opcode": "interrogate", "xid": self.xid})
开发者ID:harite,项目名称:RootTheBox,代码行数:11,代码来源:BotnetHandlers.py
注:本文中的models.Box类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论