示例#1
0
def submit(list_id=None):
    l = List.find_by_id(list_id)
    form = ListForm(request.form)

    if form.validate_on_submit():
        if l:
            l.update(name=form.name.data)
            flash('List Updated')
            return redirect(url_for('list_.index'))
        else:
            l = List.create(name=form.name.data,
                            account_id=current_user.account_id)
            if l:
                flash('List Created')
                return redirect(url_for('list_.edit', list_id=l.id))
    else:
        page = int(request.args.get('page', 1))
        flash_errors(form)

    pagination = List.find_all_desc().paginate(page=page, per_page=20)
    return render_template('list/index.html',
                           form=form,
                           list=l,
                           user=current_user,
                           pagination=pagination)
示例#2
0
def create_list(request):
    if request.method == 'GET':
        logger.info("creating new list form")
        form = ListForm()
        return render(request, 'create_list.html', {
            'form': form,
        })
    elif request.method == 'POST':
        logger.info("saving a new list")
        form = ListForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['name']
            description = form.cleaned_data['description']
            user = request.user
            list = List.objects.create_list(name=name, description=description, user=user)
            if list:
                follower = Follower.objects.create_follower(user=user, list=list)
                if follower:
                    #emailutil.send_follow_confirmation_email(user, list)
                    return HttpResponseRedirect('/%s' % list.url)
                else:
                    return HttpResponse(status=500)
        else:
            return render(request, 'create_list.html', {
                'form': form
            })
    else:
        logger.info("invalid operation")
示例#3
0
def index(request):
    """Function used to make empty formset forms required."""
    class RequiredFormSet(BaseFormSet):
        def __init__(self, *args, **kwargs):
            super(RequiredFormSet, self).__init__(*args, **kwargs)
            for form in self.forms:
                form.empty_permitted = False
    ItemFormSet = formset_factory(ItemForm, max_num=10, formset=RequiredFormSet)
    if request.method == 'POST': # If the form has been submitted...
        list_form = ListForm(request.POST) # A form bound to the POST data.
        # Create a formset form the submitted data.
        item_formset = ItemFormSet(request.POST, request.FILES)

        if list_form.is_valid() and item_formset.is_valid():
            list = list_form.save()
            for form in item_formset.forms:
                item = form.save(commit=False)
                item.list = list
                item.save()
            return HttpResponseRedirect('thanks') # Redirect to a 'success' page.

    else:
        list_form = ListForm()
        item_formset = ItemFormSet()

    # For CSRF protection:
    c = {'list_form': list_form,
         'item_formset': item_formset
        }
    c.update(csrf(request))

    return render_to_response('todo/index.html', c)
示例#4
0
def editList(list_id):
    listForm = ListForm()
    slist = Slist.query.get(list_id)
    if listForm.validate_on_submit():
        slist.name = listForm.name.data
        slist.note = listForm.note.data
        db.session.commit()
    return redirect(url_for('shopapp.shop_main'))
示例#5
0
文件: views.py 项目: iredkoz/testapp
def editList(list_id):
    listForm = ListForm()
    slist = Slist.query.get(list_id)
    if listForm.validate_on_submit():
        slist.name = listForm.name.data
        slist.note=listForm.note.data
        db.session.commit()
    return redirect(url_for('shopapp.shop_main'))
示例#6
0
文件: views.py 项目: f-enye/Lister
def CreateList():
	form = ListForm()
	if form.validate_on_submit():
		list_name = form.list_name.data

		create_list = List(list_name = list_name, user_id = g.user.id)
		db.session.add(create_list)
		db.session.commit()

	return render_template_with_base_object('create_list.html', title = 'Create List', form = form)
示例#7
0
文件: views.py 项目: iredkoz/testapp
def newlist():
    listForm = ListForm()
    name = listForm.name.data
    if listForm.validate_on_submit():
        if Slist.query.filter_by(name=name).first():
            flash('List with this name already exists!','alert-danger')
        else:
            slist = Slist(name=listForm.name.data, date=datetime.datetime.now().date(), note=listForm.note.data)
            db.session.add(slist)
            db.session.commit()
    return redirect(url_for('shopapp.shop_main'))
示例#8
0
文件: views.py 项目: cnzau/do-it-py
def create_list():
    form = ListForm()
    if request.method == "POST":
        if form.validate_on_submit():
            add_name = models.List(request.form['list_name'], current_user.id)
            db.session.add(add_name)
            db.session.commit()

            return redirect(url_for('index'))
        else:
            flash('Invalid Please try again.')
    return render_template('list_c.html', form=form)
示例#9
0
def newlist():
    listForm = ListForm()
    name = listForm.name.data
    if listForm.validate_on_submit():
        if Slist.query.filter_by(name=name).first():
            flash('List with this name already exists!', 'alert-danger')
        else:
            slist = Slist(name=listForm.name.data,
                          date=datetime.datetime.now().date(),
                          note=listForm.note.data)
            db.session.add(slist)
            db.session.commit()
    return redirect(url_for('shopapp.shop_main'))
示例#10
0
文件: views.py 项目: isergey/libcms
def change_list(request, id):
    list = get_object_or_404(List, id=id, user=request.user)
    if request.method == 'POST':
        form = ListForm(request.POST, instance=list)
        if form.is_valid():
            form.save()
            return redirect('mydocs:frontend:index')
    else:
        form = ListForm(instance=list)
    return render(request, 'mydocs/frontend/list_form.html', {
        'form': form,
        'list': list,
    })
示例#11
0
def setupa(request, userid):
    if request.method == "POST":
        form = ListForm(request.POST)
        if form.is_valid():
            a = form.cleaned_data['name']
            b = userid
            new = List.objects.create(name=a, user_id=b)
            new.save()
            return redirect("setupb", b)
    else:
        form = ListForm()
    data = {'form': form}

    return render(request, 'setupa.html', data)
示例#12
0
文件: views.py 项目: isergey/libcms
def create_list(request):
    if request.method == 'POST':
        form = ListForm(request.POST)
        if form.is_valid():
            list = form.save(commit=False)
            list.user = request.user
            list.save()
            return redirect('mydocs:frontend:index')
    else:
        form = ListForm()

    return render(request, 'mydocs/frontend/list_form.html', {
        'form': form,
    })
示例#13
0
def setupa(request, userid):
    if request.method == "POST":
        form = ListForm(request.POST)
        if form.is_valid():
                a = form.cleaned_data['name']
                b = userid
                new = List.objects.create(name=a, user_id=b)
                new.save()
                return redirect("setupb", b)
    else:
        form = ListForm()
    data = {'form': form}

    return render(request, 'setupa.html', data)
示例#14
0
def createplaylist(request,userid):
    if request.method == 'POST':
        form = ListForm(request.POST)
        if form.is_valid():
            a = form.cleaned_data['name']
            b = form.cleaned_data['description']
            c = userid
            new = List.objects.create(name=a, description=b, user_id=c)
            new.save()
            return render(request, 'postlogin/createplaylistb.html')

    else:
        form = ListForm()
    data = {'form': form}

    return render(request, 'postlogin/createplaylist.html',data)
示例#15
0
def shop_main():
    listForm = ListForm()
    itemForm = ItemForm()
    catForm = CategoryForm()
    prodForm = ProductForm()
    shopForm = ShopForm()

    lists = Slist.query.all()
    cats = Category.query.all()
    shops = Shop.query.all()
    prods = db.session.query(Slist.name,
                             func.count(Item.id)).join(Item).group_by(Slist.id)
    prods = dict(prods)

    return render_template('shopapp/shopapp.html',
                           units=units,
                           lists=lists,
                           listForm=listForm,
                           itemForm=itemForm,
                           catForm=catForm,
                           prodForm=prodForm,
                           shopForm=shopForm,
                           cats=cats,
                           shops=shops,
                           prods=prods)
示例#16
0
def index():
    form = ListForm()
    page = int(request.args.get('page', 1))
    pagination = List.find_all_desc().paginate(page=page, per_page=20)
    return render_template('list/index.html',
                           user=current_user,
                           pagination=pagination,
                           form=form)
示例#17
0
def list_monkeys():
    form = IdForm(request.form)
    args = ListForm(request.args, csrf_enabled=False)

    if args.validate():
        page = args.page.data
        per_page = args.per_page.data
        order = args.order.data
        descend = args.desc.data
    else:
        abort(404)

    if Monkey.query.count() == 0:
        monkeys = []
        pages = 0
    else:
        pagination = Monkey.query
        if order == 'friends':
            sign = -1 if descend else 1
            whens_ = {m.id: sign * m.friends.count()
                      for m in Monkey.query.all()}
            sort_order = case(value=Monkey.id, whens=whens_, else_=0)
            sort_order = sort_order.label('sort_order')
        elif order == 'bf':
            sign = -1 if descend else 1
            monkeys = sorted(Monkey.query.all(),
                             key=lambda m: NONE if m.bf is None else m.bf.name)
            whens_ = {monkeys[i].id: sign * i for i in range(0, len(monkeys))}
            sort_order = case(value=Monkey.id, whens=whens_, else_=0)
            sort_order = sort_order.label('sort_order')
        else:
            sort_order = order + (' desc' if descend else ' asc')
        pagination = pagination.order_by(sort_order).paginate(page, per_page)
        mlist = pagination.items
        pages = pagination.pages
        monkeys = [
            dict(id=monkey.id, name=monkey.name,
                 bf=monkey.bf.name if monkey.bf is not None else NONE,
                 friends=monkey.friends.count())
            for monkey in mlist
        ]

    return render_template('list.html', form=form,
                           monkeys=monkeys, page=page, pages=pages,
                           per_page=per_page, order=order, desc=descend)
示例#18
0
def show_user(username):

    if "username" not in session or username != session['username']:
        raise Unauthorized()
        

    user = User.query.get(username)
    form = ListForm()

    return render_template("show.html", user=user, form=form)   
示例#19
0
def ToDoList(request):
    """
    to-do list app
    """

    helper = utils()

    if request.method == 'POST':
        form = ListForm(request.POST or None)

        if form.is_valid():
            form.save()
            all_items = List.objects.all
            messages.success(request, "new item has been added successfully!!!")
            return render(request, "to_do_list.html", {'all_items': all_items})

    else:
        all_items = List.objects.all

        return render(request, "to_do_list.html", {'all_items': all_items})
示例#20
0
def index(request):
    """Function used to make empty formset forms required."""
    class RequiredFormSet(BaseFormSet):
        def __init__(self, *args, **kwargs):
            super(RequiredFormSet, self).__init__(*args, **kwargs)
            for form in self.forms:
                form.empty_permitted = False

    ItemFormSet = formset_factory(ItemForm,
                                  max_num=10,
                                  formset=RequiredFormSet)
    if request.method == 'POST':  # If the form has been submitted...
        list_form = ListForm(request.POST)  # A form bound to the POST data.
        # Create a formset form the submitted data.
        item_formset = ItemFormSet(request.POST, request.FILES)

        if list_form.is_valid() and item_formset.is_valid():
            list = list_form.save()
            for form in item_formset.forms:
                item = form.save(commit=False)
                item.list = list
                item.save()
            return HttpResponseRedirect(
                'thanks')  # Redirect to a 'success' page.

    else:
        list_form = ListForm()
        item_formset = ItemFormSet()

    # For CSRF protection:
    c = {'list_form': list_form, 'item_formset': item_formset}
    c.update(csrf(request))

    return render_to_response('todo/index.html', c)
示例#21
0
def create_list(user_id):
    user = User.query.get_or_404(user_id)
    if current_user != user:
        flash("Access unauthorized.", "danger")
        return redirect("/login")
    form = ListForm()
    if form.validate_on_submit():
        if pf.is_profane(form.name.data) == True:
            flash('Please avoid using profanity!', 'danger')
        else:
            try:
                new_list = List(name=form.name.data,
                                description=form.description.data,
                                user_id=user.id)
                db.session.add(new_list)
                db.session.commit()
                flash("List created successfully!", "success")
                return redirect(f"/my-lists/{user.id}")
            except IntegrityError:
                db.session.rollback()
                flash("You already have a list with this name!", "danger")
    return render_template('new-list.html', form=form)
示例#22
0
def create_list(request):
    if request.method == 'POST':
        form = ListForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('mydocs:frontend:index')
    else:
        form = ListForm()

    return render(request, 'mydocs/frontend/list_form.html', {
        'form': form,
    })
示例#23
0
def change_list(request, id):
    list = get_object_or_404(List, id=id)
    if request.method == 'POST':
        form = ListForm(request.POST, instance=list)
        if form.is_valid():
            form.save()
            return redirect('mydocs:frontend:index')
    else:
        form = ListForm(instance=list)
    return render(request, 'mydocs/frontend/list_form.html', {
        'form': form,
        'list': list,
    })
示例#24
0
def edit(list_id):
    l = List.find_by_id(list_id)
    if l:
        key = 'list_%s_import' % list_id
        if get_cache(key):
            flash(get_cache(key), 'warning')
            del_cache(key)
        random_data = l.random_data_sample()
        length = l.total_send_count()
        form = ListForm(obj=l)
        return render_template('list/edit.html',
                               form=form,
                               list=l,
                               data=random_data,
                               length=length)
    else:
        flash('List not found')
        return redirect(url_for('list_.index'))
示例#25
0
def add():
    form = ListForm()
    if form.validate_on_submit():
        store_list(form)
        return redirect(url_for('index'))
    return render_template('add.html', form=form)