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): class Calendar(object):
"""Internal calendar class.""" """Internal calendar class."""
tag = "VCALENDAR"
def __init__(self, path): def __init__(self, path):
"""Initialize the calendar with ``cal`` and ``user`` parameters.""" """Initialize the calendar with ``cal`` and ``user`` parameters."""
# TODO: Use properties from the calendar configuration # TODO: Use properties from the calendar configuration

View File

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