1.1 --- a/imip_store.py Sat Sep 19 01:08:17 2015 +0200
1.2 +++ b/imip_store.py Thu Sep 24 19:13:39 2015 +0200
1.3 @@ -233,7 +233,7 @@
1.4
1.5 return all_events
1.6
1.7 - def get_event_filename(self, user, uid, recurrenceid=None, dirname=None):
1.8 + def get_event_filename(self, user, uid, recurrenceid=None, dirname=None, username=None):
1.9
1.10 """
1.11 Get the filename providing the event for the given 'user' with the given
1.12 @@ -245,9 +245,9 @@
1.13 """
1.14
1.15 if recurrenceid:
1.16 - return self.get_recurrence_filename(user, uid, recurrenceid, dirname)
1.17 + return self.get_recurrence_filename(user, uid, recurrenceid, dirname, username)
1.18 else:
1.19 - return self.get_complete_event_filename(user, uid, dirname)
1.20 + return self.get_complete_event_filename(user, uid, dirname, username)
1.21
1.22 def get_event(self, user, uid, recurrenceid=None):
1.23
1.24 @@ -263,7 +263,7 @@
1.25
1.26 return filename and self._get_object(user, filename)
1.27
1.28 - def get_complete_event_filename(self, user, uid, dirname=None):
1.29 + def get_complete_event_filename(self, user, uid, dirname=None, username=None):
1.30
1.31 """
1.32 Get the filename providing the event for the given 'user' with the given
1.33 @@ -271,9 +271,12 @@
1.34
1.35 Where 'dirname' is specified, the given directory name is used as the
1.36 base of the location within which any filename will reside.
1.37 +
1.38 + Where 'username' is specified, the event details will reside in a file
1.39 + bearing that name within a directory having 'uid' as its name.
1.40 """
1.41
1.42 - return self.get_object_in_store(user, dirname, "objects", uid)
1.43 + return self.get_object_in_store(user, dirname, "objects", uid, username)
1.44
1.45 def get_complete_event(self, user, uid):
1.46
1.47 @@ -370,7 +373,7 @@
1.48
1.49 return [name for name in listdir(filename) if isfile(join(filename, name))]
1.50
1.51 - def get_recurrence_filename(self, user, uid, recurrenceid, dirname=None):
1.52 + def get_recurrence_filename(self, user, uid, recurrenceid, dirname=None, username=None):
1.53
1.54 """
1.55 For the event of the given 'user' with the given 'uid', return the
1.56 @@ -378,9 +381,12 @@
1.57
1.58 Where 'dirname' is specified, the given directory name is used as the
1.59 base of the location within which any filename will reside.
1.60 +
1.61 + Where 'username' is specified, the event details will reside in a file
1.62 + bearing that name within a directory having 'uid' as its name.
1.63 """
1.64
1.65 - return self.get_object_in_store(user, dirname, "recurrences", uid, recurrenceid)
1.66 + return self.get_object_in_store(user, dirname, "recurrences", uid, recurrenceid, username)
1.67
1.68 def get_recurrence(self, user, uid, recurrenceid):
1.69
1.70 @@ -733,7 +739,7 @@
1.71
1.72 type = request[2]
1.73 if type == "COUNTER":
1.74 - self.remove_counter(user, uid, recurrenceid)
1.75 + self.remove_counters(user, uid, recurrenceid)
1.76
1.77 else:
1.78 result.append(request)
1.79 @@ -755,40 +761,80 @@
1.80 return True
1.81 return False
1.82
1.83 - def get_counter(self, user, uid, recurrenceid=None):
1.84 + def get_counters(self, user, uid, recurrenceid=None):
1.85
1.86 """
1.87 - For the given 'user', return the counter-proposal for the given 'uid'
1.88 - and optional 'recurrenceid'.
1.89 + For the given 'user', return a mapping of counter-proposals from other
1.90 + users to nodes representing those proposals for the given 'uid' and
1.91 + optional 'recurrenceid'.
1.92 """
1.93
1.94 filename = self.get_event_filename(user, uid, recurrenceid, "counters")
1.95 if not filename:
1.96 return False
1.97
1.98 - return filename and self._get_object(user, filename)
1.99 + counters = {}
1.100
1.101 - def set_counter(self, user, node, uid, recurrenceid=None):
1.102 + for other in listdir(filename):
1.103 + counter_filename = self.get_event_filename(user, uid, recurrenceid, "counters", other)
1.104 + counters[other] = self._get_object(user, counter_filename)
1.105 +
1.106 + return counters
1.107 +
1.108 + def get_counter(self, user, other, uid, recurrenceid=None):
1.109
1.110 """
1.111 - For the given 'user', store the given 'node' for the given 'uid' and
1.112 - 'recurrenceid' as a counter-proposal.
1.113 + For the given 'user', return the counter-proposal from 'other' for the
1.114 + given 'uid' and optional 'recurrenceid'.
1.115 + """
1.116 +
1.117 + filename = self.get_event_filename(user, uid, recurrenceid, "counters", other)
1.118 + if not filename:
1.119 + return False
1.120 +
1.121 + return self._get_object(user, filename)
1.122 +
1.123 + def set_counter(self, user, other, node, uid, recurrenceid=None):
1.124 +
1.125 + """
1.126 + For the given 'user', store a counter-proposal received from 'other' the
1.127 + given 'node' representing that proposal for the given 'uid' and
1.128 + 'recurrenceid'.
1.129 + """
1.130 +
1.131 + filename = self.get_event_filename(user, uid, recurrenceid, "counters", other)
1.132 + if not filename:
1.133 + return False
1.134 +
1.135 + return self._set_object(user, filename, node)
1.136 +
1.137 + def remove_counters(self, user, uid, recurrenceid=None):
1.138 +
1.139 + """
1.140 + For the given 'user', remove all counter-proposals associated with the
1.141 + given 'uid' and 'recurrenceid'.
1.142 """
1.143
1.144 filename = self.get_event_filename(user, uid, recurrenceid, "counters")
1.145 if not filename:
1.146 return False
1.147
1.148 - return self._set_object(user, filename, node)
1.149 + removed = False
1.150
1.151 - def remove_counter(self, user, uid, recurrenceid=None):
1.152 + for other in listdir(filename):
1.153 + counter_filename = self.get_event_filename(user, uid, recurrenceid, "counters", other)
1.154 + removed = removed or self._remove_object(counter_filename)
1.155 +
1.156 + return removed
1.157 +
1.158 + def remove_counter(self, user, other, uid, recurrenceid=None):
1.159
1.160 """
1.161 - For the given 'user', remove any counter-proposal associated with the
1.162 - given 'uid' and 'recurrenceid'.
1.163 + For the given 'user', remove any counter-proposal from 'other'
1.164 + associated with the given 'uid' and 'recurrenceid'.
1.165 """
1.166
1.167 - filename = self.get_event_filename(user, uid, recurrenceid, "counters")
1.168 + filename = self.get_event_filename(user, uid, recurrenceid, "counters", other)
1.169 if not filename:
1.170 return False
1.171