Exemplo n.º 1
0
def showItem(request, item_id=1):
    if request.POST:
        form = NotificationForm(request.POST)
        if form.is_valid():
            # do not save yet, and add in default owners_id
            obj = form.save(commit=False)
            # add in the creator's id
            obj.requestedFrom = request.user
            obj.requestedTo = Items.objects.get(id=item_id).owners
            obj.item = Items.objects.get(id=item_id)
            obj.state = "Pending"
            # save data
            obj.save()

            return HttpResponseRedirect("/web/main/")
    else:
        form = NotificationForm()

    args = {}
    args.update(csrf(request))

    args["form"] = form
    args["item"] = Items.objects.get(id=item_id)
    args["notifications"] = Notifications.objects.filter(requestedTo=request.user, state="Pending")
    args["notifications_count"] = args["notifications"].count()
    args["transactions"] = Notifications.objects.filter(requestedFrom=request.user).order_by("item", "-bid")
    args["transactions_count"] = args["transactions"].count()
    args["online_user"] = request.user

    return render_to_response("showItem.html", args)
Exemplo n.º 2
0
def admin_notification():
    '''后台通知页面(添加通知及展示历史通知)'''
    form = NotificationForm()
    if request.method == 'GET':
        notification_list = Notification.query.order_by('notification.mid DESC').all()
        return render_template('admin_notification.html', form = form, notification_list = notification_list)
    else:
        if not form.validate_on_submit():
            flash(INPUT_ERROR)
        else:
            notification = Notification(content = form.content.data, add_time = get_now_time())
            db.session.add(notification)
            db.session.commit()
            flash(ADD_NOTIFICATION_SUCCESS)

        return redirect(request.referrer)
Exemplo n.º 3
0
def admin_notification():
    '''后台通知页面(添加通知及展示历史通知)'''
    form = NotificationForm()
    if request.method == 'GET':
        notification_list = Notification.query.order_by(
            'notification.mid DESC').all()
        return render_template('admin_notification.html',
                               form=form,
                               notification_list=notification_list)
    else:
        if not form.validate_on_submit():
            flash(INPUT_ERROR)
        else:
            notification = Notification(content=form.content.data,
                                        add_time=get_now_time())
            db.session.add(notification)
            db.session.commit()
            flash(ADD_NOTIFICATION_SUCCESS)

        return redirect(request.referrer)