Skip to content

Commit

Permalink
TODO show current date events
Browse files Browse the repository at this point in the history
  • Loading branch information
robdayz committed Oct 25, 2018
1 parent dde5391 commit ea2cbd9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
21 changes: 12 additions & 9 deletions genweb/organs/portlets/portlet_calendar.pt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<ul class="icons-ul">


<tal:block tal:repeat="event view/getDayEventsGroup" tal:condition="view/isAnon">
<!-- <tal:block tal:repeat="event view/getDayEventsGroup" tal:condition="view/isAnon">
<li tal:define="licolor event/color" tal:attributes="style string:border-left: 5px solid ${licolor}">
<p>
<i class="fa fa-calendar"></i>&nbsp;
Expand All @@ -107,15 +107,19 @@
<a tal:attributes="href event/community_url" tal:content="event/community_name"></a>
</span>
</li>
</tal:block>
</tal:block> -->

<hr/>NEW CODE
<tal:block tal:repeat="event view/next3Events">
<li>
<li tal:define="licolor event/color" tal:attributes="style string:border-left: 5px solid ${licolor}">
<p>
<i class="fa fa-calendar"></i>&nbsp;
<a tal:attributes="href event/url">
<a tal:attributes="href event/url;
style string:color:${event/color}">
<tal:event content="event/start"> 07/12 </tal:event>
<span tal:condition="event/end">
<span i18n:translate="" i18n:domain="genweb.organs"> to </span>
<tal:event content="event/end"> 07/12 </tal:event>
</span>
- <tal:event content="event/session_title"> Event Title </tal:event>
</a>
</p>
Expand All @@ -125,9 +129,8 @@
</span>
</li>
</tal:block>
<br/>end new code<hr/>
<hr/>OLDCODE


<!-- <hr/>OLDCODE
<tal:block tal:repeat="event view/getDayEventsGroupValidated" tal:condition="not:view/isAnon">
<li tal:define="licolor event/color" tal:attributes="style string:border-left: 5px solid ${licolor}">
<p>
Expand All @@ -148,7 +151,7 @@
</span>
</li>
</tal:block>
END OLDCODE
END OLDCODE -->
<hr/>

</ul>
Expand Down
35 changes: 24 additions & 11 deletions genweb/organs/portlets/portlet_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import time
from plone import api
import DateTime
import datetime
import calendar


Expand Down Expand Up @@ -228,38 +227,52 @@ def filterNextEvents(self, events):

def next3Events(self):
""" Returns next 3 events based on public organs fields """
start_time = time.time()
print("\n-- START NEW CODE --- %s seconds --- " % (time.time() - start_time))
today = DateTime.DateTime() # Today
date_future_events = {'query': (today), 'range': 'min'}

formatDate = "%Y-%m-%d"
if 'day' in self.request.form and 'year' in self.request.form and 'month' in self.request.form:
date = '{}-{}-{}'.format(
self.request.form['year'],
self.request.form['month'],
self.request.form['day'])
dateEvent = datetime.strptime(date, formatDate)
# Shows only specified date
date_events = {'query': (dateEvent, dateEvent), 'range': 'min:max'}
else:
# TODO....
# Future, show 3 events
date = datetime.today().strftime(formatDate)
dateEvent = datetime.strptime(date, formatDate)
date_events = {'query': (dateEvent), 'range': 'min'}
portal_catalog = getToolByName(self.context, 'portal_catalog')
if api.user.is_anonymous():
future_sessions = portal_catalog.unrestrictedSearchResults(
portal_type='genweb.organs.sessio',
sort_on='start',
end=date_future_events,
start=date_events,
path=self.get_public_organs_fields()
)[:3]
else:
future_sessions = portal_catalog.unrestrictedSearchResults(
portal_type='genweb.organs.sessio',
sort_on='start',
end=date_future_events,
start=date_events,
)[:3]

future = []
current_year = datetime.datetime.now().strftime('%Y')
current_year = datetime.now().strftime('%Y')
for session in future_sessions:
obj = session._unrestrictedGetObject()
event = IEventAccessor(obj)
start = event.start.strftime('%d/%m')
end = event.end.strftime('%d/%m')
end = None if end == start else end
if obj.start.strftime('%Y') == current_year:
future.append(dict(
title=obj.aq_parent.title,
session_title=obj.title,
start=event.start.strftime('%d/%m'),
start=start,
end=end,
color=obj.eventsColor,
url=session.getPath()))
print("-- END NEW CODE --- %s seconds --- " % (time.time() - start_time))
return future

def getDayEventsGroup(self):
Expand Down

0 comments on commit ea2cbd9

Please sign in to comment.