-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove restapi #106
Merged
Merged
Remove restapi #106
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7df4879
Remove restapi
rodfersou 2bd97d1
Remove tzname treatment in frontend
rodfersou b7cf82f
Fix traversal
hvelarde f37b40e
Fix pare redirection; Validate if date is valid
rodfersou 9552658
Code review
rodfersou 6255237
Add upgrade step to cook resources
rodfersou 9cdfd43
Fix tests
rodfersou 7cab498
Code review
hvelarde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
from six.moves import range # noqa: I001 | ||
from brasil.gov.agenda import _ | ||
from brasil.gov.agenda.config import AGENDADIARIAFMT | ||
from brasil.gov.agenda.interfaces import ICompromisso | ||
from brasil.gov.agenda.utils import AgendaMixin | ||
from datetime import datetime | ||
from datetime import timedelta | ||
from DateTime import DateTime | ||
from Products.CMFCore.utils import getToolByName | ||
from dateutil.tz import tzlocal | ||
from plone import api | ||
from Products.Five.browser import BrowserView | ||
from zExceptions import NotFound | ||
from zope.component import getMultiAdapter | ||
from zope.i18nmessageid import Message | ||
from zope.interface import implementer | ||
from zope.publisher.interfaces import IPublishTraverse | ||
from zope.publisher.publish import mapply | ||
|
||
import json | ||
|
||
|
||
class AgendaView(BrowserView, AgendaMixin): | ||
"""Visao padrao da agenda.""" | ||
|
@@ -18,7 +28,7 @@ def update(self): | |
name='plone_tools') | ||
context_state = getMultiAdapter((self.context, self.request), | ||
name=u'plone_context_state') | ||
self._ts = getToolByName(self.context, 'translation_service') | ||
self._ts = api.portal.get_tool('translation_service') | ||
self.catalog = plone_tools.catalog() | ||
self.agenda = self.context | ||
self.workflow = plone_tools.workflow() | ||
|
@@ -29,9 +39,9 @@ def __call__(self): | |
# return super(AgendaView, self).__call__() | ||
agenda_recente = self.agenda_recente() | ||
if agenda_recente and not self.editable: | ||
return agenda_recente.restrictedTraverse('@@view')() | ||
else: | ||
return super(AgendaView, self).__call__() | ||
response = self.request.response | ||
response.redirect(agenda_recente.absolute_url()) | ||
return super(AgendaView, self).__call__() | ||
|
||
def agenda_recente(self): | ||
"""Deve retornar a agendadiaria para o dia atual | ||
|
@@ -91,3 +101,67 @@ def imagem(self): | |
scale = view.scale(fieldname='image', scale='large') | ||
tag = scale.tag() | ||
return tag | ||
|
||
|
||
@implementer(IPublishTraverse) | ||
class AgendaJSONView(BrowserView, AgendaMixin): | ||
"""JSON view.""" | ||
|
||
def publishTraverse(self, request, date): | ||
"""Get the selected date.""" | ||
try: | ||
datetime.strptime(date, AGENDADIARIAFMT) | ||
except ValueError: # invalid date format | ||
raise NotFound | ||
|
||
self.date = date | ||
return self | ||
|
||
def weekday(self, date): | ||
ts = api.portal.get_tool('translation_service') | ||
return self._translate(ts.day_msgid(date.strftime('%w'))) | ||
|
||
def extract_data(self): | ||
data = [] | ||
now = datetime.now() | ||
tzname = datetime.now(tzlocal()).tzname() | ||
selected = datetime.strptime(self.date, AGENDADIARIAFMT) | ||
days = [selected + timedelta(days=i) for i in range(-3, 4)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
for date in days: | ||
strday = date.strftime(AGENDADIARIAFMT) | ||
day = { | ||
'datetime': '{0}{1}:00'.format(date.isoformat(), tzname), | ||
'day': date.day, | ||
'weekday': self.weekday(date)[:3], | ||
'items': [], | ||
'hasAppointment': False, | ||
'isSelected': False, | ||
} | ||
if self.date == strday: | ||
day['isSelected'] = True | ||
agendadiaria = self.context.get(strday, None) | ||
if agendadiaria: | ||
day['hasAppointment'] = True | ||
compromissos = api.content.find( | ||
context=agendadiaria, | ||
object_provides=ICompromisso, | ||
sort_on='start', | ||
) | ||
for brain in compromissos: | ||
obj = brain.getObject() | ||
day['items'].append({ | ||
'title': obj.title, | ||
'start': obj.start_date.strftime('%Hh%M'), | ||
'datetime': '{0}{1}:00'.format(obj.start_date.isoformat(), tzname), | ||
'location': obj.location, | ||
'href': obj.absolute_url(), | ||
'vcal': '{0}/vcal_view'.format(obj.absolute_url()), | ||
'isNow': obj.start_date <= now <= obj.end_date, | ||
}) | ||
data.append(day) | ||
return data | ||
|
||
def __call__(self): | ||
response = self.request.response | ||
response.setHeader('content-type', 'application/json') | ||
return response.setBody(json.dumps(self.extract_data())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,16 +32,9 @@ def Title(self): | |
fmt_date = date.strftime('%d/%m/%Y') | ||
autoridade = self.autoridade | ||
mapping = {'autoridade': autoridade, 'fmt_date': fmt_date} | ||
if type(self.REQUEST) is str: | ||
# this happens with plone.restapi, we lose reference of REQUEST object when | ||
# it adapts to plone.app.contentlisting so there is no way to do get portal_state | ||
# https://github.com/plone/plone.restapi/blob/master/src/plone/restapi/serializer/summary.py#L25 | ||
# https://github.com/plone/plone.app.contentlisting/blob/1.0.5/plone/app/contentlisting/realobject.py#L38 | ||
current_language = 'pt-br' | ||
else: | ||
portal_state = getMultiAdapter((self, self.REQUEST), | ||
name=u'plone_portal_state') | ||
current_language = portal_state.language() | ||
portal_state = getMultiAdapter((self, self.REQUEST), | ||
name=u'plone_portal_state') | ||
current_language = portal_state.language() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the API: |
||
tool = api.portal.get_tool('translation_service') | ||
# FIXME: Ao trocar a língua de um portal, o título de uma agenda não | ||
# será alterado no folder_contents. Como a recomendação atual de sites | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tem uma explicação melhor sobre isso? Na branch 1.x os testes passam, mas se eu dou checkout para fazer um teste exploratório, não consigo salvar uma agenda.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agora estamos usando uma versão de
lxml
maior e eles removeram ocssselect
de ai.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sim, o traceback começa no lxml, só achei engraçado os testes passarem. Vou adicionar essa dependência na branch 1.x.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
na verdade acho que a dependência tem que ser adicionada no plone.protect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plone/plone.protect#79