-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview_myprofile.py
More file actions
98 lines (84 loc) · 3.46 KB
/
view_myprofile.py
File metadata and controls
98 lines (84 loc) · 3.46 KB
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
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
import bene_query
import bene_util
import os
"""
View my Producer Page
"""
class ViewMyProfile(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
if not user: # need to sign in
self.redirect('/?signin=True')
return
'''
PRODUCER PROFILE
'''
if bene_query.getCurrentUser().isProducer:
_producer = bene_query.getCurrentProducer()
if _producer == None: # no producer signed up, so ask to sign up
self.redirect('/')
return
# Make a dictionary for template
name = _producer.name
description = _producer.description
products = _producer.getProducts()
workers = _producer.getWorkers()
factories = _producer.getFactories()
template_values = bene_util.initTemplate(self.request.uri)
template_values['id'] = _producer.key()
template_values['name'] = name
template_values['description'] = description
template_values['factories'] = factories
template_values['products'] = products
template_values['producer'] = _producer
template_values['workers'] = workers
template_values['url'] = self.request.url
template_values['can_edit'] = False
user = users.get_current_user()
if user:
if _producer.owner == user:
template_values['can_edit'] = True
if _producer.getPicture():
template_values['has_image'] = True
else:
template_values['has_image'] = False
path = os.path.join(os.path.dirname(__file__), 'viewproducer.html')
self.response.out.write(template.render(path, template_values))
return
'''
CONSUMER PROFILE
'''
_consumer = bene_query.getCurrentConsumer();
if _consumer == None: # no consumer page, so create one
self.redirect('/')
return
# Make a dictionary for template
name = _consumer.name
profile = _consumer.profile
template_values = bene_util.initTemplate(self.request.uri)
template_values['id'] = _consumer.key()
template_values['consumer'] = _consumer
template_values['name'] = name
template_values['profile'] = profile
template_values['can_edit'] = False
user = users.get_current_user()
if user:
if _consumer.owner == user:
template_values['can_edit'] = True
path = os.path.join(os.path.dirname(__file__), 'viewconsumer.html')
self.response.out.write(template.render(path, template_values))
return
'''
Exception handler
'''
def handle_exception(self, exception, debug_mode):
if debug_mode:
super(ViewMyProfile, self).handle_exception(exception, debug_mode)
else:
template_values = bene_util.initTemplate(self.request.uri)
path = os.path.join(os.path.dirname(__file__), 'not_found.html')
self.response.out.write(template.render(path, template_values))
return