def cfp(cfp_type='talk'): if cfp_type not in ['talk', 'workshop', 'installation']: abort(404) forms = [TalkProposalForm(), WorkshopProposalForm(), InstallationProposalForm()] (form,) = [f for f in forms if f.type == cfp_type] if request.method == 'POST': app.logger.info('Checking %s proposal for %s (%s)', cfp_type, form.name.data, form.email.data) if form.validate_on_submit(): if cfp_type == 'talk': cfp = TalkProposal() cfp.length = form.length.data cfp.experience = form.experience.data cfp.one_day = form.one_day.data elif cfp_type == 'workshop': cfp = WorkshopProposal() cfp.length = form.length.data cfp.attendees = form.attendees.data cfp.one_day = form.one_day.data elif cfp_type == 'installation': cfp = InstallationProposal() cfp.size = form.size.data cfp.name = form.name.data cfp.email = form.email.data cfp.title = form.title.data cfp.description = form.description.data cfp.need_finance = form.need_finance.data cfp.diversity = ProposalDiversity() cfp.diversity.age = form.diversity.age.data cfp.diversity.gender = form.diversity.gender.data cfp.diversity.ethnicity = form.diversity.ethnicity.data db.session.add(cfp) db.session.commit() return redirect(url_for('cfp_complete')) if current_user.is_authenticated(): form.name.data = current_user.name form.email.data = current_user.email full_price = TicketType.query.get('full').get_price('GBP') return render_template('cfp.html', full_price=full_price, forms=forms, active_cfp_type=cfp_type, has_errors=bool(form.errors))
def run(self, filename, state): faker = Faker() with open(filename) as csvfile: # id, title, description, length, need_finance, # one_day, type, experience, attendees, size reader = DictReader(csvfile) count = 0 for row in reader: if Proposal.query.filter_by(title=row['title']).first(): continue user = User('*****@*****.**' % count, faker.name()) db.session.add(user) proposal = TalkProposal() if row['type'] == u'talk' else\ WorkshopProposal() if row['type'] == u'workshop' else\ InstallationProposal() proposal.state = state proposal.title = row['title'] proposal.description = row['description'] proposal.one_day = True if row.get('one_day') == 't' else False proposal.needs_money = True if row.get( 'need_finance') == 't' else False if row['type'] == 'talk': proposal.length = row['length'] elif row['type'] == 'workshop': proposal.length = row['length'] proposal.attendees = row['attendees'] else: proposal.size = row['size'] proposal.user = user db.session.add(proposal) db.session.commit() count += 1 app.logger.info('Imported %s proposals' % count)
def run(self, filename, state): faker = Faker() with open(filename) as csvfile: # id, title, description, length, need_finance, # one_day, type, experience, attendees, size reader = DictReader(csvfile) count = 0 for row in reader: if Proposal.query.filter_by(title=row['title']).first(): continue user = User('*****@*****.**' % count, faker.name()) db.session.add(user) proposal = TalkProposal() if row['type'] == u'talk' else\ WorkshopProposal() if row['type'] == u'workshop' else\ InstallationProposal() proposal.state = state proposal.title = row['title'] proposal.description = row['description'] proposal.one_day = True if row.get('one_day') == 't' else False proposal.needs_money = True if row.get('need_finance') == 't' else False if row['type'] == 'talk': proposal.length = row['length'] elif row['type'] == 'workshop': proposal.length = row['length'] proposal.attendees = row['attendees'] else: proposal.size = row['size'] proposal.user = user db.session.add(proposal) db.session.commit() count += 1 app.logger.info('Imported %s proposals' % count)