[M1] W-word long text, equipment borrowing registration system based on Python+Flask+SQLAlchemy+LayUI (recommended Collection)

1, Effect display

1. Equipment information query

2. Enterprise employee information query  

  3. New equipment registration

  4. Warehousing of new equipment

5. Equipment borrowed by employees

6. Return of equipment by employees  

 

2, System function

Function:

Equipment management: Warehousing Management (new equipment warehousing - > new equipment registration), borrowing equipment and returning equipment

Information settings: administrator information settings

Equipment information query: equipment name, manufacturer, category and equipment number

Employee information query: employee card number, validity period, arrears or not, return date

Administrator information: personal information and authority, modify password

Login and logout

Role:

This management system is divided into two types of user roles: enterprise employee and administrator.

Enterprise employees: you can view equipment information and borrowing records, and switch functions in the navigation bar at the top of the login page without entering user name and password.

Administrator: you can use all functions. You need to log in with an account and password to carry out daily business operations

Demo:

Equipment information, equipment name, can be filled in   "Spectrum analyzer"  , "3D scanner";

Category, can be filled in   "Analysis equipment"   Etc;

Employee job card: 16000001;

3, Overall framework

Category

content

brief introduction

development language

Python 3

Why Python?

Python won the title of programming language in 2020. At the same time, Python is also the first programming language to win the award four times since the release of the TIOBE list. Python achieved a positive growth rate of 2.01% in 2020, followed by C + + with a growth rate of 1.99%. Among other programming languages, C (+ 1.66%), Groovy (+ 1.23%) and R (+ 1.10%) ranked second.

Back end frame

Flask

Flask is a micro "microframework" Web framework developed by Python, based on WSGI toolbox and Jinja2   Template engine, flash uses BSD authorization. With its freedom, flexibility and strong scalability, it is widely used in various server-side architectures.

Front end frame

LayUI

Open source modular front-end UI framework. Created by professional front-end, it is easy to start, open-source and free Web UI component library for front-end and back-end developers at all levels

database

SQLite

SQLite is a very lightweight relational database system that supports most SQL92 standards. SQLite does not need to install settings or processes to start, stop or configure before use. Most other SQL database engines are used as a separate server process by the program to use some kind of internal process communication (typically TCP / IP) to send requests to the server and receive query results. SQLite does not use this working method. When using SQLite, the program accessing the database reads and writes directly from the database file on the disk, and there is no intermediate server process. Using SQLite generally only needs to bring a dll to use all its functions.

The main application scenarios of SQLite include the database as a mobile application and the database of small desktop software.

4, Key code

Front end code

{% extends "base.html" %}
{% block title %}Borrow equipment{% endblock %}

{% block card %}<div class="layui-card-header"><h2>Borrow equipment</h2></div>{% endblock %}
{% block body %}
    <form class="layui-form" method="post" id="searchForm">
    <!--{{ form.csrf_token }}-->
        <div class="layui-form-item">
            <div class="layui-inline">
                <label style="font-size: medium;width: 150px;" class="layui-form-label">Employee card No.:</label>
                <div class="layui-input-inline">
                    {{ form.card(class="layui-input", id="card") }}
                </div>
                <label style="font-size: medium;width: 80px;" class="layui-form-label">Equipment name:</label>
                <div class="layui-input-inline">
                    {{ form.equipment_name(class="layui-input", id="equipment_name") }}
                </div>
                <div class="layui-input-inline">{{ form.submit(class="layui-btn", id="search") }}</div>
            </div>
        </div>
    </form>
    <div id="remove">
    <table lay-even id="result" lay-filter="re">
      <thead>
        <tr>
          <th lay-data="{field:'barcode', width:160}">Device barcode</th>
          <th lay-data="{field:'equipmentNo', width:180}">Equipment number</th>
          <th lay-data="{field:'equipment_name', width:240}">Device name</th>
          <th lay-data="{field:'manufacturer', width:160}">manufacturer</th>
          <th lay-data="{field:'start_date', width:200}">industry</th>
          <th lay-data="{field:'end_date'}">operation</th>
        </tr>
      </thead>
      <tbody>

      </tbody>
    </table>
    </div>
    <table id="test" lay-filter="test"></table>

{% endblock %}

{% block script %}
    <script>
    layui.use(['form','table','jquery'], function(){
        var form = layui.form;
        var table = layui.table;
        var $ = layui.$;

        table.init('re', {
              height: 390
              ,limit: 7
              ,page: true
        });
        table.on('tool(test)', function(obj){ //Note: tool is the toolbar event name, and test is the attribute lay filter = "corresponding value" of the original table container
          var data = obj.data; //Get current row data
          var layEvent = obj.event; //Obtain the value corresponding to the lay event (or the value corresponding to the event parameter in the header)
          //var tr = obj.tr; // Gets the DOM object of the current row tr
            console.log(obj);
          if(layEvent === 'borr'){
            layer.confirm('Are you sure to lend it?', function(index){
              //obj.del(); // Delete the DOM structure of the corresponding row (tr) and update the cache
              //Send a delete instruction to the server
                table.reload('test', {
                  url: '{{ url_for('out') }}',
                  where: {
                      'barcode': data.barcode,
                      'card': $('#card').val(),
                      'equipment_name': $('#equipment_name').val()
                  }
                });
                layer.close(index);
            });
          }
        });

        $(document).ready(function(){
            $('#search').on('click',function () {
                var form = new FormData(document.getElementById("searchForm"));
                if($('#card').val() === "" || $('#equipment_name').val() === ""){
                    layui.use('layer', function(){
                        var layer = layui.layer;

                        layer.msg('Please fill in the query content',{time: 800});
                    });
                }
                else{
                    $.ajax({
                        url:"{{ url_for('find_staff_equipment') }}",
                        type:"post",
                        data:form,
                        processData:false,
                        contentType:false,
                        success:function(data){
                            if(data.length !== 0){
                                if(data[0].staff === 0){
                                    layui.use('layer', function(){
                                    var layer = layui.layer;

                                    layer.msg('Please enter the correct employee card number!',{time: 1000});
                                    });
                                }
                                else if(data[0].staff === 1){
                                    layui.use('layer', function(){
                                    var layer = layui.layer;

                                    layer.msg('The employee card is in arrears!',{time: 1000});
                                    });
                                }
                                else if(data[0].staff === 2){
                                    layui.use('layer', function(){
                                    var layer = layui.layer;

                                    layer.msg('The employee card borrowing has expired!',{time: 1000});
                                    });
                                }
                                else if(data[0].staff === 3){
                                    layui.use('layer', function(){
                                    var layer = layui.layer;

                                    layer.msg('The employee card has been reported lost!',{time: 1000});
                                    });
                                }
                                else{
                                    $('#remove').remove();
                                    table.render({
                                        elem: '#test'
                                        ,data:data
                                        ,cols: [[
                                            {field:'barcode', title:'Device barcode', width:160}
                                            ,{field:'equipmentNo', title:'Equipment number', width:180}
                                            ,{field:'equipment_name', title:'Device name', width:240}
                                            ,{field:'manufacturer', title:'manufacturer', width:140}
                                            ,{field:'industry', title:'industry', width:200}
                                            ,{title:'operation', fixed: 'right', align:'center', toolbar: '#barDemo'}
                                        ]]
                                        ,page: true
                                        ,height: 380
                                        ,limit: 7
                                        ,response: {
                                            statusCode: 200
                                        }
                                        ,parseData: function(data){
                                            return {
                                                "code": 200,
                                                "msg": data.message,
                                                "count": data.length,
                                                "data": data
                                            };
                                        }
                                    });
                                }
                            }
                            else {
                                layui.use('layer', function(){
                                var layer = layui.layer;

                                layer.msg('The device cannot be found!',{time: 1000});
                                });
                            }
                        }
                    });

                }
                return false;
            });
        });
    });
    </script>
    <script type="text/html" id="barDemo">
      <a class="layui-btn layui-btn-sm" lay-event="borr">lend</a>
    </script>
{% endblock %}

Back end code

@app.route('/change_password', methods=['GET', 'POST'])
@login_required
def change_password():
    form = ChangePasswordForm()
    if form.password2.data != form.password.data:
        flash(u'The two passwords are inconsistent!')
    if form.validate_on_submit():
        if current_user.verify_password(form.old_password.data):
            current_user.password = form.password.data
            db.session.add(current_user)
            db.session.commit()
            flash(u'The password has been modified successfully!')
            return redirect(url_for('index'))
        else:
            flash(u'Original password input error, modification failed!')
    return render_template("change-password.html", form=form)


@app.route('/change_info', methods=['GET', 'POST'])
@login_required
def change_info():
    form = EditInfoForm()
    if form.validate_on_submit():
        current_user.admin_name = form.name.data
        db.session.add(current_user)
        flash(u'Personal information has been modified successfully!')
        return redirect(url_for('user_info', id=current_user.admin_id))
    form.name.data = current_user.admin_name
    id = current_user.admin_id
    right = current_user.right
    return render_template('change-info.html', form=form, id=id, right=right)


@app.route('/search_equipment', methods=['GET', 'POST'])
@login_required
def search_equipment():  # The submit button is no longer handled in this function, and Ajax local refresh is used
    form = SearchEquipmentForm()
    return render_template('search-equipment.html', name=session.get('name'), form=form)


@app.route('/equipments', methods=['POST'])
def find_equipment():

    def find_name():
        return Equipment.query.filter(Equipment.equipment_name.like('%'+request.form.get('content')+'%')).all()

    def find_manufacturer():
        return Equipment.query.filter(Equipment.manufacturer.contains(request.form.get('content'))).all()

    def find_class():
        return Equipment.query.filter(Equipment.class_name.contains(request.form.get('content'))).all()

    def find_equipmentNo():
        return Equipment.query.filter(Equipment.equipmentNo.contains(request.form.get('content'))).all()

    methods = {
        'equipment_name': find_name,
        'manufacturer': find_manufacturer,
        'class_name': find_class,
        'equipmentNo': find_equipmentNo
    }
    equipments = methods[request.form.get('method')]()
    data = []
    for equipment in equipments:
        count = Inventory.query.filter_by(equipmentNo=equipment.equipmentNo).count()
        available = Inventory.query.filter_by(equipmentNo=equipment.equipmentNo, status=True).count()
        item = {'equipmentNo': equipment.equipmentNo, 'equipment_name': equipment.equipment_name, 'industry': equipment.industry, 'manufacturer': equipment.manufacturer,
                'class_name': equipment.class_name, 'count': count, 'available': available}
        data.append(item)
    return jsonify(data)


@app.route('/user/equipment', methods=['GET', 'POST'])
def user_equipment():
    form = SearchEquipmentForm()
    return render_template('user-equipment.html', form=form)


@app.route('/search_staff', methods=['GET', 'POST'])
@login_required
def search_staff():
    form = SearchStaffForm()
    return render_template('search-staff.html', name=session.get('name'), form=form)


def timeStamp(timeNum):
    if timeNum is None:
        return timeNum
    else:
        timeStamp = float(float(timeNum)/1000)
        timeArray = time.localtime(timeStamp)
        print(time.strftime("%Y-%m-%d", timeArray))
        return time.strftime("%Y-%m-%d", timeArray)


@app.route('/staff', methods=['POST'])
def find_staff():
    staff = Staff.query.filter_by(card_id=request.form.get('card')).first()
    if staff is None:
        return jsonify([])
    else:
        valid_date = timeStamp(staff.valid_date)
        return jsonify([{'name': staff.staff_name, 'gender': staff.sex, 'valid_date': valid_date, 'debt': staff.debt}])

Database code

from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField, SelectField, PasswordField
from wtforms.validators import DataRequired, EqualTo, Length


class Login(FlaskForm):
    account = StringField(u'account number', validators=[DataRequired()])
    password = PasswordField(u'password', validators=[DataRequired()])
    submit = SubmitField(u'Sign in')


class ChangePasswordForm(FlaskForm):
    old_password = PasswordField(u'Original password', validators=[DataRequired()])
    password = PasswordField(u'New password', validators=[DataRequired(), EqualTo('password2', message=u'The two passwords must be the same!')])
    password2 = PasswordField(u'Confirm new password', validators=[DataRequired()])
    submit = SubmitField(u'Confirm modification')


class EditInfoForm(FlaskForm):
    name = StringField(u'user name', validators=[Length(1, 32)])
    submit = SubmitField(u'Submit')


class SearchEquipmentForm(FlaskForm):
    methods = [('equipment_name', 'Device name'), ('manufacturer', 'manufacturer'), ('class_name', 'category'), ('equipmentNo', 'Equipment number')]
    method = SelectField(choices=methods, validators=[DataRequired()], coerce=str)
    content = StringField(validators=[DataRequired()])
    submit = SubmitField('search')

5, Start command

Install dependent libraries: pip   install  - r   requirements.txt

Startup command: python   main.py   runserver  - p   eight thousand and eighty

Enter the system: enter in the browser    http://127.0.0.1:8080/   

administrators    Account No.: 00000 1    Password: 123456

6, Source download

Note: new functions can be developed and improved on this basis.

Tags: Python Flask Layui

Posted on Fri, 08 Oct 2021 22:40:58 -0400 by AutomatikStudio