[fedocal] master: Rework the retrieve_meeting_to_remind (774a7bb)
by Pierre-YvesChibon
Repository : http://git.fedorahosted.org/cgit/fedocal.git
On branch : master
>---------------------------------------------------------------
commit 774a7bbc31267d5044d9f1f68a46db3219603a46
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Mon Nov 26 21:58:22 2012 +0100
Rework the retrieve_meeting_to_remind
Hey look we can do the same thing but in a much nicer way!
>---------------------------------------------------------------
fedocal/fedocallib/__init__.py | 33 ++++++++++-----------------------
1 files changed, 10 insertions(+), 23 deletions(-)
diff --git a/fedocal/fedocallib/__init__.py b/fedocal/fedocallib/__init__.py
index a7fa883..c3c5924 100644
--- a/fedocal/fedocallib/__init__.py
+++ b/fedocal/fedocallib/__init__.py
@@ -508,29 +508,16 @@ def retrieve_meeting_to_remind(session, offset=30):
to avoid sending twice the same reminder.
"""
today = datetime.utcnow()
- # Retrieve meeting planned in less than 12h
- new_date = _generate_date_rounded_to_the_hour(today, 12)
- end_date = new_date + timedelta(minutes=offset)
- meetings = Meeting.get_meeting_with_reminder(session,
- new_date.date(), new_date.time(), end_date.time(), 'H-12')
-
- # Retrieve meeting planned in less than 24h
- new_date = _generate_date_rounded_to_the_hour(today, 24)
- end_date = new_date + timedelta(minutes=offset)
- meetings.extend(Meeting.get_meeting_with_reminder(session,
- new_date.date(), new_date.time(), end_date.time(), 'H-24'))
-
- # Retrieve meeting planned in less than 48h
- new_date = _generate_date_rounded_to_the_hour(today, 48)
- end_date = new_date + timedelta(minutes=offset)
- meetings.extend(Meeting.get_meeting_with_reminder(session,
- new_date.date(), new_date.time(), end_date.time(), 'H-48'))
-
- # Retrieve meeting planned in less than 168h
- new_date = _generate_date_rounded_to_the_hour(today, 168)
- end_date = new_date + timedelta(minutes=offset)
- meetings.extend(Meeting.get_meeting_with_reminder(session,
- new_date.date(), new_date.time(), end_date.time(), 'H-168'))
+ meetings = []
+
+ for reminder_time in [12, 24, 48, 168]:
+ # Retrieve meeting planned in less than X hours
+ new_date = _generate_date_rounded_to_the_hour(today,
+ reminder_time)
+ end_date = new_date + timedelta(minutes=offset)
+ meetings.extend(Meeting.get_meeting_with_reminder(session,
+ new_date.date(), new_date.time(), end_date.time(), 'H-%s' %
+ reminder_time))
return meetings
11 years, 5 months
[fedocal] master: Fix retrieve_meeting_to_remind (6079260)
by pingou@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/fedocal.git
On branch : master
>---------------------------------------------------------------
commit 60792607deba83794f71891ca188431b77124ccd
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Mon Nov 26 21:52:06 2012 +0100
Fix retrieve_meeting_to_remind
When we update the new_date we need to update the end_date as well
>---------------------------------------------------------------
fedocal/fedocallib/__init__.py | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/fedocal/fedocallib/__init__.py b/fedocal/fedocallib/__init__.py
index 16f197f..a7fa883 100644
--- a/fedocal/fedocallib/__init__.py
+++ b/fedocal/fedocallib/__init__.py
@@ -513,13 +513,22 @@ def retrieve_meeting_to_remind(session, offset=30):
end_date = new_date + timedelta(minutes=offset)
meetings = Meeting.get_meeting_with_reminder(session,
new_date.date(), new_date.time(), end_date.time(), 'H-12')
+
+ # Retrieve meeting planned in less than 24h
new_date = _generate_date_rounded_to_the_hour(today, 24)
+ end_date = new_date + timedelta(minutes=offset)
meetings.extend(Meeting.get_meeting_with_reminder(session,
new_date.date(), new_date.time(), end_date.time(), 'H-24'))
+
+ # Retrieve meeting planned in less than 48h
new_date = _generate_date_rounded_to_the_hour(today, 48)
+ end_date = new_date + timedelta(minutes=offset)
meetings.extend(Meeting.get_meeting_with_reminder(session,
new_date.date(), new_date.time(), end_date.time(), 'H-48'))
+
+ # Retrieve meeting planned in less than 168h
new_date = _generate_date_rounded_to_the_hour(today, 168)
+ end_date = new_date + timedelta(minutes=offset)
meetings.extend(Meeting.get_meeting_with_reminder(session,
new_date.date(), new_date.time(), end_date.time(), 'H-168'))
11 years, 5 months
[fedocal] master: When retrieving the meetings for a week, specify the calendar for all the meetings. (9b0c551)
by pingou@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/fedocal.git
On branch : master
>---------------------------------------------------------------
commit 9b0c55116425f055f1f58469d483fbb2cfebfa2e
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Mon Nov 26 21:33:45 2012 +0100
When retrieving the meetings for a week, specify the calendar for all the meetings.
>---------------------------------------------------------------
fedocal/fedocallib/week.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/fedocal/fedocallib/week.py b/fedocal/fedocallib/week.py
index 60b218a..2d24291 100644
--- a/fedocal/fedocallib/week.py
+++ b/fedocal/fedocallib/week.py
@@ -43,7 +43,7 @@ class Week(object):
self.start_date, self.stop_date)
for meeting in Meeting.get_active_regular_meeting(self.session,
- self.stop_date):
+ self.calendar, self.stop_date):
for delta in range(0, 7):
day = self.start_date + timedelta(days=delta)
if ((meeting.meeting_date - day).days %
11 years, 5 months
[fedocal] master: When retrieving the active regular meeting, we need to restrict them for a given calendar (34c8d46)
by pingou@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/fedocal.git
On branch : master
>---------------------------------------------------------------
commit 34c8d46daff330cba61af5ed389770953919475b
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Mon Nov 26 21:33:11 2012 +0100
When retrieving the active regular meeting, we need to restrict them for a given calendar
>---------------------------------------------------------------
fedocal/fedocallib/model.py | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/fedocal/fedocallib/model.py b/fedocal/fedocallib/model.py
index f942ca3..8f6b74a 100644
--- a/fedocal/fedocallib/model.py
+++ b/fedocal/fedocallib/model.py
@@ -277,7 +277,7 @@ class Meeting(BASE):
(Meeting.meeting_date < stop_date)).all()
@classmethod
- def get_active_regular_meeting(cls, session, end_date):
+ def get_active_regular_meeting(cls, session, calendar, end_date):
""" Retrieve the list of meetings with a recursion which
end_date is not past the provided end_date and starting before
the end of the time considered.
@@ -285,6 +285,7 @@ class Meeting(BASE):
meetings = session.query(cls).filter(and_
(Meeting.meeting_date <= end_date),
(Meeting.recursion_ends >= end_date),
+ (Meeting.calendar == calendar),
(Meeting.recursion_frequency != None)
).order_by(Meeting.meeting_date).all()
return meetings
11 years, 5 months
[fedocal] master: The CRON_FREQUENCY is an integer not a string (0c04702)
by pingou@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/fedocal.git
On branch : master
>---------------------------------------------------------------
commit 0c04702d1f7bf8b04c9849f3ada59fcf5247660d
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Mon Nov 26 21:35:12 2012 +0100
The CRON_FREQUENCY is an integer not a string
>---------------------------------------------------------------
fedocal.cfg.sample | 4 ++--
fedocal/default_config.py | 2 +-
fedocal_cron.py | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/fedocal.cfg.sample b/fedocal.cfg.sample
index cc22847..3747a02 100644
--- a/fedocal.cfg.sample
+++ b/fedocal.cfg.sample
@@ -19,5 +19,5 @@ SMTP_SERVER='localhost'
### The cron job can be set with any frequency but fedocal_cron needs
### this information to accurately retrieve the meetings to remind and
### avoid sending multiple reminders for a single meeting.
-### Default: '30'
-CRON_FREQUENCY='30'
+### Default: 30
+CRON_FREQUENCY=30
diff --git a/fedocal/default_config.py b/fedocal/default_config.py
index ffc30d1..55f306a 100644
--- a/fedocal/default_config.py
+++ b/fedocal/default_config.py
@@ -38,4 +38,4 @@ SMTP_SERVER = 'localhost'
# The cron job can be set with any frequency but fedocal_cron
-CRON_FREQUENCY='30'
+CRON_FREQUENCY=30
diff --git a/fedocal_cron.py b/fedocal_cron.py
index ea6945d..9370677 100644
--- a/fedocal_cron.py
+++ b/fedocal_cron.py
@@ -80,7 +80,7 @@ def send_reminder():
db_url = fedocal.APP.config['DB_URL']
session = fedocallib.create_session(db_url)
meetings = fedocallib.retrieve_meeting_to_remind(session,
- offset=fedocal.APP.config['CRON_FREQUENCY'])
+ offset=int(fedocal.APP.config['CRON_FREQUENCY']))
for meeting in meetings:
send_reminder_meeting(meeting)
11 years, 5 months
[fedocal] #19: Add to the configuration file option regarding to the frequency of the cron
by fedocal
#19: Add to the configuration file option regarding to the frequency of the cron
-------------------------+-------------------------
Reporter: pingou | Owner:
Type: enhancement | Status: new
Priority: major | Milestone: 0.1.0
Component: fedocal | Version: development
Keywords: |
-------------------------+-------------------------
To retrieve the list of meetings to send the reminder of, we use a time
period. However, the time interval changes according on the frequency set
for the cron job. We should make as configuration item the cron frequency
to be sure we retrieve the correct meetings.
--
Ticket URL: <https://fedorahosted.org/fedocal/ticket/19>
fedocal <https://fedorahosted.org/fedocal>
A web-based calendar application for Fedora
11 years, 5 months
[fedocal] master: Add a CRON_FREQUENCY item in the configuration file (f770bb8)
by pingou@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/fedocal.git
On branch : master
>---------------------------------------------------------------
commit f770bb89a693f6108c31298ab3057ec13f12761a
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Mon Nov 26 21:02:27 2012 +0100
Add a CRON_FREQUENCY item in the configuration file
We need to know at which frequency the cron job is set to retrieve the meetings to
remind correctly. This is now set in the configuration file.
Fixes #19
>---------------------------------------------------------------
doc/configuration.rst | 16 +++++++++++++++-
fedocal.cfg.sample | 6 ++++++
fedocal/default_config.py | 4 ++++
fedocal_cron.py | 3 ++-
4 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/doc/configuration.rst b/doc/configuration.rst
index ee4437c..63678bb 100644
--- a/doc/configuration.rst
+++ b/doc/configuration.rst
@@ -51,10 +51,24 @@ The SMTP server address
-----------------------
Fedocal sends reminder emails for the meeting for which it has been asked.
-This tasks is performed by an hourly cron job.
+This tasks is performed by a cron job.
The ``SMTP_SERVER`` field in the configuration file refers to the address
of the `SMTP <http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol>`
server to use to send these reminders.
This field defaults to ``SMTP_SERVER='localhost'``.
+
+
+The cron job frequency
+----------------------
+
+Fedocal sends reminder emails for the meeting for which it has been asked.
+This tasks is performed by a cron job.
+The ``CRON_FREQUENCY`` field in the configuration file refers to the
+time (in minute) spent between two consecutive run of the cron job. This
+information is essentiel to accurately retrieve the meetings to remind
+and avoid sending multiple reminder for one meeting.
+
+
+This field defaults to ``CRON_FREQUENCY='30'``.
diff --git a/fedocal.cfg.sample b/fedocal.cfg.sample
index 535ce59..cc22847 100644
--- a/fedocal.cfg.sample
+++ b/fedocal.cfg.sample
@@ -15,3 +15,9 @@ ADMIN_GROUP='fedocal_admin'
### via the cron job.
### Default: 'localhost'
SMTP_SERVER='localhost'
+
+### The cron job can be set with any frequency but fedocal_cron needs
+### this information to accurately retrieve the meetings to remind and
+### avoid sending multiple reminders for a single meeting.
+### Default: '30'
+CRON_FREQUENCY='30'
diff --git a/fedocal/default_config.py b/fedocal/default_config.py
index c225879..ffc30d1 100644
--- a/fedocal/default_config.py
+++ b/fedocal/default_config.py
@@ -35,3 +35,7 @@ ADMIN_GROUP = 'fedocal_admin'
# The address of the SMTP server used to send the reminders emails
# via the cron job.
SMTP_SERVER = 'localhost'
+
+
+# The cron job can be set with any frequency but fedocal_cron
+CRON_FREQUENCY='30'
diff --git a/fedocal_cron.py b/fedocal_cron.py
index 3c577e5..ea6945d 100644
--- a/fedocal_cron.py
+++ b/fedocal_cron.py
@@ -79,7 +79,8 @@ def send_reminder():
"""
db_url = fedocal.APP.config['DB_URL']
session = fedocallib.create_session(db_url)
- meetings = fedocallib.retrieve_meeting_to_remind(session)
+ meetings = fedocallib.retrieve_meeting_to_remind(session,
+ offset=fedocal.APP.config['CRON_FREQUENCY'])
for meeting in meetings:
send_reminder_meeting(meeting)
11 years, 5 months
[fedocal] master: Add information on how to set up the cron job (cef2f1a)
by pingou@fedorahosted.org
Repository : http://git.fedorahosted.org/cgit/fedocal.git
On branch : master
>---------------------------------------------------------------
commit cef2f1a49dd6546f840324faae4d00a6df076e7f
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Mon Nov 26 20:59:53 2012 +0100
Add information on how to set up the cron job
Fixes #20
>---------------------------------------------------------------
doc/deployment.rst | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/doc/deployment.rst b/doc/deployment.rst
index c73ea1a..511a5dc 100644
--- a/doc/deployment.rst
+++ b/doc/deployment.rst
@@ -101,6 +101,30 @@ http://localhost/fedocal
<http://flask.pocoo.org/docs/deploying/mod_wsgi/>`_.
+Set-up the cron job
+-------------------
+
+Reminders are sent by a cron job which is provided with the source under
+the name ``fedocal_cron.py``.
+
+You will need to specified the ``FEDOCAL_CONFIG`` environment variable
+when running the cron job as the specified configuration file contains
+information required by the cron job (ie: SMTP_SERVER or CRON_FREQUENCY,
+see :doc:`configuration`).
+
+The only tricky part is that the configuration file will need to be
+adjusted according to how the cron job is set-up. See :doc:`configuration`
+on how to set-up the configuration file.
+
+Example of the cron job:
+
+::
+
+ */30 * * * * FEDOCAL_CONFIG=/etc/fedocal.cfg python /path/to/fedocal_cron.py
+
+
+
+
For testing
-----------
11 years, 5 months
[fedocal] master: Add recursive meetings to the get_meeting_with_reminder functions (da7b4cc)
by Pierre-YvesChibon
Repository : http://git.fedorahosted.org/cgit/fedocal.git
On branch : master
>---------------------------------------------------------------
commit da7b4cc8423a2f37d9b76dbf295b07625c51c930
Author: Pierre-Yves Chibon <pingou(a)pingoured.fr>
Date: Mon Nov 26 20:40:51 2012 +0100
Add recursive meetings to the get_meeting_with_reminder functions
With the change in database design we were not considering recursive meetings when
retrieving meetings to remind. This commit takes care of it.
The unit-tests have been changed accordingly to check that we do retrieve a recursive
meeting in the 3 weeks following the first meeting.
>---------------------------------------------------------------
fedocal/fedocallib/model.py | 19 +++++++++++++++++-
fedocal/tests/test_meeting.py | 43 +++++++++++++++++++++++++++++++++++++++-
2 files changed, 59 insertions(+), 3 deletions(-)
diff --git a/fedocal/fedocallib/model.py b/fedocal/fedocallib/model.py
index 12f3e9c..f942ca3 100644
--- a/fedocal/fedocallib/model.py
+++ b/fedocal/fedocallib/model.py
@@ -19,6 +19,7 @@ import pkg_resources
from datetime import datetime
from datetime import date
+from datetime import timedelta
from sqlalchemy import (
Boolean,
@@ -372,11 +373,27 @@ class Meeting(BASE):
reminders = [int(item.reminder_id) for item in reminders]
if not reminders:
return []
- return session.query(cls).filter(and_
+ meetings = session.query(cls).filter(and_
(Meeting.meeting_date == start_date),
(Meeting.meeting_time_start >= start_time),
(Meeting.meeting_time_start < stop_time),
(Meeting.reminder_id.in_(reminders))).all()
+ # Add recursive meetings
+ recursive_meetings = session.query(cls).filter(and_
+ (Meeting.meeting_time_start >= start_time),
+ (Meeting.meeting_time_start < stop_time),
+ (Meeting.recursion_ends >= start_date),
+ (Meeting.reminder_id.in_(reminders))).all()
+ for meeting in recursive_meetings:
+ meeting_date = meeting.meeting_date
+ while meeting_date <= meeting.recursion_ends:
+ if meeting_date == start_date:
+ if meeting not in meetings:
+ meetings.append(meeting)
+ break
+ meeting_date = meeting_date + timedelta(
+ days=meeting.recursion_frequency)
+ return meetings
class Reminder(BASE):
diff --git a/fedocal/tests/test_meeting.py b/fedocal/tests/test_meeting.py
index 52763b9..82c3bfb 100644
--- a/fedocal/tests/test_meeting.py
+++ b/fedocal/tests/test_meeting.py
@@ -543,9 +543,18 @@ class Meetingtests(Modeltests):
def test_get_meeting_with_reminder(self):
""" Test the Meeting get_meeting_with_reminder function. """
self.test_init_meeting()
+ for delta in [0, 7, 14, 21]:
+ meetings = model.Meeting.get_meeting_with_reminder(self.session,
+ TODAY + timedelta(days=12 + delta), time(10, 00),
+ time(10, 30), 'H-12')
+ self.assertNotEqual(meetings, None)
+ self.assertEqual(len(meetings), 1)
+ self.assertEqual(meetings[0].meeting_name,
+ 'Test meeting with reminder and recursion')
+
meetings = model.Meeting.get_meeting_with_reminder(self.session,
- TODAY + timedelta(days=11), time(11, 00), time(11, 30),
- 'H-12')
+ TODAY + timedelta(days=11), time(11, 00),
+ time(11, 30), 'H-12')
self.assertNotEqual(meetings, None)
self.assertEqual(len(meetings), 1)
self.assertEqual(meetings[0].meeting_name,
@@ -577,6 +586,36 @@ class Meetingtests(Modeltests):
self.assertEqual(len(meetings), 0)
self.assertEqual(meetings, [])
+ meetings = model.Meeting.get_meeting_with_reminder(self.session,
+ TODAY + timedelta(days=11), time(10, 30), time(11, 00),
+ 'H-12')
+ self.assertNotEqual(meetings, None)
+ self.assertEqual(len(meetings), 0)
+ self.assertEqual(meetings, [])
+
+ meetings = model.Meeting.get_meeting_with_reminder(self.session,
+ TODAY + timedelta(days=11), time(11, 30), time(12, 00),
+ 'H-12')
+ self.assertNotEqual(meetings, None)
+ self.assertEqual(len(meetings), 0)
+ self.assertEqual(meetings, [])
+
+ for delta in [0, 7, 14, 21]:
+ meetings = model.Meeting.get_meeting_with_reminder(self.session,
+ TODAY + timedelta(days=12 + delta), time(9, 30),
+ time(10, 00), 'H-12')
+ self.assertNotEqual(meetings, None)
+ self.assertEqual(len(meetings), 0)
+ self.assertEqual(meetings, [])
+
+ meetings = model.Meeting.get_meeting_with_reminder(self.session,
+ TODAY + timedelta(days=12 + delta), time(10, 30),
+ time(11, 00), 'H-12')
+ self.assertNotEqual(meetings, None)
+ self.assertEqual(len(meetings), 0)
+ self.assertEqual(meetings, [])
+
+
if __name__ == '__main__':
SUITE = unittest.TestLoader().loadTestsFromTestCase(Meetingtests)
unittest.TextTestRunner(verbosity=2).run(SUITE)
11 years, 5 months