Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Work on mutable records.

  • Loading branch information
wsanchez committed Feb 11, 2013
1 parent f318eaa commit 783c22e97d2f702161d742beef13c359548f0748
Showing with 82 additions and 4 deletions.
  1. +22 −0 twext/who/directory.py
  2. +19 −3 twext/who/test/test_xml.py
  3. +41 −1 twext/who/xml.py
@@ -192,6 +192,28 @@ def __getattr__(self, name):
raise AttributeError(name)


def description(self):
description = [self.__class__.__name__, ":"]

for name, value in self.fields.items():
if hasattr(name, "description"):
name = name.description
else:
name = str(name)

if hasattr(value, "description"):
value = value.description
else:
value = str(value)

description.append("\n ")
description.append(name)
description.append(" = ")
description.append(value)

return "".join(description)


def members(self):
if self.recordType == RecordType.group:
raise NotImplementedError()
@@ -280,14 +280,30 @@ def test_updateRecord(self):

# Verify change is present immediately
record = (yield service.recordWithUID("__wsanchez__"))
self.assertEquals(record.fullName, "Wilfredo Sanchez Vega")
self.assertEquals(set(record.fullNames), set(("Wilfredo Sanchez Vega",)))

# Verify change is persisted
service.flush()
record = (yield service.recordWithUID("__wsanchez__"))
self.assertEquals(record.fullName, "Wilfredo Sanchez Vega")
self.assertEquals(set(record.fullNames), set(("Wilfredo Sanchez Vega",)))

test_updateRecord.todo = "Not implemented."

@inlineCallbacks
def test_addRecord(self):
service = self._testService()

raise NotImplementedError()

test_addRecord.todo = "Not implemented."


@inlineCallbacks
def test_addRecordNo(self):
service = self._testService()

raise NotImplementedError()

test_addRecord.todo = "Not implemented."



@@ -29,6 +29,8 @@

from xml.etree.ElementTree import parse as parseXML
from xml.etree.ElementTree import ParseError as XMLParseError
from xml.etree.ElementTree import tostring as etreeToString
from xml.etree.ElementTree import Element as XMLElement

from twisted.python.constants import Names, NamedConstant, Values, ValueConstant
from twisted.internet.defer import succeed, inlineCallbacks, returnValue
@@ -408,7 +410,45 @@ def updateRecords(self, records, create=False):
record = recordsByUID.get(uidNode.text, None)

if record:
raise NotImplementedError("Update record: %s" % (record,))
recordNode.clear()

for (name, value) in record.fields.items():
if name == self.fieldName.recordType:
# FIXME: This lookup of the record type value is a bit much to do in a loop
for valueName in self.value.iterconstants():
if getattr(valueName, "recordType", None) == value:
recordNode.set(self.attribute.recordType.value, valueName.value)
break
else:
raise AssertionError("Unknown record type: %r" % (value,))
else:
# FIXME: This lookup of the field name element is a bit much to do in a loop
for elementName in self.element.iterconstants():
if getattr(elementName, "fieldName", None) == name:
if self.fieldName.isMultiValue(name):
values = value
else:
values = (value,)

for value in values:
subNode = XMLElement(tag=elementName.value)
subNode.text = value
recordNode.append(subNode)

break
else:
raise AssertionError("Unknown field name: %r" % (name,))

del recordsByUID[record.uid]

if recordsByUID:
if not create:
raise NotImplementedError("Raise something.")

raise NotImplementedError("Add new records.")

self.filePath.setContent(etreeToString(directoryNode))
self.flush()



0 comments on commit 783c22e

Please sign in to comment.
You can’t perform that action at this time.