Fix the PROPFIND request management (list events and todos)

This commit is contained in:
Guillaume Ayoub 2010-09-28 16:32:47 +02:00
parent 040b125377
commit 076b6b60a4
2 changed files with 51 additions and 35 deletions

View File

@ -131,6 +131,8 @@ class Timezone(Item):
class Calendar(object):
"""Internal calendar class."""
tag = "VCALENDAR"
def __init__(self, path):
"""Initialize the calendar with ``cal`` and ``user`` parameters."""
# TODO: Use properties from the calendar configuration

View File

@ -95,11 +95,15 @@ def propfind(path, xml_request, calendar, request):
# Writing answer
multistatus = ET.Element(_tag("D", "multistatus"))
for item in (calendar,) + tuple(calendar.events) + tuple(calendar.todos):
response = ET.Element(_tag("D", "response"))
multistatus.append(response)
href = ET.Element(_tag("D", "href"))
if item.tag == "VCALENDAR":
href.text = path
else:
href.text = "%s/%s" % (path.rstrip("/"), item.name)
response.append(href)
propstat = ET.Element(_tag("D", "propstat"))
@ -110,27 +114,34 @@ def propfind(path, xml_request, calendar, request):
for tag in props:
element = ET.Element(tag)
if tag == _tag("D", "resourcetype"):
element.append(ET.Element(_tag("C", "calendar")))
if item.tag == "VCALENDAR":
# Item is a calendar
tag = ET.Element(_tag("C", "calendar"))
else:
# Item is an event or a todo
tag = ET.Element(_tag("C", "comp"))
tag.set("name", item.tag)
element.append(tag)
elif tag == _tag("D", "owner"):
element.text = calendar.owner
elif tag == _tag("D", "getcontenttype"):
element.text = "text/calendar"
elif tag == _tag("D", "getetag"):
element.text = calendar.etag
element.text = item.etag
elif tag == _tag("D", "displayname"):
element.text = calendar.name
elif tag == _tag("D", "supported-report-set"):
supported_report = ET.Element(_tag("D", "supported-report"))
report = ET.Element(_tag("D", "report"))
report.append(ET.Element(_tag("C", "calendar-multiget")))
supported_report.append(report)
report_set = ET.Element(_tag("D", "report"))
report_set.append(ET.Element(_tag("C", "calendar-multiget")))
supported_report.append(report_set)
element.append(supported_report)
elif tag == _tag("D", "principal-URL"):
# TODO: use a real principal URL, read rfc3744-4.2 for info
element.text = "%s://%s%s" % (
request.server.PROTOCOL, request.headers["Host"], request.path)
request.server.PROTOCOL, request.headers["Host"],
request.path)
prop.append(element)
@ -138,6 +149,9 @@ def propfind(path, xml_request, calendar, request):
status.text = _response(200)
propstat.append(status)
# Add calendar to answers
multistatus.append(response)
return ET.tostring(multistatus, config.get("encoding", "request"))