Пример #1
0
def edit_subscriber(id):
    form = SubscriberForm()
    subscriber = data_services.get_subscriber_by_id(id)
    if request.method == "GET":
        form = SubscriberForm(obj=subscriber)
        return render_template('edit_subscriber.html',
                               form=form,
                               status='edit')
    elif request.method == 'POST':
        if form.update.data:
            if form.validate_on_submit():
                data_services.update_subscriber(subs=subscriber,
                                                firstname=form.first_name.data,
                                                lastname=form.last_name.data,
                                                email=form.email.data,
                                                address=form.address.data,
                                                ssn=form.ssn.data)
                flash('Subscriber created successfully', 'success')
            else:
                for k, v in form.errors.items():
                    flash(v[0], 'danger')
                return render_template('edit_subscriber.html',
                                       form=form,
                                       status='edit')
        elif form.delete.data:
            data_services.delete_subscriber(subs=subscriber)
            flash('Subscriber deleted successfully', 'success')
        return redirect('/subscriber/list')
Пример #2
0
def edit_subscriber(id):
    subscriber = Subscriber.objects(id=id).first()
    form = SubscriberForm(obj=subscriber)
    if request.method == 'GET':
        return render_template('subscriber.html', form=form, id=id)
    elif request.method == 'POST':
        if form.submit.data:
            if form.validate_on_submit():
                subscriber.name = form.name.data
                subscriber.email = form.email.data
                subscriber.phone = form.phone.data
                subscriber.address = form.address.data
                subscriber.save()
                flash("Subscriber created successfully", 'success')
        return redirect("/list")
Пример #3
0
def create_subscriber():
    form = SubscriberForm()
    if request.method == 'GET':
        return render_template('subscriber.html', form=form)
    elif request.method == 'POST':
        if form.submit.data:
            if form.validate_on_submit():
                subscriber = Subscriber()
                subscriber.name = form.name.data
                subscriber.email = form.email.data
                subscriber.phone = form.phone.data
                subscriber.address = form.address.data
                subscriber.save()
                flash("Subscriber created successfully", 'success')
        return redirect('/list')
Пример #4
0
def new_subscriber():
    form = SubscriberForm()
    if request.method == 'GET':
        return render_template('edit_subscriber.html', form=form, status='new')
    elif request.method == 'POST':
        if form.validate_on_submit():
            data_services.create_subscriber(firstname=form.first_name.data,
                                            lastname=form.last_name.data,
                                            email=form.email.data,
                                            address=form.address.data,
                                            ssn=form.ssn.data)
            flash('Subscriber created successfully', 'success')
        else:
            for k, v in form.errors.items():
                flash(v[0], 'danger')
            return render_template('edit_subscriber.html',
                                   form=form,
                                   status='new')
        return redirect('/subscriber/list')