update mock function

This commit is contained in:
Chen Shuyang
2021-03-02 15:56:00 +00:00
parent a6cf4362d9
commit 01d560f41f
7 changed files with 105 additions and 113 deletions

127
app.py
View File

@ -1,6 +1,6 @@
from flask import Flask, redirect, url_for, render_template, request, flash
from models import db, Contact, User, Company, Trans, Inquery
from forms import ContactForm, CompanyForm, TransForm, InqueryForm
from models import db, Contact, User
from forms import ContactForm
from flask_login import LoginManager, current_user, login_user, login_required
@ -149,79 +149,100 @@ def contacts_delete():
@app.route("/test1", methods=('GET', 'POST'))
@login_required
def test1():
c1 = Company()
c1.name = '大连丰达海产品有限公司'
c1.city = '辽宁省大连市'
c1.date = '2018-09-02'
c1 = dict()
c1['account'] = '15120201012'
c1['ip'] = '23.14.234.12'
c1['location'] = '河南郑州'
c1['isp'] = '中国联通'
c1['cnt1'] = '3'
c1['cnt2'] = '2'
c2 = Company()
c2.name = '北京斯科特科技有限公司'
c2.city = '北京市'
c2.date = '2020-11-29'
c2 = dict()
c2['account'] = '15120210128'
c2['ip'] = '12.221.21.2'
c2['location'] = '广州深圳'
c2['isp'] = '中国联通'
c2['cnt1'] = '1'
c2['cnt2'] = '1'
c3 = Company()
c3.name = '大连罗森有限公司'
c3.city = '辽宁省大连市'
c3.date = '2020-12-22'
c3 = dict()
c3['account'] = '15220201214'
c3['ip'] = '122.23.11.25'
c3['location'] = '北京'
c3['isp'] = '中国电信'
c3['cnt1'] = '8'
c3['cnt2'] = '4'
companies = []
companies.append(c1)
companies.append(c2)
companies.append(c3)
data = []
data.append(c1)
data.append(c2)
data.append(c3)
return render_template('web/test1.html', contacts=companies)
return render_template('web/test1.html', contacts=data)
@app.route("/test2", methods=('GET', 'POST'))
@login_required
def test2():
t1 = Trans()
t1.name = '大连丰达海产品有限公司'
t1.number = 1
t1.price = 3500
t1 = dict()
t1['account'] = '15220201027'
t1['login'] = '2021-02-28 12:16:23'
t1['duration'] = '41'
t1['total'] = '953'
t2 = Trans()
t2.name = '大连罗森有限公司'
t2.number = 3
t2.price = 3500
t2 = dict()
t2['account'] = '15220201214'
t2['login'] = '2021-02-22 09:23:51'
t2['duration'] = '342'
t2['total'] = '1234'
t3 = Trans()
t3.name = '大连罗森有限公司'
t3.number = 10
t3.price = 3000
t3 = dict()
t3['account'] = '15220210129'
t3['login'] = '2020-12-31 12:34:22'
t3['duration'] = '12'
t3['total'] = '31'
t4 = Trans()
t4.name = '大连丰达海产品有限公司'
t4.number = 5
t4.price = 3300
t4 = dict()
t4['account'] = '15320201030'
t4['login'] = '2021-01-03 20:12:34'
t4['duration'] = '434'
t4['total'] = '1356'
trans_list = []
trans_list.append(t1)
trans_list.append(t2)
trans_list.append(t3)
trans_list.append(t4)
data = []
data.append(t1)
data.append(t2)
data.append(t3)
data.append(t4)
return render_template('web/test2.html', contacts=trans_list)
return render_template('web/test2.html', contacts=data)
@app.route("/test3", methods=('GET', 'POST'))
@login_required
def test3():
i1 = Inquery()
i1.name = '大连罗森有限公司'
i1.date = '2021-01-06'
i1.subject = '关于产品有效期问题'
d1 = dict()
d1['account'] = '15220210129'
d1['count'] = 9
i2 = Inquery()
i2.name = '大连罗森有限公司'
i2.date = '2021-01-11'
i2.subject = '关于产品售后支持'
d2 = dict()
d2['account'] = '15320201013'
d2['count'] = 22
inqueries = []
inqueries.append(i1)
inqueries.append(i2)
d3 = dict()
d3['account'] = '15320210302'
d3['count'] = 78
return render_template('web/test3.html', contacts=inqueries)
d4 = dict()
d4['account'] = '15220210129'
d4['count'] = 12
data = []
data.append(d1)
data.append(d2)
data.append(d3)
data.append(d4)
return render_template('web/test3.html', contacts=data)
if __name__ == "__main__":

View File

@ -11,19 +11,3 @@ class ContactForm(FlaskForm):
# surname = StringField('Surname', validators=[Length(min=-1, max=100, message='You cannot have more than 100 characters')])
# email = StringField('E-Mail', validators=[Email(), Length(min=-1, max=200, message='You cannot have more than 200 characters')])
# phone = StringField('Phone', validators=[Length(min=-1, max=20, message='You cannot have more than 20 characters')])
class CompanyForm(FlaskForm):
name = StringField('公司名', validators=[DataRequired(), Length(min=-1, max=30, message='用户名需要控制在30个字符以内')])
city = StringField('所在城市', validators=[DataRequired(), Length(min=-1, max=30, message='用户名需要控制在30个字符以内')])
date = StringField('登录日期', validators=[DataRequired(), Length(min=-1, max=30, message='用户名需要控制在30个字符以内')])
class TransForm(FlaskForm):
name = StringField('公司名', validators=[DataRequired(), Length(min=-1, max=30, message='用户名需要控制在30个字符以内')])
date = StringField('采购日期', validators=[DataRequired(), Length(min=-1, max=30, message='用户名需要控制在30个字符以内')])
number = StringField('采购数量', validators=[DataRequired(), Length(min=-1, max=30, message='用户名需要控制在30个字符以内')])
price = StringField('单价', validators=[DataRequired(), Length(min=-1, max=30, message='用户名需要控制在30个字符以内')])
class InqueryForm(FlaskForm):
name = StringField('公司名', validators=[DataRequired(), Length(min=-1, max=30, message='用户名需要控制在30个字符以内')])
date = StringField('问询日期', validators=[DataRequired(), Length(min=-1, max=30, message='用户名需要控制在30个字符以内')])
subject = StringField('问询主题', validators=[DataRequired(), Length(min=-1, max=30, message='用户名需要控制在30个字符以内')])

View File

@ -26,20 +26,3 @@ class User():
def get_id(id):
return 1
class Company():
name = ''
city = ''
date = ''
class Trans():
name = ''
date = ''
number = ''
price = ''
class Inquery():
name = ''
date = ''
subject = ''

View File

@ -36,9 +36,9 @@
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">客户信息<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="{{ url_for('test1') }}">客户公司信息</a></li>
<li><a href="{{ url_for('test2') }}">购买记录</a></li>
<li><a href="{{ url_for('test3') }}">客户咨询记录</a></li>
<li><a href="{{ url_for('test1') }}">IP登陆地统计</a></li>
<li><a href="{{ url_for('test2') }}">登陆市场统计</a></li>
<li><a href="{{ url_for('test3') }}">登录次数统计</a></li>
</ul>
</li>
</ul>

View File

@ -1,22 +1,27 @@
{% extends 'layouts/master.html' %}
{% block title %}View{% endblock %}
{% block body %}
<h1>Contacts</h1>
<h1>IP登陆地统计</h1>
<table class="table table-hover">
<thead>
<tr>
<th scope="col">公司名称</th>
<th scope="col">所在城市</th>
<th scope="col">登录日期</th>
<td></td>
<th scope="col">账号</th>
<th scope="col">上次登录IP</th>
<th scope="col">上次登陆地</th>
<th scope="col">运营商</th>
<th scope="col">登录IP地址统计</th>
<th scope="col">登陆地统计(省)</th>
</tr>
</thead>
<tbody>
{% for contact in contacts %}
<tr>
<td>{{ contact.name }}</td>
<td>{{ contact.city }}</td>
<td>{{ contact.date }}</td>
<td>{{ contact['account'] }}</td>
<td>{{ contact['ip'] }}</td>
<td>{{ contact['location'] }}</td>
<td>{{ contact['isp'] }}</td>
<td>{{ contact['cnt1'] }}</td>
<td>{{ contact['cnt2'] }}</td>
</tr>
{% endfor %}
</tbody>

View File

@ -1,22 +1,24 @@
{% extends 'layouts/master.html' %}
{% block title %}View{% endblock %}
{% block body %}
<h1>Contacts</h1>
<h1>登录时间统计</h1>
<table class="table table-hover">
<thead>
<tr>
<th scope="col">公司名称</th>
<th scope="col">购买数量</th>
<th scope="col">单价</th>
<th scope="col">账号</th>
<th scope="col">上次登录时间</th>
<th scope="col">上次登陆时长</th>
<th scope="col">总时长</th>
<td></td>
</tr>
</thead>
<tbody>
{% for contact in contacts %}
<tr>
<td>{{ contact.name }}</td>
<td>{{ contact.number}}</td>
<td>{{ contact.price}}</td>
<td>{{ contact['account'] }}</td>
<td>{{ contact['login'] }}</td>
<td>{{ contact['duration']}}</td>
<td>{{ contact['total']}}</td>
</tr>
{% endfor %}
</tbody>

View File

@ -1,22 +1,19 @@
{% extends 'layouts/master.html' %}
{% block title %}View{% endblock %}
{% block body %}
<h1>Contacts</h1>
<h1>登录次数统计</h1>
<table class="table table-hover">
<thead>
<tr>
<th scope="col">公司名称</th>
<th scope="col">咨询时间</th>
<th scope="col">咨询主题</th>
<td></td>
<th scope="col">账号</th>
<th scope="col">登录次数</th>
</tr>
</thead>
<tbody>
{% for contact in contacts %}
<tr>
<td>{{ contact.name }}</td>
<td>{{ contact.date }}</td>
<td>{{ contact.subject }}</td>
<td>{{ contact['account'] }}</td>
<td>{{ contact['count'] }}</td>
</tr>
{% endfor %}
</tbody>