Exemple #1
0
def create():
    params = request.json
    staff = User.get_or_none(User.identity_card == get_jwt_identity())
    new_material = Material(classroom=params.get("classroom_id"),
                            staff=staff.id,
                            topic=params.get("topic"),
                            name=params.get("name"),
                            link_url=params.get("link_url"))
    if staff.roles == "staff":
        if new_material.save():
            response = {
                "Message": "Successfully saved",
                "Status": "Success",
                "material.id": new_material.id,
                "classroom": new_material.classroom_id,
                "subject": new_material.classroom.subject.name,
                "topic": new_material.topic,
                "name": new_material.name,
                "link_url": new_material.link_url
            }
        else:
            response = {
                "Message": "Action unsuccessful",
                "Status": "Failed",
            }
        return jsonify(response)
    else:
        response = {"Message": "You are not allow to perform this action!"}
    return jsonify(response)
Exemple #2
0
 def info_popup(self):
     """popup to display more information about selection"""
     if self.polarity == None:
         record = Material.get_material(self.name)
         self.dialog = MDDialog(
             title=record['material_name'],
             type='custom',
             content_cls=MaterialInfo(),
             buttons=[
                 MDRectangleFlatButton(
                     text="Okay",
                     on_release=lambda x: self.dialog.dismiss())
             ])
     else:
         record = Solvent.get_solvent(self.name)
         self.dialog = MDDialog(
             title=record['solvent_name'],
             type='custom',
             content_cls=SolventInfo(),
             buttons=[
                 MDRectangleFlatButton(
                     text="Okay",
                     on_release=lambda x: self.dialog.dismiss())
             ])
     for key in record:
         setattr(self.dialog.content_cls, key, record[key])
     self.dialog.open()
Exemple #3
0
 def edit(self):
     """Takes solvent/material & opens information to be editted"""
     if self.polarity == None:
         record = Material.get_material(self.name)
     else:
         record = Solvent.get_solvent(self.name)
     app = MDApp.get_running_app()
     app.root.ids.screens.get_screen('update').edit(record)
Exemple #4
0
def test_material(session):
    material = add_material(name='test')
    material.props = {'a': 'aaa'}
    material.save()

    material2 = Material.get(material.id)
    assert material2.name == 'test'
    assert material2.props.get('a') == 'aaa'
Exemple #5
0
def create():
    params = request.json
    staff = User.get_or_none(User.identity_card == get_jwt_identity())
    #creating a new exam in material database
    new_material = Material(classroom=params.get("classroom_id"),
                            staff=staff.id,
                            topic=params.get("topic"),
                            name=params.get("name"),
                            link_url=params.get("link_url"))
    if staff.roles == "staff":
        if new_material.save():
            new_exam = Exam(material=new_material, staff=staff.id)
            if new_exam.save():
                response = {
                    "Message": "Successfully saved",
                    "Status": "Success",
                    "material.id": new_material.id,
                    "classroom": new_material.classroom_id,
                    "subject": new_material.classroom.subject.name,
                    "exam.id": new_exam.id,
                    "staff": new_material.staff.id,
                    "staff": new_material.staff.full_name,
                    "topic": new_material.topic,
                    "name": new_material.name,
                    "link_url": new_material.link_url
                }
            else:
                response = {
                    "Message": "Unable to save into Exam",
                    "Status": "Failed",
                }
        else:
            response = {
                "Message": "Unable to save into Material",
                "Status": "Failed",
            }
    else:
        response = {"Message": "You are not allow to perform this action!"}
    return jsonify(response)
Exemple #6
0
def new_material(item_id):
    item = AdItem.get(item_id)
    if not item:
        abort(404)
    form = RawMaterialForm(request.form)
    if request.method == 'POST' and form.validate():
        material = Material.add(name=form.name.data, item=item, creator=g.user)
        material.code = form.code.data
        material.status = form.status.data
        material.save()
        flash(u'新建素材(%s)成功!' % material.name, 'success')
        return redirect(url_for('order.item_materials', item_id=item.id))
    return tpl('material_raw.html', form=form)
Exemple #7
0
def destroy():
    params = request.json
    staff = User.get_or_none(User.identity_card == get_jwt_identity())
    material_id = params.get("id")
    if staff.roles == "staff":
        material = Material.get_or_none(Material.id == material_id)
        if material.delete_instance():
            response = {"Message": "Post deleted", "Status": "Success"}
        else:
            response = {"Message": "Action unsuccessful", "Status": "Failed"}
    else:
        response = {"Message": "You are not allow to perform this action!"}
    return jsonify(response)
Exemple #8
0
def new_material(item_id):
    item = AdItem.get(item_id)
    if not item:
        abort(404)
    form = RawMaterialForm(request.form)
    if request.method == 'POST' and form.validate():
        material = Material.add(name=form.name.data, item=item, creator=g.user)
        material.code = form.code.data
        material.status = form.status.data
        material.save()
        flash(u'新建素材(%s)成功!' % material.name, 'success')
        return redirect(url_for('order.item_materials', item_id=item.id))
    return tpl('material_raw.html', form=form)
Exemple #9
0
 def put(self):
     json = request.get_json(force=True)
     id = json.get('Id')
     name = json['Name']
     desc = json['Description']
     if id:
         m = Material.query.get(id)
         m.name = name
         m.description = desc
     else:
         m = Material(name=name, description=desc, capacity=0.)
     db.session.add(m)
     db.session.commit()
     return jsonify(statusCode=200, data=True)
Exemple #10
0
def copy_material(item_id):
    item_ids = request.form.getlist('item_id')
    material_ids = request.form.getlist('material_id')
    if not material_ids:
        flash(u"请选择素材")
    elif not item_ids:
        flash(u"请选择订单项")
    else:
        items = [AdItem.get(i_id) for i_id in item_ids]
        for m_id in material_ids:
            material = Material.get(m_id)
            for i in items:
                new_material = Material.add(name="%s_copy" % material.name,
                                            item=i,
                                            creator=g.user,
                                            type=material.type)
                new_material.code = material.code
                new_material.status = material.status
                new_material.props = material.props
                new_material.save()
        flash(u'拷贝%s素材到个%s订单项成功!' % (len(material_ids), len(item_ids)),
              'success')
    return redirect(url_for('order.item_detail', item_id=item_id))
Exemple #11
0
def copy_material(item_id):
    item_ids = request.form.getlist('item_id')
    material_ids = request.form.getlist('material_id')
    if not material_ids:
        flash(u"请选择素材")
    elif not item_ids:
        flash(u"请选择订单项")
    else:
        items = [AdItem.get(i_id) for i_id in item_ids]
        for m_id in material_ids:
            material = Material.get(m_id)
            for i in items:
                new_material = Material.add(
                    name="%s_copy" % material.name,
                    item=i,
                    creator=g.user,
                    type=material.type)
                new_material.code = material.code
                new_material.status = material.status
                new_material.props = material.props
                new_material.save()
        flash(u'拷贝%s素材到个%s订单项成功!' % (len(material_ids), len(item_ids)), 'success')
    return redirect(url_for('order.item_detail', item_id=item_id))
Exemple #12
0
def show(id):
    user = User.get_or_none(User.identity_card == get_jwt_identity())
    material = Material.get_or_none(Material.id == id)
    if user:
        if material.id == int(id):
            response = []
            response.append({
                "material.id": material.id,
                "classroom": material.classroom_id,
                "subject": material.classroom.subject.name,
                "staff": material.staff.full_name,
                "topic": material.topic,
                "name": material.name,
                "link_url": material.link_url
            })
    return jsonify(response)
Exemple #13
0
def raw_material(material_id):
    material = Material.get(material_id)
    if not material:
        abort(404)
    form = RawMaterialForm(request.form)
    if request.method == 'POST':
        if form.validate():
            material.name = form.name.data
            material.code = form.code.data
            material.status = form.status.data
            material.save()
            flash(u'素材(%s)保存成功!' % material.name, 'success')
    else:
        form.name.data = material.name
        form.code.data = material.code
        form.status.data = material.status
    return tpl('material_raw.html', form=form, material=material)
Exemple #14
0
def raw_material(material_id):
    material = Material.get(material_id)
    if not material:
        abort(404)
    form = RawMaterialForm(request.form)
    if request.method == 'POST':
        if form.validate():
            material.name = form.name.data
            material.code = form.code.data
            material.status = form.status.data
            material.save()
            flash(u'素材(%s)保存成功!' % material.name, 'success')
    else:
        form.name.data = material.name
        form.code.data = material.code
        form.status.data = material.status
    return tpl('material_raw.html', form=form, material=material)
Exemple #15
0
def create_material():
    form = MaterialForm(request.form)
    if request.method == 'POST' and 'role' in session and form.validate():
        curUser = Member.query.filter(Member.name == session['name']).first()
        material = Material(name=form.name.data,
                            quantity=form.quantity.data,
                            create_user_id=curUser.Id,
                            create_user_name=curUser.name,
                            role=curUser.role)
        db_session.add(material)
        db_session.commit()

        if session['role'] == 'user':
            return redirect(url_for('user_material_list'))
        else:
            return redirect(url_for('mechanism_material_list'))

    return render_template('create_material.html', form=form)
Exemple #16
0
def update(id):
    staff = User.get_or_none(User.identity_card == get_jwt_identity())
    if staff.roles == "staff":
        params = request.json
        exam = Exam.get_or_none(Exam.id == id)
        material = Material.get_or_none(Material.id == exam.material_id)

        material.classroom = params.get("classroom_id")
        material.topic = params.get("topic")
        material.name = params.get("name")
        material.link_url = params.get("link_url")
        if material.save():
            exam.staff = params.get("staff_id")
            if exam.save():
                response = {
                    "Message": "Successfully saved",
                    "Status": "Success",
                    "material.id": material.id,
                    "classroom": material.classroom_id,
                    "subject": material.classroom.subject.name,
                    "exam.id": exam.id,
                    "staff": material.staff.id,
                    "staff": material.staff.full_name,
                    "topic": material.topic,
                    "name": material.name,
                    "link_url": material.link_url
                }
            else:
                response = {
                    "Message": "Unable to update exam's data",
                    "Status": "Failed",
                }
        else:
            response = {
                "Message": "Unable to update material's data",
                "Status": "Failed",
            }
    else:
        response = {"Message": "You are not allow to perform this action!"}
    return jsonify(response)
Exemple #17
0
def add_material(item=None, material_type=MATERIAL_TYPE_RAW, name=None):
    item = item or add_item()
    user = get_default_user()
    name = name or 'test_material'
    material = Material.add(name=name, item=item, creator=user, type=material_type)
    return material
Exemple #18
0
def raw_preview(material_id):
    material = Material.get(material_id)
    return material_preview_response(material)
Exemple #19
0
def raw_preview(material_id):
    material = Material.get(material_id)
    return material_preview_response(material)
Exemple #20
0
def get_export_materials(_date):
    """当天的广告素材索引信息, 素材id, 素材html"""
    ret = {}
    for m in Material.online_materials(_date):
        ret[str(m.id)] = material_info(m)
    return ret
 def get_mol_weight(self, material_name):
     material = Material.get_material(material_name)
     mol_weight = material["molecular_weight"]
     self.MOLECULAR_WEIGHT = f'{mol_weight}'
 def get_materials(self):
     self.MATERIAL_LIST = Material.get_all()