DELETE requests can delete calendars (closes #514)
This commit is contained in:
parent
bfe527dd41
commit
1f2f39a87a
@ -267,8 +267,15 @@ class Application(object):
|
|||||||
def delete(self, environ, calendars, content, user):
|
def delete(self, environ, calendars, content, user):
|
||||||
"""Manage DELETE request."""
|
"""Manage DELETE request."""
|
||||||
calendar = calendars[0]
|
calendar = calendars[0]
|
||||||
|
|
||||||
|
if calendar.local_path == environ["PATH_INFO"].strip("/"):
|
||||||
|
# Path matching the calendar, the item to delete is the calendar
|
||||||
|
item = calendar
|
||||||
|
else:
|
||||||
|
# Try to get an item matching the path
|
||||||
item = calendar.get_item(
|
item = calendar.get_item(
|
||||||
xmlutils.name_from_path(environ["PATH_INFO"], calendar))
|
xmlutils.name_from_path(environ["PATH_INFO"], calendar))
|
||||||
|
|
||||||
if item and environ.get("HTTP_IF_MATCH", item.etag) == item.etag:
|
if item and environ.get("HTTP_IF_MATCH", item.etag) == item.etag:
|
||||||
# No ETag precondition or precondition verified, delete item
|
# No ETag precondition or precondition verified, delete item
|
||||||
answer = xmlutils.delete(environ["PATH_INFO"], calendar)
|
answer = xmlutils.delete(environ["PATH_INFO"], calendar)
|
||||||
|
@ -172,6 +172,7 @@ class Calendar(object):
|
|||||||
self.encoding = "utf-8"
|
self.encoding = "utf-8"
|
||||||
split_path = path.split("/")
|
split_path = path.split("/")
|
||||||
self.path = os.path.join(FOLDER, path.replace("/", os.sep))
|
self.path = os.path.join(FOLDER, path.replace("/", os.sep))
|
||||||
|
self.props_path = self.path + '.props'
|
||||||
if principal and split_path and os.path.isdir(self.path):
|
if principal and split_path and os.path.isdir(self.path):
|
||||||
# Already existing principal calendar
|
# Already existing principal calendar
|
||||||
self.owner = split_path[0]
|
self.owner = split_path[0]
|
||||||
@ -300,6 +301,11 @@ class Calendar(object):
|
|||||||
|
|
||||||
self.write(items=items)
|
self.write(items=items)
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
"""Delete the calendar."""
|
||||||
|
os.remove(self.path)
|
||||||
|
os.remove(self.props_path)
|
||||||
|
|
||||||
def remove(self, name):
|
def remove(self, name):
|
||||||
"""Remove object named ``name`` from calendar."""
|
"""Remove object named ``name`` from calendar."""
|
||||||
components = [
|
components = [
|
||||||
@ -415,16 +421,15 @@ class Calendar(object):
|
|||||||
@contextmanager
|
@contextmanager
|
||||||
def props(self):
|
def props(self):
|
||||||
"""Get the calendar properties."""
|
"""Get the calendar properties."""
|
||||||
props_path = self.path + '.props'
|
|
||||||
# On enter
|
# On enter
|
||||||
properties = {}
|
properties = {}
|
||||||
if os.path.exists(props_path):
|
if os.path.exists(self.props_path):
|
||||||
with open(props_path) as prop_file:
|
with open(self.props_path) as prop_file:
|
||||||
properties.update(json.load(prop_file))
|
properties.update(json.load(prop_file))
|
||||||
yield properties
|
yield properties
|
||||||
# On exit
|
# On exit
|
||||||
self._create_dirs(props_path)
|
self._create_dirs(self.props_path)
|
||||||
with open(props_path, 'w') as prop_file:
|
with open(self.props_path, 'w') as prop_file:
|
||||||
json.dump(properties, prop_file)
|
json.dump(properties, prop_file)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -153,6 +153,11 @@ def delete(path, calendar):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
# Reading request
|
# Reading request
|
||||||
|
if calendar.local_path == path.strip("/"):
|
||||||
|
# Delete the whole calendar
|
||||||
|
calendar.delete()
|
||||||
|
else:
|
||||||
|
# Remove an item from the calendar
|
||||||
calendar.remove(name_from_path(path, calendar))
|
calendar.remove(name_from_path(path, calendar))
|
||||||
|
|
||||||
# Writing answer
|
# Writing answer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user