Skip to content

Commit

Permalink
Code to change migrated property. Solved the hasattr property code
Browse files Browse the repository at this point in the history
  • Loading branch information
Roberto Diaz committed May 24, 2018
1 parent dec7e45 commit 7f5c940
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 20 deletions.
36 changes: 36 additions & 0 deletions genweb/organs/browser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,42 @@
from genweb.organs.interfaces import IGenwebOrgansLayer
import json
import transaction
from Products.statusmessages.interfaces import IStatusMessage


class changeMigrated(grok.View):
# Change migrated property of sessions.
# No se pueden editar sessiones de la versión antigua, pero
# en algunos casos, nos han pedido que se pueda...
# Este código cambia el valor de la propiedad para eso
grok.context(IDexterityContent)
grok.name('change_migrated_to')
grok.require('cmf.ManagePortal')
grok.layer(IGenwebOrgansLayer)

def render(self):
# http:/session_url/change_migrated_to?value=False
messages = IStatusMessage(self.request)
if self.context.portal_type == 'genweb.organs.sessio':
if self.request['value'] == 'True':
elements = api.content.find(path=self.context.absolute_url_path())
for item in elements:
value = item.getObject()
value.migrated = True
transaction.commit()
elif self.request['value'] == 'False':
elements = api.content.find(path=self.context.absolute_url_path())
for item in elements:
value = item.getObject()
value.migrated = False
transaction.commit()
else:
return

messages.add('migrated property set to: ' + str(self.request['value']), type='warning')
self.request.response.redirect(self.context.absolute_url())
else:
pass


class changeInitialProposalPoint(grok.View):
Expand Down
36 changes: 22 additions & 14 deletions genweb/organs/browser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,14 @@ def __call__(self):
class Move(BrowserView):

def __call__(self):
migrated = hasattr(self.context, 'migrated')
if migrated is True:
# Don't give option to modify numbers
return
migrated_property = hasattr(self.context, 'migrated')
if migrated_property:
if self.context.migrated is True:
return

# Disable CSRF
alsoProvides(self.request, IDisableCSRFProtection)

ordering = getOrdering(self.context)
# authenticator = getMultiAdapter((self.context, self.request),
# name=u"authenticator")
Expand Down Expand Up @@ -334,10 +338,10 @@ class ReloadAcords(BrowserView):
def __call__(self):
""" This call reassign the correct proposalPoints to the contents in this folder
"""
migrated = hasattr(self.context, 'migrated')
if migrated is True:
# Don't give option to modify numbers
return
migrated_property = hasattr(self.context, 'migrated')
if migrated_property:
if self.context.migrated is True:
return

# Disable CSRF
alsoProvides(self.request, IDisableCSRFProtection)
Expand Down Expand Up @@ -396,18 +400,18 @@ def __call__(self):

index = index + 1

self.request.response.redirect(self.context.absolute_url())
return self.request.response.redirect(self.context.absolute_url())


class ReloadPoints(BrowserView):
""" Renumera els punts manualment """
def __call__(self):
""" This call reassign the correct Point number to the contents in this folder
"""
migrated = hasattr(self.context, 'migrated')
if migrated is True:
# Don't give option to modify numbers
return
migrated_property = hasattr(self.context, 'migrated')
if migrated_property:
if self.context.migrated is True:
return

# Disable CSRF
alsoProvides(self.request, IDisableCSRFProtection)
Expand Down Expand Up @@ -443,7 +447,7 @@ def __call__(self):

index = index + 1

self.request.response.redirect(self.context.absolute_url())
return self.request.response.redirect(self.context.absolute_url())


class changeActualState(BrowserView):
Expand Down Expand Up @@ -490,6 +494,7 @@ def __call__(self):
addEntryLog(self.context, None, _(u'Changed acord color state'), itemid + ' → ' + estat) # add log
except:
pass
return


class changeSubpuntState(BrowserView):
Expand All @@ -499,6 +504,7 @@ class changeSubpuntState(BrowserView):
def __call__(self):
# Disable CSRF
alsoProvides(self.request, IDisableCSRFProtection)

portal_catalog = getToolByName(self, 'portal_catalog')
estat = self.request.form.get('estat')
itemid = self.request.form.get('id')
Expand All @@ -516,6 +522,8 @@ def __call__(self):
else:
addEntryLog(self.context, None, _(u'Changed acord intern state color'), currentitem[0].getPath() + ' → ' + estat) # add log

return


class Butlleti(BrowserView):
__call__ = ViewPageTemplateFile('views/butlleti.pt')
Expand Down
7 changes: 4 additions & 3 deletions genweb/organs/content/manualimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ def update(self):
""" Return true if user is Editor or Manager, but if the session """
""" came from the previous version, then make impossible to """
""" create new elements """
migrated = hasattr(self.context, 'migrated')
if migrated is True:
raise Unauthorized
migrated_property = hasattr(self.context, 'migrated')
if migrated_property:
if self.context.migrated is True:
raise Unauthorized

try:
username = api.user.get_current().id
Expand Down
8 changes: 5 additions & 3 deletions genweb/organs/content/sessio.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,11 @@ def viewHistory(self):

def canModify(self):
# If item is migrated, it can't be modified
migrated = hasattr(self.context, 'migrated')
if migrated is True:
return False
migrated_property = hasattr(self.context, 'migrated')
if migrated_property:
if self.context.migrated is True:
return False

# But if not migrated, check permissions...
review_state = api.content.get_state(self.context)
value = False
Expand Down

0 comments on commit 7f5c940

Please sign in to comment.