|
| @@ -2,6 +2,7 @@ |
| @@ -2,6 +2,7 @@ |
|
2
| |
2
| |
|
3
| import json |
3
| import json |
|
4
| |
4
| |
|
| |
5
| +from Products.statusmessages.interfaces import IStatusMessage |
|
5
| from plone import api |
6
| from plone import api |
|
6
| from five import grok |
7
| from five import grok |
|
7
| from zope.interface import Interface |
8
| from zope.interface import Interface |
|
| @@ -73,7 +74,26 @@ class ListaTelefonicaView(grok.View): |
| @@ -73,7 +74,26 @@ class ListaTelefonicaView(grok.View): |
|
73
| return self.context.Description() |
74
| return self.context.Description() |
|
74
| |
75
| |
|
75
| |
76
| |
|
76
| -class PessoaView(grok.View): |
77
| +class PessoaMixin(object): |
|
| |
78
| + |
|
| |
79
| + def is_owner(self): |
|
| |
80
| + # Get username |
|
| |
81
| + current = api.user.get_current() |
|
| |
82
| + username = current.getUserName() |
|
| |
83
| + |
|
| |
84
| + # Check if logged user is object's creator |
|
| |
85
| + owner = self.context.Creator() |
|
| |
86
| + if username == owner: |
|
| |
87
| + return True |
|
| |
88
| + return False |
|
| |
89
| + |
|
| |
90
| + def was_deleted(self): |
|
| |
91
| + if self.is_owner() and self.context.excluir_dados: |
|
| |
92
| + return True |
|
| |
93
| + return False |
|
| |
94
| + |
|
| |
95
| + |
|
| |
96
| +class PessoaView(PessoaMixin, grok.View): |
|
77
| grok.context(IPessoa) |
97
| grok.context(IPessoa) |
|
78
| grok.require('zope2.View') |
98
| grok.require('zope2.View') |
|
79
| grok.name('view') |
99
| grok.name('view') |
|
| @@ -87,16 +107,32 @@ class PessoaView(grok.View): |
| @@ -87,16 +107,32 @@ class PessoaView(grok.View): |
|
87
| |
107
| |
|
88
| return "<span>{0}</span> <br /> <span>{1}</span>".format(ramal1, ramal2) |
108
| return "<span>{0}</span> <br /> <span>{1}</span>".format(ramal1, ramal2) |
|
89
| |
109
| |
|
90
| - def is_owner(self): |
| |
|
91
| - # Get username |
| |
|
92
| - current = api.user.get_current() |
| |
|
93
| - username = current.getUserName() |
| |
|
94
| |
110
| |
|
95
| - # Check if logged user is object's creator |
| |
|
96
| - owner = self.context.Creator() |
| |
|
97
| - if username == owner: |
| |
|
98
| - return True |
| |
|
99
| - return False |
111
| +class SelfDeleteData(PessoaMixin, grok.View): |
|
| |
112
| + """ """ |
|
| |
113
| + grok.context(IPessoa) |
|
| |
114
| + grok.require('zope2.View') |
|
| |
115
| + grok.name('lista_delete_data') |
|
| |
116
| + |
|
| |
117
| + def __call__(self): |
|
| |
118
| + if not self.was_deleted() or not self.is_owner(): |
|
| |
119
| + return self.redirect(self.context.absolute_url()) |
|
| |
120
| + self.delete() |
|
| |
121
| + return super(SelfDeleteData, self).__call__() |
|
| |
122
| + |
|
| |
123
| + def delete(self): |
|
| |
124
| + if 'cancel' in self.request.form and self.request.form['cancel'] == 'yes': |
|
| |
125
| + import transaction |
|
| |
126
| + self.context.excluir_dados = False |
|
| |
127
| + transaction.commit() |
|
| |
128
| + return self.redirect(self.context.absolute_url()) |
|
| |
129
| + else: |
|
| |
130
| + api.content.delete(self.context) |
|
| |
131
| + messages = IStatusMessage(self.request) |
|
| |
132
| + messages.add(u'Seus dados foram excluídos com sucesso!', type=u'info') |
|
| |
133
| + portal_url = api.portal.get().absolute_url() |
|
| |
134
| + url_return = "{0}/lista-telefonica".format(portal_url) |
|
| |
135
| + return self.redirect(url_return) |
|
100
| |
136
| |
|
101
| |
137
| |
|
102
| class UnidadesView(grok.View): |
138
| class UnidadesView(grok.View): |
|
| @@ -205,6 +241,12 @@ class UnidadesView(grok.View): |
| @@ -205,6 +241,12 @@ class UnidadesView(grok.View): |
|
205
| def update(self): |
241
| def update(self): |
|
206
| self.persons = self.get_results() |
242
| self.persons = self.get_results() |
|
207
| |
243
| |
|
| |
244
| + def registry(self): |
|
| |
245
| + """ """ |
|
| |
246
| + portal_url = self.context.absolute_url() |
|
| |
247
| + login_url = "{0}/login_form?came_from=after_login".format(portal_url) |
|
| |
248
| + return login_url |
|
| |
249
| + |
|
208
| |
250
| |
|
209
| class UnidadesIframeView(UnidadesView): |
251
| class UnidadesIframeView(UnidadesView): |
|
210
| grok.name('unidade_iframe') |
252
| grok.name('unidade_iframe') |