Type Management

Understanding Type Conversion

Text here listing how it works

fborm.types Module Documentation

fborm.types.fbint(data)[source]

Type converter for API integer values.

fbBug = dict(
    ixBug = fborm.types.fbint,
)

See `typemapping`_ for more information on the type maps framework.

Some integer fields can be empty, and have special meaning when that happens. Here we retun 0 when no data is present as a catchall. In some API calls the number 1 is reserverd with special meaning, or can be valid. The ixPerson 1 means CLOSED and is not assiciated with a person. While on an Area ixPersonPrimaryContact is set to -1 to denote that the primary contact should be used. However there is a discrepency between some API calls where the list version of a call will return an empty string instead of -1. Because this is API call specific, we turn all empty strings into 0 for integer fields. Clients need to be aware of these discrepencies. This should generalize to ixPersonField > 1 for evaluating of a field has a valid user id.

fborm.types.fbfloat(data)[source]
fborm.types.fbbool(data)[source]
fborm.types.fbstring(data)[source]
fborm.types.fbdatetime(data)[source]

Type converter for API datetime values.

Will return a full python datetime.datetime object for an API datetime value. The ORM will map these values back to strings conforming to the FogBugz API. This allows for rich datetime evaluation, comparison and modification.

fborm.types.fblistof(fbtype)[source]
fborm.types.fbcommalistof(fbtype)[source]
fborm.types.fbcol(fbtype, colname=None, resname=None, attrib=False, gettable=True, settable=True, setname=None, setter=None)[source]
fborm.types.fbconditional(converter, **conditions)[source]
fborm.types.fbminievents(eventdict)[source]
fborm.types.fbevents(eventdict)[source]
fborm.types.fblatestevent(eventdict)[source]
fborm.types.fbattr(fbtype)[source]
fborm.types.fbself = <functools.partial object at 0x100684838>

Special element converter which will convert the parent XML element as a string. This is needed for when the FogBugz API does not break the data into sub-taged elements, but instead has only a single piece of string data in the object, and the remaining data is encoded in attributes on the parent element. See fborm.objects.fbFilter for an example of this.

fborm.types.fbtags = <functools.partial object at 0x1006848e8>

fborm.types.fbcol (fborm.types.fblistof (fborm.types.fbstring), colname=’tags’, resname=’tags’, setname=’sTags’, setter= fborm.parse.fbsetconvert)

fbtags = fborm.types.fbcol(
    fborm.types.fblistof(fborm.types.fbstring),
    colname='tags',
    resname='tags',
    setname='sTags',
    setter=fborm.parse.fbsetconvert)
fborm.types.fbixBugChildren = <functools.partial object at 0x100684998>

fborm.types.fbcol (fborm.types.fbcommalistof (fborm.types.fbint), colname=’ixBugChildren’, setname=’ixBugChildren’, setter=lambda x: fborm.parse.fbsetconvert (x) if x else ‘ ‘)

fbixBugChildren = fborm.types.fbcol(
    fborm.types.fbcommalistof(fborm.types.fbint),
    colname='ixBugChildren',
    setname='ixBugChildren',
    setter=lambda x: fborm.parse.fbsetconvert(x) if x else ' ')
fborm.types.fbFiles = <functools.partial object at 0x1006849f0>

fborm.types.fbcol (lambda x: None, gettable=False, setname=’Files’, setter=_maybeOpen)

def _maybeOpen(filemap):
    result = dict(filemap)
    for name, fileobj in filemap.iteritmes():
        if isinstance(fileobj, basestring):
            result[name] = open(fileobj, 'rb')
        elif not hasattr(fileobj, 'read'):
            raise TypeError(
                "The 'File' mapping must have values which are "
                "either strings pointing to a file on disk, or "
                "objects with a read() method.")
    return result

fbFiles = types.fbcol(
    lambda x: None,
    gettable=False,
    setname='Files',
    setter=_maybeOpen)

This is used for when you want to upload attachments. The documentation on the FogBugz API for uploading attachments with FogBugzPy is hidden here: https://developers.fogbugz.com/default.asp?W208

You need to pass in ‘Files’ set to a dictionary of file names mapped to open file handles set for reading in binary mode. To simplify this we treat this as a dictionary of file names, mapped to file names on disk, and the fborm.objects.fbFiles column type converter will convert the on disk names into open file handles for you.

We are cheating by creating a new dictionary which will go out of scope and be deleted. This will cause the file handles to be closed implicitly. Not very clean, but it is safe.

FogBugz has a file size limit which is configurable by administration up to 100Meg. You are responcible for finding out what that limit is set to and to make sure your files are under that limit.

This should be used as follows:

bugType = dict(
    ixBug = fborm.types.fbint,
    Files = fborm.types.fbFiles,
)

bug = dict(
    ixBug = 42,
    Files = {
        'somefile.txt': '/place/on/disk/somefile.txt',
        'binary.exe': '/other/place/on/disk/foo.bin',
    }
)

fbo.edit(bug, bugType)

Table Of Contents

Previous topic

Object Type Mappings

Next topic

FogBugz XML API Data Parsing

This Page