本文整理汇总了Python中models.Corporation类的典型用法代码示例。如果您正苦于以下问题:Python Corporation类的具体用法?Python Corporation怎么用?Python Corporation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Corporation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_corporation
def create_corporation(name, description="No description"):
if Corporation.by_name(name) is not None:
logging.info("Corporation with name '%s' already exists, skipping" % (name))
return Corporation.by_name(name)
logging.info("Create Corporation: %s" % name)
corp = Corporation(
name=unicode(name[:32]),
description=unicode(description[:1024]),
)
dbsession.add(corp)
dbsession.flush()
return corp
示例2: 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)
示例3: corporation_manage_department
def corporation_manage_department(request,url_number):
from accounts.models import Student
corporation = Corporation.objects(url_number=url_number).get()
if request.method == "POST":
if "user_url_number" in request.POST:
form_move = MoveMemberForm(request.POST)
if form_move.is_valid():
department_name = form_move.cleaned_data['department_name']
user_url_number = form_move.cleaned_data['user_url_number']
user = Student.objects(url_number=user_url_number).get()
sccard = S_C_Card.objects(user=user,corporation=corporation).get()
corporation.delete_member_from_department(sccard.department,user_url_number)
corporation.add_member_to_department(department_name,user_url_number)
return HttpResponseRedirect('')
elif "creat_department" in request.POST:
form_creat = CreatDepartmentForm(request.POST)
if form_creat.is_valid():
department_name = form_creat.cleaned_data['department_name']
corporation.creat_department(department_name)
return HttpResponseRedirect('')
elif "delete_department" in request.POST:
form_delete = DeleteDepartmentForm(request.POST)
if form_delete.is_valid():
department_name = form_delete.cleaned_data['department_name']
corporation.delete_department(department_name)
return HttpResponseRedirect('')
else:
form_move = MoveMemberForm()
form_creat = CreatDepartmentForm()
form_delete = DeleteDepartmentForm()
return render_to_response('corporation/corporation_manage_department.html', {'corporation':corporation, 'STATIC_URL':STATIC_URL, 'current_user':request.user}, context_instance=RequestContext(request))
示例4: edit_corporations
def edit_corporations(self):
''' Updates corporation object in the database '''
form = Form(
uuid="Object not selected",
name="Missing corporation name",
description="Missing description",
)
if form.validate(self.request.arguments):
corp = Corporation.by_uuid(self.get_argument('uuid'))
if corp is not None:
if self.get_argument('name') != corp.name:
logging.info("Updated corporation name %s -> %s" %
(corp.name, self.get_argument('name'),)
)
corp.name = unicode(self.get_argument('name'))
if self.get_argument('description') != corp.description:
logging.info("Updated corporation description %s -> %s" %
(corp.description, self.get_argument('description'),)
)
corp.description = unicode(self.get_argument('description'))
dbsession.add(corp)
dbsession.flush()
self.redirect('/admin/view/game_objects')
else:
self.render("admin/view/game_objects.html",
errors=["Corporation does not exist"]
)
else:
self.render("admin/view/game_objects.html", errors=form.errors)
示例5: visit_corporation_topics
def visit_corporation_topics(request, gurl_number):
corporation = Corporation.objects(url_number=gurl_number).get()
if request.method == "POST":
form = NewTopicForm(request.POST)
if form.is_valid():
title = form.cleaned_data['title']
content = form.cleaned_data['content']
topic = Topic(title=title)
turl_number = len(Topic.objects) + 1
topic.url_number = turl_number
topic.content = content
topic.creat_time = datetime.datetime.now()
topic.is_active = True
topic.is_locked = False
topic.is_top = False
topic.clicks = 0
topic.update_time = datetime.datetime.now()
topic.update_author = request.user
sccard = S_C_Card.objects(user=request.user, corporation=corporation).get()
topic.creator = sccard
topic.save()
return HttpResponseRedirect('/corporation/' + str(gurl_number) + '/topic/' + str(turl_number) + '/')
else:
form = NewTopicForm()
return render_to_response('corporation/corporation_topics.html', {'form':form, 'corporation':corporation, 'STATIC_URL':STATIC_URL, 'current_user':request.user}, context_instance=RequestContext(request))
示例6: showactivity
def showactivity(request, gurl_number, turl_number):
corporation = Corporation.objects(url_number=gurl_number).get()
activity = Activity.objects(url_number=turl_number).get()
if request.method == 'POST':
if "reply" in request.POST:
reply_form = NewReplyForm(request.POST)
if reply_form.is_valid():
content = reply_form.cleaned_data['content']
reply = Reply(content=content)
sccard = S_C_Card.objects(user=request.user, corporation=corporation).get()
reply.creator = sccard
reply.creat_time = datetime.datetime.now()
reply.target = activity
reply.is_active = True
reply.save()
activity.clicks = topic.clicks - 1
activity.save()
return HttpResponseRedirect('/corporation/' + str(gurl_number) + '/activity/' + str(turl_number) + '/')
else:
reply_form = NewReplyForm()
activity.clicks = activity.clicks + 1
activity.save()
return render_to_response('corporation/activity_corporation.html', {'corporation':corporation, 'current_user':request.user, 'reply_form':reply_form, 'activity':activity, 'STATIC_URL':STATIC_URL}, context_instance=RequestContext(request))
示例7: update_corporation
def update_corporation(corpID, sync=False):
"""
Updates a corporation from the API. If it's alliance doesn't exist,
update that as well.
"""
api = eveapi.EVEAPIConnection(cacheHandler=handler)
# Encapsulate this in a try block because one corp has a fucked
# up character that chokes eveapi
try:
corpapi = api.corp.CorporationSheet(corporationID=corpID)
except:
raise AttributeError("Invalid Corp ID or Corp has malformed data.")
if corpapi.allianceID:
try:
alliance = Alliance.objects.get(id=corpapi.allianceID)
except:
# If the alliance doesn't exist, we start a task to add it
# and terminate this task since the alliance task will call
# it after creating the alliance object
if not sync:
update_alliance.delay(corpapi.allianceID)
return
else:
# Something is waiting and requires the corp object
# We set alliance to None and kick off the
# update_alliance task to fix it later
alliance = None
update_alliance.delay(corpapi.allianceID)
else:
alliance = None
if Corporation.objects.filter(id=corpID).count():
# Corp exists, update it
corp = Corporation.objects.get(id=corpID)
corp.member_count = corpapi.memberCount
corp.ticker = corpapi.ticker
corp.name = corpapi.corporationName
corp.alliance = alliance
corp.save()
else:
# Corp doesn't exist, create it
corp = Corporation(id=corpID, member_count=corpapi.memberCount,
name=corpapi.corporationName, alliance=alliance)
corp.save()
return corp
示例8: creat_corporation
def creat_corporation(request):
if request.method == "POST":
form = CreatCorporationForm(request.POST)
if form.is_valid():
name = form.cleaned_data['name']
introduction = form.cleaned_data['introduction']
birthyear = form.cleaned_data['birthyear']
school = form.cleaned_data['school']
corporation = Corporation(name=name, introduction=introduction, school=school, birthyear=birthyear, logo=STATIC_URL + 'img/face.png')
url_number = len(Corporation.objects) + 1
corporation.url_number = url_number
corporation.creat_time = datetime.datetime.now()
if request.FILES:
path = 'img/corporation/' + str(url_number)
if not os.path.exists(MEDIA_ROOT + path):
os.makedirs(MEDIA_ROOT + path)
img = Image.open(request.FILES['logo'])
if img.mode == 'RGB':
filename = 'logo.jpg'
filename_thumbnail = 'thumbnail.jpg'
elif img.mode == 'P':
filename = 'logo.png'
filename_thumbnail = 'thumbnail.png'
filepath = '%s/%s' % (path, filename)
filepath_thumbnail = '%s/%s' % (path, filename_thumbnail)
# 获得图像的宽度和高度
width, height = img.size
# 计算宽高
ratio = 1.0 * height / width
# 计算新的高度
new_height = int(288 * ratio)
new_size = (288, new_height)
# 缩放图像
if new_height >= 288:
thumbnail_size = (0,0,288,288)
else:
thumbnail_size = (0,0,new_height,new_height)
out = img.resize(new_size, Image.ANTIALIAS)
thumbnail = out.crop(thumbnail_size)
thumbnail.save(MEDIA_ROOT + filepath_thumbnail)
corporation.thumbnail = MEDIA_URL + filepath_thumbnail
out.save(MEDIA_ROOT + filepath)
corporation.logo = MEDIA_URL + filepath
corporation.save()
sccard = S_C_Card(user=request.user, corporation=corporation, is_active=True, is_admin=True,creat_time=datetime.datetime.now())
sccard.save()
return HttpResponseRedirect('/corporation/' + str(url_number) + '/')
else:
return HttpResponseNotFound("出错了。。。。。")
else:
form = CreatCorporationForm()
return render_to_response('corporation/creat_corporation.html', {'form':form, 'STATIC_URL':STATIC_URL, 'current_user':request.user}, context_instance=RequestContext(request))
示例9: __mkbox__
def __mkbox__(self):
''' Creates a box in the database '''
corp = Corporation.by_uuid(self.get_argument('corporation_uuid'))
level = GameLevel.by_number(int(self.get_argument('game_level')))
box = Box(
name=unicode(self.get_argument('box_name')),
description=unicode(self.get_argument('description')),
difficulty=unicode(self.get_argument('difficulty')),
corporation_id=corp.id,
game_level_id=level.id,
)
dbsession.add(box)
dbsession.flush()
示例10: ask_quitcorporation
def ask_quitcorporation(request, url_number):
corporation = Corporation.objects(url_number=url_number).get()
if request.method == "POST":
form = NewAskForm(request.POST)
if form.is_valid():
content = form.cleaned_data['content']
creator = S_S_Card.objects.get_or_create(user=request.user, target__in=corporation.get_user_admin)
url_number = len(Sitemail.objects) + 1
mail = Sitemail(title='退社申请', content=content, creator=creator, creat_time=datetime.datetime.now(), is_readed=False, url_number=url_number).save()
return HttpResponse('success')
else:
return HttpResponse('success')
示例11: visit_corporation_structure
def visit_corporation_structure(request, url_number):
corporation = Corporation.objects(url_number=url_number).get()
if request.method == "POST":
form = NewAskForm(request.POST)
if form.is_valid():
content = form.cleaned_data['content']
creator = [a[0] for a in [S_S_Card.objects.get_or_create(user=request.user, target=admin) for admin in corporation.get_user_admin()]]
url_number = len(Sitemail.objects) + 1
mail = Sitemail(title='入社申请', content=content, creator=creator, creat_time=datetime.datetime.now(), is_readed=False, url_number=url_number).save()
S_C_Card(user=request.user,corporation=corporation,is_active=False,is_admin=False).save()
return HttpResponse('success')
else:
form = NewAskForm()
return render_to_response('corporation/corporation_structure.html', {'form':form,'current_user':request.user, 'url_number':url_number, 'corporation':corporation, 'STATIC_URL':STATIC_URL}, context_instance=RequestContext(request))
示例12: 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)
示例13: corporation_manage_edit
def corporation_manage_edit(request,url_number):
corporation = Corporation.objects(url_number=url_number).get()
if request.method == "POST":
form = ModifyCorporationForm(request.POST)
if form.is_valid():
name = form.cleaned_data['name']
introduction = form.cleaned_data['introduction']
corporation.update(set__name=name, set__introduction=introduction)
if request.FILES:
path = 'img/corporation/' + str(url_number)
if not os.path.exists(MEDIA_ROOT + path):
os.makedirs(MEDIA_ROOT + path)
img = Image.open(request.FILES['logo'])
if img.mode == 'RGB':
filename = 'logo.jpg'
filename_thumbnail = 'thumbnail.jpg'
elif img.mode == 'P':
filename = 'logo.png'
filename_thumbnail = 'thumbnail.png'
filepath = '%s/%s' % (path, filename)
filepath_thumbnail = '%s/%s' % (path, filename_thumbnail)
# 获得图像的宽度和高度
width, height = img.size
# 计算宽高
ratio = 1.0 * height / width
# 计算新的高度
new_height = int(288 * ratio)
new_size = (288, new_height)
# 缩放图像
if new_height >= 288:
thumbnail_size = (0,0,288,288)
else:
thumbnail_size = (0,0,new_height,new_height)
out = img.resize(new_size, Image.ANTIALIAS)
thumbnail = out.crop(thumbnail_size)
thumbnail.save(MEDIA_ROOT + filepath_thumbnail)
corporation.thumbnail = MEDIA_URL + filepath_thumbnail
out.save(MEDIA_ROOT + filepath)
corporation.logo = MEDIA_URL + filepath
corporation.save()
return HttpResponseRedirect('/corporation/' + str(url_number) + '/')
else:
form = ModifyCorporationForm()
return render_to_response('corporation/corporation_manage_edit.html', {'corporation':corporation, 'STATIC_URL':STATIC_URL, 'current_user':request.user}, context_instance=RequestContext(request))
示例14: visit_corporation_activity
def visit_corporation_activity(request, url_number):
corporation = Corporation.objects(url_number=url_number).get()
sccard = S_C_Card.objects(corporation=corporation,user=request.user).get()
if request.method == "POST":
form = CreatActivityForm(request.POST)
if form.is_valid():
name = form.cleaned_data['name']
start_time = form.cleaned_data['start_time']
finish_time = form.cleaned_data['finish_time']
place = form.cleaned_data['place']
max_student = form.cleaned_data['max_student']
pay = form.cleaned_data['pay']
detail = form.cleaned_data['detail']
aurl_number = len(Activity.objects) + 1
activity = Activity(creator=sccard,url_number=aurl_number,name=name,start_time=start_time,finish_time=finish_time,place=place,max_student=max_student,pay=pay,detail=detail,clicks = 0).save()
return HttpResponseRedirect('/corporation/' + str(url_number) + '/activity/' + str(aurl_number) + '/')
else:
form = CreatActivityForm()
return render_to_response('corporation/corporation_activity.html', {'form':form, 'current_user':request.user, 'url_number':url_number, 'corporation':corporation, 'STATIC_URL':STATIC_URL}, context_instance=RequestContext(request))
示例15: create_corporation
def create_corporation(self):
''' Add a new corporation to the database '''
form = Form(
corporation_name="Enter a corporation name",
description="Please enter a description",
)
if form.validate(self.request.arguments):
corp_name = self.get_argument('corporation_name')
if Corporation.by_name(corp_name) is not None:
self.render("admin/create/corporation.html",
errors=["Name already exists"]
)
else:
corporation = Corporation(
name=unicode(corp_name),
description=unicode(self.get_argument('description')),
)
dbsession.add(corporation)
dbsession.flush()
self.redirect('/admin/view/game_objects')
else:
self.render("admin/create/corporation.html", errors=form.errors)