def save_training_program(key='', title='', venue='', faculty='', when_from='', when_to='', when_registration_ends='', participation_counts=[], participation_fees=[]): if key: training_program = db.get(db.Key(key)) else: training_program = models.TrainingProgram training_program.title = title training_program.venue = venue training_program.faculty = faculty training_program.when_from = parse_iso_datetime_string(when_from) training_program.when_to = parse_iso_datetime_string(when_to) training_program.when_registration_ends = parse_iso_datetime_string(when_registration_ends) training_program.put() fees = [] for count, fee in izip(participation_counts, participation_fees): tpfee = models.TrainingProgramFee() tpfee.for_participation_count = count if '.' in fee: fee_integer, fee_fraction = fee.split('.') else: fee_integer, fee_fraction = fee, '0' tpfee.fee_integer = dec(fee_integer) tpfee.fee_fraction = dec(fee_fraction) tpfee.training_program = training_program fees.append(tpfee) db.put(fees)
def post(self, key): training_program = db.get(db.Key(key)) title = self.request.get('title') venue = self.request.get('venue') when_from = self.request.get('when_from') when_to = self.request.get('when_to') faculty = self.request.get('faculty') when_registration_ends = self.request.get('when_registration_ends') when_payment_is_calculated = self.request.get('when_payment_is_calculated') max_participants = self.request.get('max_participants') brochure_url = self.request.get('brochure_url') description = self.request.get("description") training_program.title = title training_program.venue = venue training_program.when_from = parse_iso_datetime_string(when_from) training_program.when_to = parse_iso_datetime_string(when_to) training_program.faculty = faculty training_program.when_registration_ends = parse_iso_datetime_string(when_registration_ends) training_program.when_payment_is_calculated = parse_iso_datetime_string(when_payment_is_calculated) training_program.max_participants = dec(max_participants) training_program.brochure_url = brochure_url training_program.description = description fees1 = Decimal(self.request.get('fees_1')) fees2 = Decimal(self.request.get('fees_2')) fees3 = Decimal(self.request.get('fees_3')) participants1 = dec(self.request.get('participants_1')) participants2 = dec(self.request.get('participants_2')) participants3 = dec(self.request.get('participants_3')) fees = training_program.fees fees_1 = fees[0] fees_2 = fees[1] fees_3 = fees[2] fees_1.fee = fees1 fees_1.for_participant_count = participants1 fees_2.fee = fees2 fees_2.for_participant_count = participants2 fees_3.fee = fees3 fees_3.for_participant_count = participants3 db.put([training_program, fees_1, fees_2, fees_3]) self.response.out.write(training_program.to_json('title', 'is_deleted', 'is_active', 'is_starred', 'when_created'))
def post(self): title = self.request.get('title') venue = self.request.get('venue') when_from = self.request.get('when_from') when_to = self.request.get('when_to') faculty = self.request.get('faculty') when_registration_ends = self.request.get('when_registration_ends') when_payment_is_calculated = self.request.get('when_payment_is_calculated') max_participants = self.request.get('max_participants') brochure_url = self.request.get('brochure_url') description = self.request.get("description") training_program = TrainingProgram() training_program.title = title training_program.venue = venue training_program.when_from = parse_iso_datetime_string(when_from) training_program.when_to = parse_iso_datetime_string(when_to) training_program.faculty = faculty training_program.when_registration_ends = parse_iso_datetime_string(when_registration_ends) training_program.when_payment_is_calculated = parse_iso_datetime_string(when_payment_is_calculated) training_program.max_participants = dec(max_participants) training_program.brochure_url = brochure_url training_program.description = description training_program.put() fees1 = Decimal(self.request.get('fees_1')) fees2 = Decimal(self.request.get('fees_2')) fees3 = Decimal(self.request.get('fees_3')) participants1 = dec(self.request.get('participants_1')) participants2 = dec(self.request.get('participants_2')) participants3 = dec(self.request.get('participants_3')) fees_1 = TrainingProgramFee(fee=fees1, for_participant_count=participants1) fees_1.training_program = training_program fees_2 = TrainingProgramFee(fee=fees2, for_participant_count=participants2) fees_2.training_program = training_program fees_3 = TrainingProgramFee(fee=fees3, for_participant_count=participants3) fees_3.training_program = training_program db.put([fees_1, fees_2, fees_3]) self.response.out.write(training_program.to_json('title', 'is_deleted', 'is_active', 'is_starred', 'when_created'))