Example #1
0
def distributor_id(req):
	id = req['PATH_INFO'].split("/")[2];
	db = req['cur'];
	user = writes.helper_req2user(req);
	distributor = None
	if(user['type'] == 'manufacturer'):
		distributors = get_employees(db, 'manufacturer', user['id'])
		for dist in distributors:
			if dist['boss'] == user['id']:
				distributor = get_users(db, 'distributor', id)[0]
		if(distributor is None):
			return "200 OK", [('Content-type', 'text/html')], 'Not your employee!'
	elif(user['type'] == 'admin'):
		distributor = get_users(db, 'distributor', id)[0]
	elif(user['type'] == 'distributor'):
			distributor = get_users(db, 'distributor', id)[0]
	else:
		return "200 OK", [('Content-type', 'text/html')], 'Not enough priviledges'
	tmpl = env.get_template( "distributor_id.html")
		 
	html = tmpl.render(
	    distributor = distributor,
		sellers = get_employees(db, 'distributor', distributor['id'])
	)
	return "200 OK", [('Content-type', 'text/html')], str(html)
Example #2
0
def distributor(req):
	db = req['cur'];
	user = writes.helper_req2user(req);
	if(user is not None):
		if(user['type'] == 'manufacturer' or user['type'] == 'admin'):
			tmpl = env.get_template( "distributor.html")
			distributors = None
			if(user['type'] == 'manufacturer'):
				distributors = get_employees(db, 'manufacturer', user['id'])
			else:
				distributors = get_users(db, 'distributor')

			countries = []
			for distributor in distributors:
				if distributor['location'] not in countries:
					countries.append(distributor['location'])


			html = tmpl.render(
			    distributors = distributors,
			    sellers = get_users(db, 'seller'),
				countries = countries
			)
			return "200 OK", [('Content-type', 'text/html')], str(html)
		else:
			return "200 OK", [('Content-type', 'text/html')], 'Not a manufacturer!'
	else:
		return "200 OK", [('Content-type', 'text/html')], 'Please login'
Example #3
0
def customer(req):
	db = req['cur'];
	user = writes.helper_req2user(req);
	tmpl = env.get_template( "customer.html")
		 
	html = tmpl.render(
	    customers = get_users(db, 'customer')
	)
	return "200 OK", [('Content-type', 'text/html')], str(html)
Example #4
0
def manufacturer(req):
	db = req['cur'];
	user = writes.helper_req2user(req);
	if(user is not None):
		if(user['type'] == 'admin'):
			tmpl = env.get_template( "manufacturer.html")
			manufacturers = get_users(db, 'manufacturer')
			countries = []

			for manufacturer in manufacturers:
				if manufacturer['location'] not in countries:
					countries.append(manufacturer['location'])
				 
			html = tmpl.render(
			    manufacturers = get_users(db, 'manufacturer'),
			    distributors = get_users(db, 'distributor'),
			    sellers = get_users(db, 'seller'),
				countries = countries
			)
			return "200 OK", [('Content-type', 'text/html')], str(html)
		else:
			return "200 OK", [('Content-type', 'text/html')], 'Not an admin!'
	else:
		return "200 OK", [('Content-type', 'text/html')], 'Please login'
Example #5
0
def seller(req):
	db = req['cur'];
	user = writes.helper_req2user(req);
	if(user is not None):
		tmpl = env.get_template( "seller.html")
		distributors = None
		sellers = []
		if(user['type'] == 'manufacturer'):
			distributors = get_employees(db, 'manufacturer', user['id'])
			for distributor in distributors:
				seller = get_employees(db, 'distributor', distributor['id'])
				for s in seller:
					sellers.append(s)
			if(sellers is None):
				return "200 OK", [('Content-type', 'text/html')], 'No sellers'
		elif(user['type'] == 'distributor'):
			distributors = get_employees(db, 'distributor', user['id'])
		elif(user['type'] == 'admin'):
			sellers = get_users(db, 'seller')
		else:
			return "200 OK", [('Content-type', 'text/html')], 'Not enough priviledges'

		countries = []
		for seller in sellers:
			if seller['location'] not in countries:
				countries.append(seller['location'])


		html = tmpl.render(
		    sellers = sellers,
		    customers = get_users(db, 'customer'),
			countries = countries
		)
		return "200 OK", [('Content-type', 'text/html')], str(html)
	else:
		return "200 OK", [('Content-type', 'text/html')], 'Please login'
Example #6
0
def product(req):
	#require login
	user = writes.helper_req2user(req);
	if not user:
	    return "302 Found", [('Location', '/?next={}'.format(urllib.quote(req['PATH_INFO'])))], ""
	db = req['cur'];
	user = writes.helper_req2user(req);
	products = []
	distributors = None
	sellers = []
	customers = []
	if(user['type'] == 'manufacturer'):
		distributors = get_employees(db, 'manufacturer', user['id'])
		for distributor in distributors:
			seller = get_employees(db, 'distributor', distributor['id'])
			for s in seller:
				sellers.append(s)
		if(sellers is None):
			return "200 OK", [('Content-type', 'text/html')], 'No sellers'
		else:
			for seller in sellers:
				customer = get_employees(db, 'seller', seller['id'])
				for c in customer:
					customers.append(c)
	elif(user['type'] == 'distributor'):
		sellers = get_employees(db, 'distributor', user['id'])
		for seller in sellers:
			customer = get_employees(db, 'seller', seller['id'])
			for c in customer:
				customers.append(c)
	elif(user['type'] == 'seller'):
		customer = get_employees(db, 'seller', user['id'])
		for c in customer:
			customers.append(c)
	else:
		return "200 OK", [('Content-type', 'text/html')], 'Not enough priviledges'

	for p in get_products(db, user['id']):
		products.append(p)

	if(distributors is not None and distributors ):
		for d in distributors:
			for p in get_products(db, d['id']):
				products.append(p)
	if(sellers is not None and sellers ):
		for s in sellers:
			for p in get_products(db, s['id']):
				products.append(p)
	if(customers is not None and customers ):
		for c in customers:
			for p in get_products(db, c['id']):
				products.append(p)

	products = sorted(products, key=lambda k: k['id'])

	tmpl = env.get_template( "product.html")
	html = tmpl.render(
	    products = products,
	    user = user
	    )
	return "200 OK", [('Content-type', 'text/html')], str(html)