1.1 --- a/imip_store.py Sun Sep 06 01:06:28 2015 +0200
1.2 +++ b/imip_store.py Sun Sep 06 01:15:30 2015 +0200
1.3 @@ -201,17 +201,21 @@
1.4
1.5 return all_events
1.6
1.7 - def get_active_events(self, user):
1.8 + def get_event_filename(self, user, uid, recurrenceid=None, dirname=None):
1.9
1.10 - "Return a set of uncancelled events of the form (uid, recurrenceid)."
1.11 -
1.12 - all_events = self.get_all_events(user)
1.13 + """
1.14 + Get the filename providing the event for the given 'user' with the given
1.15 + 'uid'. If the optional 'recurrenceid' is specified, a specific instance
1.16 + or occurrence of an event is returned.
1.17
1.18 - # Filter out cancelled events.
1.19 + Where 'dirname' is specified, the given directory name is used as the
1.20 + base of the location within which any filename will reside.
1.21 + """
1.22
1.23 - cancelled = self.get_cancellations(user) or []
1.24 - all_events.difference_update(cancelled)
1.25 - return all_events
1.26 + if recurrenceid:
1.27 + return self.get_recurrence_filename(user, uid, recurrenceid, dirname)
1.28 + else:
1.29 + return self.get_complete_event_filename(user, uid, dirname)
1.30
1.31 def get_event(self, user, uid, recurrenceid=None):
1.32
1.33 @@ -221,20 +225,33 @@
1.34 occurrence of an event is returned.
1.35 """
1.36
1.37 - if recurrenceid:
1.38 - return self.get_recurrence(user, uid, recurrenceid)
1.39 - else:
1.40 - return self.get_complete_event(user, uid)
1.41 + filename = self.get_event_filename(user, uid, recurrenceid)
1.42 + if not filename or not exists(filename):
1.43 + return None
1.44 +
1.45 + return filename and self._get_object(user, filename)
1.46 +
1.47 + def get_complete_event_filename(self, user, uid, dirname=None):
1.48 +
1.49 + """
1.50 + Get the filename providing the event for the given 'user' with the given
1.51 + 'uid'.
1.52 +
1.53 + Where 'dirname' is specified, the given directory name is used as the
1.54 + base of the location within which any filename will reside.
1.55 + """
1.56 +
1.57 + return self.get_object_in_store(user, dirname, "objects", uid)
1.58
1.59 def get_complete_event(self, user, uid):
1.60
1.61 "Get the event for the given 'user' with the given 'uid'."
1.62
1.63 - filename = self.get_object_in_store(user, "objects", uid)
1.64 + filename = self.get_complete_event_filename(user, uid)
1.65 if not filename or not exists(filename):
1.66 return None
1.67
1.68 - return self._get_object(user, filename)
1.69 + return filename and self._get_object(user, filename)
1.70
1.71 def set_event(self, user, uid, recurrenceid, node):
1.72
1.73 @@ -290,7 +307,16 @@
1.74
1.75 """
1.76 Get additional event instances for an event of the given 'user' with the
1.77 - indicated 'uid'.
1.78 + indicated 'uid'. Both active and cancelled recurrences are returned.
1.79 + """
1.80 +
1.81 + return self.get_active_recurrences(user, uid) + self.get_cancelled_recurrences(user, uid)
1.82 +
1.83 + def get_active_recurrences(self, user, uid):
1.84 +
1.85 + """
1.86 + Get additional event instances for an event of the given 'user' with the
1.87 + indicated 'uid'. Cancelled recurrences are not returned.
1.88 """
1.89
1.90 filename = self.get_object_in_store(user, "recurrences", uid)
1.91 @@ -299,6 +325,31 @@
1.92
1.93 return [name for name in listdir(filename) if isfile(join(filename, name))]
1.94
1.95 + def get_cancelled_recurrences(self, user, uid):
1.96 +
1.97 + """
1.98 + Get additional event instances for an event of the given 'user' with the
1.99 + indicated 'uid'. Only cancelled recurrences are returned.
1.100 + """
1.101 +
1.102 + filename = self.get_object_in_store(user, "cancelled", "recurrences", uid)
1.103 + if not filename or not exists(filename):
1.104 + return []
1.105 +
1.106 + return [name for name in listdir(filename) if isfile(join(filename, name))]
1.107 +
1.108 + def get_recurrence_filename(self, user, uid, recurrenceid, dirname=None):
1.109 +
1.110 + """
1.111 + For the event of the given 'user' with the given 'uid', return the
1.112 + filename providing the recurrence with the given 'recurrenceid'.
1.113 +
1.114 + Where 'dirname' is specified, the given directory name is used as the
1.115 + base of the location within which any filename will reside.
1.116 + """
1.117 +
1.118 + return self.get_object_in_store(user, dirname, "recurrences", uid, recurrenceid)
1.119 +
1.120 def get_recurrence(self, user, uid, recurrenceid):
1.121
1.122 """
1.123 @@ -306,11 +357,11 @@
1.124 specific recurrence indicated by the 'recurrenceid'.
1.125 """
1.126
1.127 - filename = self.get_object_in_store(user, "recurrences", uid, recurrenceid)
1.128 + filename = self.get_recurrence_filename(user, uid, recurrenceid)
1.129 if not filename or not exists(filename):
1.130 return None
1.131
1.132 - return self._get_object(user, filename)
1.133 + return filename and self._get_object(user, filename)
1.134
1.135 def set_recurrence(self, user, uid, recurrenceid, node):
1.136
1.137 @@ -526,12 +577,6 @@
1.138
1.139 return self._get_requests(user, "requests")
1.140
1.141 - def get_cancellations(self, user):
1.142 -
1.143 - "Get cancellations for the given 'user'."
1.144 -
1.145 - return self._get_requests(user, "cancellations")
1.146 -
1.147 def _set_requests(self, user, requests, queue):
1.148
1.149 """
1.150 @@ -563,12 +608,6 @@
1.151
1.152 return self._set_requests(user, requests, "requests")
1.153
1.154 - def set_cancellations(self, user, cancellations):
1.155 -
1.156 - "For the given 'user', set the list of queued 'cancellations'."
1.157 -
1.158 - return self._set_requests(user, cancellations, "cancellations")
1.159 -
1.160 def _set_request(self, user, uid, recurrenceid, queue):
1.161
1.162 """
1.163 @@ -599,12 +638,6 @@
1.164
1.165 return self._set_request(user, uid, recurrenceid, "requests")
1.166
1.167 - def set_cancellation(self, user, uid, recurrenceid=None):
1.168 -
1.169 - "For the given 'user', set the queued 'uid' and 'recurrenceid'."
1.170 -
1.171 - return self._set_request(user, uid, recurrenceid, "cancellations")
1.172 -
1.173 def queue_request(self, user, uid, recurrenceid=None):
1.174
1.175 """
1.176 @@ -641,15 +674,16 @@
1.177 def cancel_event(self, user, uid, recurrenceid=None):
1.178
1.179 """
1.180 - Queue an event for cancellation for 'user' having the given 'uid'. If
1.181 - the optional 'recurrenceid' is specified, a specific instance or
1.182 - occurrence of an event is cancelled.
1.183 + Cancel an event for 'user' having the given 'uid'. If the optional
1.184 + 'recurrenceid' is specified, a specific instance or occurrence of an
1.185 + event is cancelled.
1.186 """
1.187
1.188 - cancellations = self.get_cancellations(user) or []
1.189 + filename = self.get_event_filename(user, uid, recurrenceid)
1.190 + cancelled_filename = self.get_event_filename(user, uid, recurrenceid, "cancellations")
1.191
1.192 - if (uid, recurrenceid) not in cancellations:
1.193 - return self.set_cancellation(user, uid, recurrenceid)
1.194 + if filename and cancelled_filename and exists(filename):
1.195 + return self.move_object(filename, cancelled_filename)
1.196
1.197 return False
1.198