Exemple #1
0
def home():
    activity_orders = ActivityOrder.query.filter_by(unified_id=current_user.get_unified_id()).\
        order_by(ActivityOrder.created.desc()).all()
    class_orders = ClassOrder.query.filter_by(unified_id=current_user.get_unified_id())
    # TODO: add class order, activity order. delete order.

    return render_template('userorderlist_py.html',
                           activity_orders=activity_orders,
                           class_orders=class_orders)
Exemple #2
0
def success(id):
    order = ClassOrder.query.get_or_404(id)
    if order.unified_id != current_user.get_unified_id():
        abort(404)
    course = Class.query.get_or_404(order.class_id)
    org = course.get_org()
    return render_template('classattend4_py.html',
                           org=org,
                           order=order,
                           course=course)
Exemple #3
0
def success(id):
    order = ActivityOrder.query.get_or_404(id)
    if order.unified_id != current_user.get_unified_id():
        abort(404)
    activity = Activity.query.get_or_404(order.activity_id)
    org = activity.get_org()
    return render_template('activityattend3_py.html',
                           org=org,
                           order=order,
                           activity=activity)
Exemple #4
0
def detail(id):
    form = DetailForm()
    order = ClassOrder.query.get_or_404(id)
    if order.unified_id != current_user.get_unified_id():
        abort(404)
    if order.is_submitted:
        abort(404)
    if form.validate_on_submit():
        form.set_ord(order)
        db.session.add(order)
        db.session.commit()
        return redirect(url_for('.confirm', id=id))
    return render_template('classattend2_py.html', form=form)
Exemple #5
0
 def create_ord(self, id):
     class_order = ClassOrder(unified_id=current_user.get_unified_id(),
                              class_id=id,
                              created=time.time(),
                              time=time.mktime(self.time.data.timetuple()),
                              name=u'',
                              age=u'',
                              sex=True,
                              mobile='',
                              email='',
                              address=u'',
                              remark=u'')
     return class_order
Exemple #6
0
 def create_ord(self, id):
     activity_order = ActivityOrder(
         unified_id=current_user.get_unified_id(),
         activity_id=id,
         created=time.time(),
         name=self.name.data,
         age=self.age.data,
         sex=bool(self.sex.data),
         email='',
         mobile=self.cellphone.data,
         address=self.address.data,
         remark=u'')
     return activity_order
Exemple #7
0
def confirm(id):
    form = ConfirmForm()
    order = ClassOrder.query.get_or_404(id)
    course = Class.query.get_or_404(order.class_id)
    if order.unified_id != current_user.get_unified_id():
        abort(404)
    if order.is_submitted:
        abort(404)
    if form.validate_on_submit():
        order.remark = form.remark.data
        order.is_confirmed = True
        org = course.get_org()
        org.orders += 1
        db.session.add(order)
        db.session.add(org)
        db.session.commit()
        return redirect(url_for('course.success', id=order.id))
    return render_template('classattend3_py.html',
                           form=form,
                           order=order,
                           course=course)
Exemple #8
0
def confirm(id):
    order = ActivityOrder.query.get_or_404(id)
    form = ConfirmForm()
    activity = Activity.query.get_or_404(order.activity_id)
    if order.unified_id != current_user.get_unified_id():
        abort(404)
    if order.is_submitted:
        abort(404)
    if form.validate_on_submit():
        order.remark = form.remark.data
        order.is_confirmed = True
        org = activity.get_org()
        org.orders += 1
        db.session.add(order)
        db.session.add(org)
        db.session.commit()
        return redirect(url_for('activity.success', id=order.id))
    return render_template('activityattend2_py.html',
                           activity=activity,
                           order=order,
                           form=form)
Exemple #9
0
def chat():
    channel_id = current_user.get_unified_id()
    if not UnifiedId.query.get_or_404(channel_id).user_id:
        return 'false', 404
    organization_id = request.values.get('orgid', 0, type=int)
    if request.method == 'GET':
        last_id = request.values.get('id', 1, type=int)
        if last_id:
            chatline = ChatLine.query.\
                filter(ChatLine.unified_id == channel_id).\
                filter(ChatLine.is_user == False).\
                filter(organization_id == organization_id).\
                filter(ChatLine.id > last_id).first()
            if chatline:
                return jsonify({'id': chatline.id,
                                'content': chatline.content})
            return 'false', 500
        else:
            return 'false', 500

    else:
        content = request.values.get('context', None, type=unicode)
        if content and organization_id:
            chat_line = ChatLine(unified_id=channel_id,
                                 is_user=True,
                                 content=content,
                                 created=time.time(),
                                 organization_id=organization_id,
                                 source=1)

            db.session.add(chat_line)
            try:
                db.session.commit()
                return jsonify({'id': chat_line.id})
            except:
                db.session.rollback()
                raise
        return 'false', 500