def setAclRule(self, rule=None, role='read', scope_type='default', scope_value=None): """ Set the role for a rule. If no rule is specified a new rule will be created with the provides scope_type / scope_type. """ gcal = self.gCalendar if not gcal: return None aclink = gcal.GetAclLink() newRole = gdata.calendar.Role(value=to_role_uri(role)) if rule is None: # add the entry rule = gdata.calendar.CalendarAclEntry() rule.scope = gdata.calendar.Scope() rule.scope.type = scope_type if scope_value: rule.scope.value = scope_value rule.role = newRole return with_request_error_try(lambda: self.account.service.InsertAclEntry(rule, aclink.href)) else: # update the entry rule.role = newRole return with_request_error_try(lambda: self.account.service.UpdateAclEntry(rule.GetEditLink().href, rule))
def save(self): gcal = self.gCalendar if gcal: # existing calendar update new = False else: new = True gcal = gdata.calendar.CalendarListEntry() gcal.title = atom.Title(text=self.title) gcal.summary = atom.Summary(text=self.summary) if self.where: gcal.where = gdata.calendar.Where(value_string=self.where) elif gcal.where and gcal.where.text: self.where = gcal.where.text if self.color: gcal.color = gdata.calendar.Color(value=self.color) elif gcal.color and gcal.color.value: self.color = gcal.color.value if self.timezone: gcal.timezone = gdata.calendar.Timezone(value=self.timezone) elif gcal.timezone and gcal.timezone.value: self.timezone = gcal.timezone.value if new: new_gcal = with_request_error_try(lambda: self.account.service.InsertCalendar(new_calendar=gcal)) # gooogle replaces the title with the (email address) style Calendar Id #self.calendar_id = new_gcal.title.text new_gcal.title = atom.Title(text=self.title) new_gcal = self.account.service.UpdateCalendar(calendar=new_gcal) self.uri = new_gcal.id.text for link in new_gcal.link: if link.rel == 'alternate': self.feed_uri = link.href break else: new_gcal = with_request_error_try(lambda: self.account.service.UpdateCalendar(calendar=gcal)) m = re_cal_id.match(self.uri) if m: self.calendar_id = urllib.unquote(m.group(1)) # ACL model rule = self.getAclRule('default') if not self.default_share: # Not sharing if rule is not None: # remove the rule with_request_error_try(lambda: self.account.service.DeleteAclEntry(rule.GetEditLink().href)) else: if rule is None: # new rule self.setAclRule(role=self.default_share, scope_type='default') elif to_role_uri(self.default_share) != rule.role.value: # role change self.setAclRule(rule=rule, role=self.default_share) super(Calendar, self).save()