def create_corporation(name, description="No description"): print(INFO + "Create corporation: " + bold + name + W) corp = Corporation( name=unicode(name), description=unicode(description), ) dbsession.add(corp) dbsession.flush() return corp
def initDbForE2e(wipe=True): if wipe: clearDB() # TODO: Id of user a admin_id = 123 db.session.add( Character( id=admin_id, user_id=admin_id, name='ADMIN NAME', corporation_id=ascee_corp_id, refresh_token='YOUR TOKEN HERE', )) db.session.add(Admin( id=admin_id, user_id=admin_id, name='Billy Admin', )) # TODO: Id of recruiter user recruiter_id = 345 db.session.add( Character(id=recruiter_id, user_id=recruiter_id, name='RECRUITER NAME', corporation_id=ascee_corp_id, refresh_token='YOUR TOKEN HERE')) db.session.add(Recruiter( id=recruiter_id, name='RECRUITER NAME', )) # TODO: Id of applicant user character_id = 234 db.session.add( Character(id=character_id, user_id=character_id, name='APPLICANT NAME', corporation_id=ascee_corp_id, corporation=Corporation(id=ascee_corp_id, name='ASCEE'), refresh_token='YOUR TOKEN HERE')) db.session.add(User( id=character_id, name='APPLICANT NAME', )) db.session.add(Question(text='How long have you been playing Eve?')) db.session.add(Question(text='PVP or PVE? Why?')) db.session.add(Application(user_id=character_id)) db.session.commit()
def create_corporation(self): corporation = Corporation(creator_user_id=current_user.id, name=self.name) # try: db.session.add(corporation) db.session.flush() admin = AdminAccess(corporation_id=corporation.id). \ create_creator_admin() db.session.commit() return corporation, admin
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 f****d # 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
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)
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', thumbnail=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))
def enterpriseRegiste(request): if request.method == "POST": telephone = request.POST.get("telephone") servicetype = request.POST.getlist("servicetype") content = '' for s in servicetype: content = content + s + ',' print servicetype pic1 = request.FILES['pic1'] pic2 = request.FILES['pic2'] pic1_path = "" pic2_path = "" if pic1: phototime = request.user.username + str(time.time()).split('.')[0] photo_last = str(pic1).split('.')[-1] photoname = 'photos/%s.%s' % (phototime, photo_last) img = Image.open(pic1) img.save( '/Users/xieyaxiong/PycharmProjects/SpaceWebsite/pic_folder/' + photoname) pic1_path = '/pic_folder/' + photoname if pic2: phototime = request.user.username + str(time.time()).split('.')[0] photo_last = str(pic2).split('.')[-1] photoname = 'photos/%s.%s' % (phototime, photo_last) img = Image.open(pic2) img.save( '/Users/xieyaxiong/PycharmProjects/SpaceWebsite/pic_folder/' + photoname) pic2_path = '/pic_folder/' + photoname corporation = Corporation() corporation.telephone = telephone corporation.businessLicence = pic1_path corporation.serviceContent = content corporation.corporateCharter = pic2_path account = Account.objects.get(telephone=request.session['login']) corporation.userid_id = account.id corporation.save() corporation = Corporation.objects.get(userid_id=account.id) return render(request, 'frontsite/enterpriseDisplay.html', {"corporation": corporation}) else: if request.session.has_key('login'): account = Account.objects.get(telephone=request.session['login']) count = Corporation.objects.filter(userid_id=account.id).count() if count > 0: corporation = Corporation.objects.get(userid_id=account.id) return render(request, 'frontsite/enterpriseDisplay.html', {"corporation": corporation}) else: serviceTypes = ServiceType.objects.all() services = Services.objects.all() return render(request, 'frontsite/enterpriseRegiste.html', { "servicetypes": serviceTypes, "services": services }) else: return HttpResponseRedirect( '/frontsite/login/?returnUrl=/frontsite/enterpriseRegiste/')