clear
This commit is contained in:
@ -1,2 +1,9 @@
|
||||
# inventory_check
|
||||
|
||||
|
||||
click 8.1.8
|
||||
Flask 3.1.0
|
||||
Flask-Moment 1.0.6
|
||||
Flask-SQLAlchemy 3.1.1
|
||||
gunicorn 23.0.0
|
||||
openpyxl 3.1.5
|
||||
|
@ -1,170 +0,0 @@
|
||||
|
||||
|
||||
from flask import *
|
||||
#from client import Client
|
||||
import time
|
||||
import json
|
||||
import os
|
||||
import csv
|
||||
import sqlite3
|
||||
import hashlib
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
DB = 'inventory.db'
|
||||
|
||||
def getmd5(data):
|
||||
s = ''
|
||||
for i in data:
|
||||
s += str(i).strip()
|
||||
r = hashlib.md5(s.encode(encoding='UTF-8')).hexdigest()
|
||||
return r
|
||||
|
||||
def formatted_time():
|
||||
return time.strftime("%Y/%m/%d", time.localtime())
|
||||
|
||||
def dbsetup(data):
|
||||
"""
|
||||
'{
|
||||
"25":{"location": 28, "tag": "7.61/8.10", "amount": 3 },
|
||||
"26":{"location": 29, "tag": "7.59/8.10", "amount": 3 }
|
||||
}'
|
||||
"""
|
||||
conn = sqlite3.connect(DB)
|
||||
c = conn.cursor()
|
||||
c.execute("DROP TABLE IF EXISTS inventory")
|
||||
conn.commit()
|
||||
c.execute('''CREATE TABLE IF NOT EXISTS inventory
|
||||
(ID INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
SORT INT,
|
||||
LOCATION INT,
|
||||
TAG TEXT,
|
||||
AMOUNT INT,
|
||||
NAME TEXT,
|
||||
DATE TEXT);''')
|
||||
conn.commit()
|
||||
for e in data.keys():
|
||||
v = (int(e), data[e]["location"], data[e]["tag"], data[e]["amount"])
|
||||
c.execute('''INSERT INTO inventory
|
||||
(SORT,LOCATION,TAG,AMOUNT) \
|
||||
VALUES {v}'''.format(v=v))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def dbinsert(tb='inventory', v=()):
|
||||
conn = sqlite3.connect(DB)
|
||||
c = conn.cursor()
|
||||
#c.execute('''INSERT INTO {tb}
|
||||
# (ID,NU,MOULD,SPEC,AMOUNT,OUTDATE,RECEIVRE,MANAGER,\
|
||||
# FAC,SERIAL,STATE,INDATE,COLLECTOR,COMMET,MD5) \
|
||||
# VALUES {v}'''.format(tb=tb, v=v))
|
||||
c.execute("INSERT INTO {tb} VALUES {v};".format(tb=tb, v=v))
|
||||
#(2, 'Allen', 25, 'Texas', 15000.00 )
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def dbselect(tb='inventory'):
|
||||
conn = sqlite3.connect(DB)
|
||||
c = conn.cursor()
|
||||
# c.execute("SELECT ID,NU,MOULD,SPEC,AMOUNT,OUTDATE,RECEIVRE,\
|
||||
# MANAGER,FAC,SERIAL,STATE,INDATE,COLLECTOR,COMMET,MD5 from {tb};".format(tb=tb))
|
||||
c.execute("SELECT * FROM {tb};".format(tb=tb))
|
||||
return c.fetchall()
|
||||
|
||||
def dbupdate(tb='inventory', d={'ID':123123,'MD5':'asdasdasdasd'}):
|
||||
conn = sqlite3.connect(DB)
|
||||
c = conn.cursor()
|
||||
for e in d:
|
||||
if isinstance(d[e], str):
|
||||
c.execute("UPDATE {tb} SET {h} = '{r}' WHERE ID={id};".format(tb=tb, h=e, r=d[e], id=d['ID']))
|
||||
else:
|
||||
c.execute("UPDATE {tb} SET {h} = {r} WHERE ID={id};".format(tb=tb, h=e, r=d[e], id=d['ID']))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def dbdelete(tb='inventory', i=123123):
|
||||
conn = sqlite3.connect(DB)
|
||||
c = conn.cursor()
|
||||
try:
|
||||
c.execute("DELETE FROM {tb} WHERE ID={i};".format(tb=tb, i=i))
|
||||
LOG('已删除该条目……')
|
||||
except:
|
||||
LOG('没有该条目……')
|
||||
conn.commit()
|
||||
conn.close()
|
||||
LOG('已删除……')
|
||||
|
||||
def dbsearchhead(tb='inventory', h='NU', s='3'):
|
||||
conn = sqlite3.connect(DB)
|
||||
c = conn.cursor()
|
||||
#c.execute("SELECT ID,NU,MOULD,SPEC,AMOUNT,OUTDATE,RECEIVRE,MANAGER,\
|
||||
#FAC,SERIAL,STATE,INDATE,COLLECTOR,COMMET,MD5 from {tb};".format(tb=tb))
|
||||
c.execute("SELECT * FROM {tb} WHERE {h} GLOB '*{s}*';".format(tb=tb, h=h, s=s))
|
||||
return c.fetchall()
|
||||
|
||||
def dbsearchtime(tb='inventory', t=(111111,222222)):
|
||||
conn = sqlite3.connect(DB)
|
||||
c = conn.cursor()
|
||||
c.execute("SELECT * FROM {tb} WHERE ID >= {a} AND ID >= {b} ;".format(tb=tb, a=t[0], b=t[1]))
|
||||
return c.fetchall()
|
||||
|
||||
def dbadd(tb='inventory', d={'ID':123123,'MD5':'asdasdasdasd'}):
|
||||
conn = sqlite3.connect(DB)
|
||||
c = conn.cursor()
|
||||
v = (d['ID'],' ',' ',' ',1,'','','','','','','','','','',0,'')
|
||||
try:
|
||||
c.execute("INSERT INTO {tb} VALUES {v};".format(tb=tb, v=v))
|
||||
except:
|
||||
pass
|
||||
conn.commit()
|
||||
conn.close()
|
||||
#(2, 'Allen', 25, 'Texas', 15000.00 )
|
||||
dbupdate(tb=tb, d=d)
|
||||
|
||||
def dbnothave(tb='inventory', md5='md5'):
|
||||
conn = sqlite3.connect(DB)
|
||||
c = conn.cursor()
|
||||
c.execute("SELECT * FROM {tb} WHERE MD5 = '{md5}';".format(tb=tb, md5=md5))
|
||||
if c.fetchall() == []:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@app.route('/inventory', methods=['POST','GET'])
|
||||
|
||||
# from flask import Flask, request, jsonify
|
||||
def inventory():
|
||||
if request.method == 'POST':
|
||||
# 接收JSON数据
|
||||
data = request.get_json() # '{"sort": 25, "location": 28, "tag": "7.61/8.10", "name": "Bob"}'
|
||||
print("Received data:", data)
|
||||
# 处理数据(示例:简单地返回接收到的数据)
|
||||
return jsonify({"message": "JSON data received", "yourData": data})
|
||||
else:
|
||||
# 发送JSON数据
|
||||
response_data = {
|
||||
"name": "Alice",
|
||||
"age": 25,
|
||||
"city": "Los Angeles"
|
||||
}
|
||||
return jsonify(response_data)
|
||||
|
||||
@app.route('/inventory/init', methods=['POST','GET'])
|
||||
def inventory_init():
|
||||
if request.method == 'POST':
|
||||
# 接收JSON数据
|
||||
data = request.get_json() # '{25:{"location": 28, "tag": "7.61/8.10", "amount": 3 }, 26:{"location": 29, "tag": "7.59/8.10", "amount": 3 }}'
|
||||
try:
|
||||
dbsetup(data)
|
||||
return "请求成功", 200
|
||||
except:
|
||||
return "无法理解", 400
|
||||
else:
|
||||
# 发送JSON数据
|
||||
response_data = {
|
||||
"name": "Alice",
|
||||
"age": 25,
|
||||
"city": "Los Angeles"
|
||||
}
|
||||
return jsonify(response_data)
|
@ -1,92 +0,0 @@
|
||||
|
||||
|
||||
from flask import Flask, redirect, render_template, request, url_for
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from openpyxl import load_workbook
|
||||
from wtforms import Form, IntegerField, StringField, SubmitField
|
||||
from wtforms.validators import NumberRange
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///foo.db'
|
||||
app.secret_key = 'qweqweqwe'
|
||||
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
class Inventory(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
sort = db.Column(db.Integer)
|
||||
location = db.Column(db.Integer)
|
||||
tag = db.Column(db.Text)
|
||||
amount = db.Column(db.Integer)
|
||||
name = db.Column(db.Text)
|
||||
mtime = db.Column(db.Date)
|
||||
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
|
||||
class CheckForm(Form):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.sort = IntegerField('sort')
|
||||
self.location = IntegerField('location')
|
||||
self.tag = StringField('tag')
|
||||
self.amount = IntegerField('amount', validators=[NumberRange(min=0)])
|
||||
self.name = StringField('name')
|
||||
self.mtime = StringField('mtime')
|
||||
tag = StringField('tag')
|
||||
minusbuton = SubmitField('minus')
|
||||
amount = IntegerField('amount', validators=[NumberRange(min=0)])
|
||||
plusbuton = SubmitField('plus')
|
||||
goback = SubmitField('back')
|
||||
confim = SubmitField('right')
|
||||
goahead = SubmitField('ahead')
|
||||
def import_from_xlsx(file_path):
|
||||
with app.app_context():
|
||||
db.drop_all()
|
||||
db.create_all()
|
||||
# 加载Excel工作簿
|
||||
wb = load_workbook(filename=file_path, data_only=True)
|
||||
# 加载工作簿,设置 data_only=True
|
||||
ws = wb.active
|
||||
|
||||
# 遍历工作表中的每一行
|
||||
for row in ws.iter_rows(min_row=3, values_only=True): # 假设第一行是标题行
|
||||
new_inventory = Inventory(
|
||||
sort=row[0],
|
||||
location=row[1],
|
||||
tag=row[2],
|
||||
amount=row[3],
|
||||
|
||||
)
|
||||
db.session.add(new_inventory)
|
||||
|
||||
# 提交事务
|
||||
db.session.commit()
|
||||
|
||||
def db_to_turple():
|
||||
with app.app_context():
|
||||
inventory = Inventory.query.all()
|
||||
for e in inventory:
|
||||
print(e.sort, e.location, e.tag, e.amount, e.name, e.mtime)
|
||||
|
||||
@app.route('/upload', methods=['GET', 'POST'])
|
||||
def upload_form():
|
||||
if request.method == 'POST':
|
||||
# 文件上传逻辑
|
||||
pass
|
||||
return render_template('upload.html')
|
||||
|
||||
@app.route('/import', methods=['POST'])
|
||||
def import_file():
|
||||
if request.method == 'POST':
|
||||
file = request.files['file']
|
||||
if file:
|
||||
file_path = 'data.xlsx'
|
||||
file.save(file_path)
|
||||
import_from_xlsx(file_path)
|
||||
db_to_turple()
|
||||
return '文件导入成功!'
|
||||
|
||||
return redirect(url_for('upload_form'))
|
||||
|
@ -1,33 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
:author: luffmims
|
||||
:url: http://yum2.cc
|
||||
:copyright: © 2025 luffmims <luffmims@hotmaill.com>
|
||||
:license: MIT, see LICENSE for more details.
|
||||
"""
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import IntegerField, StringField, SubmitField
|
||||
from wtforms.validators import NumberRange
|
||||
|
||||
# class HelloForm(FlaskForm):
|
||||
# name = StringField('Name', validators=[DataRequired(), Length(1, 20)])
|
||||
# body = TextAreaField('Message', validators=[DataRequired(), Length(1, 200)])
|
||||
# submit = SubmitField()
|
||||
|
||||
class CheckForm(FlaskForm):
|
||||
tag = ''
|
||||
amount = 0
|
||||
id = 0
|
||||
def __init__(self, Inventory):
|
||||
super().__init__(Inventory)
|
||||
self.id = Inventory.id
|
||||
self.tag = Inventory.tag
|
||||
self.amount = Inventory.amount
|
||||
|
||||
showtag = StringField(tag)
|
||||
minusbuton = SubmitField('-')
|
||||
amount = IntegerField('amount', validators=[NumberRange(min=0)])
|
||||
plusbuton = SubmitField('+')
|
||||
goback = SubmitField('back')
|
||||
confim = SubmitField('right')
|
||||
goahead = SubmitField('ahead')
|
@ -1,143 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>Check!</title>
|
||||
<style>
|
||||
body {
|
||||
padding: 10px;
|
||||
margin: 0;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.check-form {
|
||||
background-color: #fff;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.check-title {
|
||||
font-size: 1.2em;
|
||||
font-weight: bold;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.check-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.sub-title {
|
||||
font-size: 0.8em;
|
||||
font-weight: normal;
|
||||
}
|
||||
.alert {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.btn {
|
||||
margin: 0 5px;
|
||||
}
|
||||
#bottom {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<main class="container">
|
||||
<header>
|
||||
<h1 class="text-center display-4">
|
||||
<a href="" class="text-success"><strong>CHECK</strong></a>
|
||||
<small class="text-muted sub-title">it</small>
|
||||
</h1>
|
||||
|
||||
</header>
|
||||
<div class="alert alert-info" id="flash-msg" role="alert">
|
||||
Let's go!
|
||||
</div>
|
||||
<div class="check-form">
|
||||
<div class="check-title" id="inventory-tag">
|
||||
inventory.tag
|
||||
</div>
|
||||
<p id="inventory-id" hidden>inventory.id</p>
|
||||
<div style="justify-content: space-between;">
|
||||
<button onclick="decrement()" type="button" class="btn btn-info">-</button>
|
||||
<input type="number" id="inventory-amount" value="nventory.amount" min="0" style="width: 7ch;">
|
||||
<button onclick="increment()" type="button" class="btn btn-info">+</button>
|
||||
</div>
|
||||
<div class="check-footer">
|
||||
<button type="button" class="btn btn-light">back</button>
|
||||
<button type="button" class="btn btn-success">ok</button>
|
||||
<button onclick="checknext()" type="button" class="btn btn-success">next</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer class="text-center">
|
||||
|
||||
<small> © 2025 <a href="http://yum2.cc" title="Written by luffmims">luffmims</a> /
|
||||
|
||||
</small>
|
||||
<p><a id="bottom" href="#" title="Go Top">↑</a></p>
|
||||
|
||||
</footer>
|
||||
</main>
|
||||
<script>
|
||||
function increment() {
|
||||
var amount = document.getElementById("inventory-amount");
|
||||
amount.value = parseInt(amount.value) + 1;
|
||||
}
|
||||
function decrement() {
|
||||
var amount = document.getElementById("inventory-amount");
|
||||
if (amount.value > 0) {
|
||||
amount.value = parseInt(amount.value) - 1;
|
||||
}
|
||||
}
|
||||
function checknext() {
|
||||
var amount = document.getElementById("inventory-amount");
|
||||
// 获取ID为"forid"的元素
|
||||
var idelement = document.getElementById("inventory-id");
|
||||
// 获取该元素的文本内容,并解析为整数
|
||||
var id = parseInt(idelement.innerText, 10); // 第二个参数10表示解析的基数,这里是十进制
|
||||
var tagelement = document.getElementById("inventory-tag");
|
||||
var tag = tagelement.innerText;
|
||||
var name = "A"
|
||||
var msg = document.getElementById("flash-msg");
|
||||
// var params = new URLSearchParams({
|
||||
// checked: 1,
|
||||
// id: id,
|
||||
// amount: amount.value
|
||||
// });
|
||||
// var url = `/check?${params.toString()}`;
|
||||
fetch('/get_inventory', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({id: id, amount: amount.value, name: name})
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
// console.log('Success:', data);
|
||||
amount.value = data.amount;
|
||||
tagelement.innerText = data.tag;
|
||||
idelement.innerText = data.id;
|
||||
msg.innerText = data.checkedone + " checked " + data.checkedamount;
|
||||
|
||||
})
|
||||
.catch(error => console.error('Error:', error));
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,60 +0,0 @@
|
||||
from flask import Flask, redirect, render_template, request, url_for
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
db = SQLAlchemy(model_class=Base)
|
||||
|
||||
# create the app
|
||||
app = Flask(__name__)
|
||||
# configure the SQLite database, relative to the app instance folder
|
||||
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///project.db"
|
||||
# initialize the app with the extension
|
||||
db.init_app(app)
|
||||
|
||||
from sqlalchemy import Integer, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
class User(db.Model):
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
username: Mapped[str] = mapped_column(unique=True)
|
||||
email: Mapped[str]
|
||||
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
|
||||
@app.route("/users")
|
||||
def user_list():
|
||||
users = db.session.execute(db.select(User).order_by(User.username)).scalars()
|
||||
return render_template("user/list.html", users=users)
|
||||
|
||||
@app.route("/users/create", methods=["GET", "POST"])
|
||||
def user_create():
|
||||
if request.method == "POST":
|
||||
user = User(
|
||||
username=request.form["username"],
|
||||
email=request.form["email"],
|
||||
)
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
return redirect(url_for("user_detail", id=user.id))
|
||||
|
||||
return render_template("user/create.html")
|
||||
|
||||
@app.route("/user/<int:id>")
|
||||
def user_detail(id):
|
||||
user = db.get_or_404(User, id)
|
||||
return render_template("user/detail.html", user=user)
|
||||
|
||||
@app.route("/user/<int:id>/delete", methods=["GET", "POST"])
|
||||
def user_delete(id):
|
||||
user = db.get_or_404(User, id)
|
||||
|
||||
if request.method == "POST":
|
||||
db.session.delete(user)
|
||||
db.session.commit()
|
||||
return redirect(url_for("user_list"))
|
||||
|
||||
return render_template("user/delete.html", user=user)
|
Reference in New Issue
Block a user