-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper_functions.py
61 lines (49 loc) · 1.74 KB
/
helper_functions.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
import re
import db
def relative_link(request_path, request_referrer):
path = request_path
referrer = request_referrer
# print('Path: '+path+'\n'+'Referrer: '+referrer)
if path is None:
return '/'
if referrer is None:
referrer = ''
listing_detail = re.compile(r'/listing/\d*$').findall(path)
listing_purchase = re.compile(r'/listing/buy/\d*$').findall(path)
user_profile = re.compile(r'/user/\d*$').findall(path)
user_refer = re.compile(r'/user/\d*$').findall(referrer)
search = re.findall(r'/search', referrer)
account = re.findall(r'/account', referrer)
index = re.compile(r'\/[0-9]+').findall(path)
if listing_detail and user_refer:
return referrer
elif listing_detail and not search and not account:
return '/'
elif listing_detail and not search and account:
return referrer
elif listing_purchase:
return '/listing' + index[0]
elif user_profile:
return referrer
elif search:
return referrer
elif index:
return '/'
def address_string(user_id):
address = db.get_user_address(user_id)
location_address = '{}, {}'.format(address['city'], address['abbrev'])
for_gapi = '{}+{}%2C+{}+{}'.format(
'+'.join(address['street'].split(' ')), '+'.join(
address['city'].split(' ')), '+'.join(address['name'].split(' ')),
address['zipcode'])
return location_address, for_gapi
def address_url(address):
map_url = 'https://www.google.com/maps/search/?api=1&query={}'.format(
address)
return map_url
def get_usa_states():
states = db.get_all_states()
states_list = []
for state in states:
states_list.append((state[0], state[1]))
return states_list