-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathinit.py
114 lines (96 loc) · 3.08 KB
/
init.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
##
# -*- coding: utf-8 -*-
##
##
# Bootstrap CRM app service.
##
# Import community modules.
import sys
# Append App specific Python paths.
sys.path.append('model')
sys.path.append('controller')
sys.path.append('helper')
# Import community modules.
import argparse
from flask import Flask,request
# Import custom modules.
from controller.user import user_web_controller
from controller.customer import customer_web_controller
from controller.contact import contact_web_controller
# Health web controller.
def health_web_controller():
return str('OK')
# View dashboard.
def dashboard():
if request.method=='GET':
return user_web_controller(request).get()
else:
return None
# Create customer.
def create_customer():
if request.method=='GET':
return customer_web_controller(request).get()
elif request.method=='POST':
return customer_web_controller(request).post()
else:
return None
# Update customer.
def update_customer(arg_0):
if request.method=='GET':
return customer_web_controller(request).get(str(arg_0))
elif request.method=='POST':
return customer_web_controller(request).post(str(arg_0))
else:
return None
# List customers.
def list_customers():
if request.method=='GET':
return customer_web_controller(request).get()
else:
return None
# Create contact.
def create_contact(arg_0):
if request.method=='GET':
return contact_web_controller(request).get(str(arg_0))
elif request.method=='POST':
return contact_web_controller(request).post(str(arg_0))
else:
return None
# Update contact.
def update_contact(arg_0,arg_1):
if request.method=='GET':
return contact_web_controller(request).get(str(arg_0),str(arg_1))
elif request.method=='POST':
return contact_web_controller(request).post(str(arg_0),str(arg_1))
else:
return None
# List contacts.
def list_contacts():
if request.method=='GET':
return contact_web_controller(request).get()
else:
return None
# Initialize Flask app.
app = Flask('CRM app',template_folder='view')
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False
# App routes.
app.add_url_rule('/health',view_func=health_web_controller)
app.add_url_rule('/dashboard',view_func=dashboard)
app.add_url_rule('/customer/create',view_func=create_customer,methods=['GET','POST'])
app.add_url_rule('/customer/<int:arg_0>/update',view_func=update_customer,methods=['GET','POST'])
app.add_url_rule('/customers',view_func=list_customers)
app.add_url_rule('/customer/<int:arg_0>/contact/create',view_func=create_contact,methods=['GET','POST'])
app.add_url_rule('/customer/<int:arg_0>/contact/<int:arg_1>/update',view_func=update_contact,methods=['GET','POST'])
app.add_url_rule('/customer/<int:arg_0>/contacts',view_func=list_contacts)
if __name__=='__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--port',type=int,default=2000)
parser.add_argument('--host',default='0.0.0.0')
args = parser.parse_args()
try:
print 'Starting CRM app service...'
app.run(debug=True,host=args.host,port=args.port)
except KeyboardInterrupt:
print 'Stopping CRM app service...'
finally:
pass