コード例 #1
0
ファイル: views.py プロジェクト: nevilgeorge/bulk-sms
def sender():
    """Render show senders/ add sender page."""

    add_sender_form = forms.AddSenderForm()

    if add_sender_form.validate_on_submit():
        number = utils.normalize_number(add_sender_form.sender_number.data)
        try:
            sender_repo.create_one(number=number)

            # check for numbers with no sender_id
            sender = sender_repo.get_min_sender()
            numbers = number_repo.get_many_by_kwargs(sender_id=None)
            for number in numbers:
                number.sender_id = sender.id
                db.session.add(number)
            db.session.commit()

            flash('Sender added!', 'success')
        except DuplicateError as e:
            flash('Sender already exists!', 'error')
            print e
            pass

        # reset form
        add_sender_form.sender_number.data = None

    senders = sender_repo.get_all()

    return render_template('sender.html',
                           senders=senders,
                           add_sender_form=add_sender_form)
コード例 #2
0
ファイル: number_repo.py プロジェクト: nevilgeorge/bulk-sms
def create_one(**kwargs):
    """Create Number entity using kwargs."""
    min_sender = sender_repo.get_min_sender()
    kwargs['sender_id'] = min_sender.id if min_sender != None else None
    number = models.Number(**kwargs)
    db.session.add(number)
    try:
        db.session.commit()
    except IntegrityError:
        db.session.rollback()
        e = DuplicateError('Number already exists!')
        e.number = number.number
        raise e

    return number
コード例 #3
0
ファイル: views.py プロジェクト: NUWildHacks/bulk-sms
def sender():
	"""Render show senders/ add sender page."""

	add_sender_form = forms.AddSenderForm()

	if add_sender_form.validate_on_submit():
		number = utils.normalize_number(add_sender_form.sender_number.data)
		try:
			sender_repo.create_one(
				number=number
			)

			# check for numbers with no sender_id
			sender = sender_repo.get_min_sender()
			numbers = number_repo.get_many_by_kwargs(
				sender_id=None
			)
			for number in numbers:
				number.sender_id = sender.id
				db.session.add(number)
			db.session.commit()

			flash('Sender added!', 'success')
		except DuplicateError as e:
			flash('Sender already exists!', 'error')
			print e
			pass

		# reset form
		add_sender_form.sender_number.data = None

	senders = sender_repo.get_all()

	return render_template(
		'sender.html',
		senders=senders,
		add_sender_form=add_sender_form
	)