Clean the ical API
This commit is contained in:
@ -139,12 +139,7 @@ class Collection(ical.Collection):
|
||||
"""Collection's object mapped to the table line."""
|
||||
return self.session.query(DBCollection).get(self.path)
|
||||
|
||||
def write(self, headers=None, items=None):
|
||||
headers = headers or self.headers or (
|
||||
ical.Header("PRODID:-//Radicale//NONSGML Radicale Server//EN"),
|
||||
ical.Header("VERSION:%s" % self.version))
|
||||
items = items if items is not None else self.items
|
||||
|
||||
def write(self):
|
||||
if self._db_collection:
|
||||
for item in self._db_collection.items:
|
||||
for line in item.lines:
|
||||
@ -158,13 +153,13 @@ class Collection(ical.Collection):
|
||||
db_collection.parent_path = "/".join(self.path.split("/")[:-1])
|
||||
self.session.add(db_collection)
|
||||
|
||||
for header in headers:
|
||||
for header in self.headers:
|
||||
db_header = DBHeader()
|
||||
db_header.name, db_header.value = header.text.split(":", 1)
|
||||
db_header.collection_path = self.path
|
||||
self.session.add(db_header)
|
||||
|
||||
for item in items:
|
||||
for item in self.items.values():
|
||||
db_item = DBItem()
|
||||
db_item.name = item.name
|
||||
db_item.tag = item.tag
|
||||
@ -258,11 +253,6 @@ class Collection(ical.Collection):
|
||||
prop.collection_path = self.path
|
||||
self.session.add(prop)
|
||||
|
||||
@property
|
||||
def items(self):
|
||||
return self._query(
|
||||
(ical.Event, ical.Todo, ical.Journal, ical.Card, ical.Timezone))
|
||||
|
||||
@property
|
||||
def components(self):
|
||||
return self._query((ical.Event, ical.Todo, ical.Journal, ical.Card))
|
||||
|
@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# This file is part of Radicale Server - Calendar Server
|
||||
# Copyright © 2012-2013 Guillaume Ayoub
|
||||
# Copyright © 2012-2015 Guillaume Ayoub
|
||||
#
|
||||
# This library is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -1,8 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# This file is part of Radicale Server - Calendar Server
|
||||
# Copyright © 2013 Guillaume Ayoub
|
||||
# Copyright © 2013 Jean-Marc Martins
|
||||
# Copyright © 2014 Jean-Marc Martins
|
||||
# Copyright © 2014-2015 Guillaume Ayoub
|
||||
#
|
||||
# This library is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -43,14 +43,11 @@ class Collection(filesystem.Collection):
|
||||
ical.Header("PRODID:-//Radicale//NONSGML Radicale Server//EN"),
|
||||
ical.Header("VERSION:%s" % self.version))
|
||||
|
||||
def write(self, headers=None, items=None):
|
||||
def write(self):
|
||||
self._create_dirs()
|
||||
headers = headers or self.headers
|
||||
items = items if items is not None else self.items
|
||||
timezones = list(set(i for i in items if isinstance(i, ical.Timezone)))
|
||||
components = [i for i in items if isinstance(i, ical.Component)]
|
||||
for component in components:
|
||||
text = ical.serialize(self.tag, headers, [component] + timezones)
|
||||
for component in self.components:
|
||||
text = ical.serialize(
|
||||
self.tag, self.headers, [component] + self.timezones)
|
||||
name = (
|
||||
component.name if sys.version_info[0] >= 3 else
|
||||
component.name.encode(filesystem.FILESYSTEM_ENCODING))
|
||||
|
Reference in New Issue
Block a user