Managers¶
The raw FileMaker manager¶
-
class
filemaker.manager.
RawManager
(url, db, layout, response_layout=None, **kwargs)[source]¶ The raw manager allows you to query the FileMaker web interface.
Most manager methods (the exceptions being the committing methods;
find
,find_all
,edit
,new
, anddelete
) are chainable, enabling usage likemanager = RawManager(...) manager = manager.filter(field=value).add_sort_param('some_field') results = manager.find_all()
-
__init__
(url, db, layout, response_layout=None, **kwargs)[source]¶ Parameters: - url – The URL to access the FileMaker server. This should contain
any authorization credentials. If a path is not provided (e.g. no
trailing slash, like
http://username:password@192.168.1.2
) then the default path of/fmi/xml/fmresultset.xml
will be used. - db – The database name to access (sets the
-db
parameter). - layout – The layout to use (sets the
-lay
parameter). - response_layout – (Optional) The layout to use (sets the
-lay.response
parameter).
- url – The URL to access the FileMaker server. This should contain
any authorization credentials. If a path is not provided (e.g. no
trailing slash, like
-
add_db_param
(field, value, op=None)[source]¶ Adds an arbitrary parameter to the query to be performed. An optional operator parameter may be specified which will add an additional field to the parameters. e.g.
.add_db_param('foo', 'bar')
sets the parameter...&foo=bar&...
,.add_db_param('foo', 'bar', 'gt')
sets...&foo=bar&foo.op=gt&...
.Parameters: - field – The field to query on.
- value – The query value.
- op – (Optional) The operator to use for this query.
-
add_sort_param
(field, order=u'ascend', priority=0)[source]¶ Add a sort field to the query.
Parameters: - field – The field to sort on.
- order – (Optional, defaults to
ascend
) The direction to sort, one ofascending
ordescending
. - priority – (Optional, defaults to
0
) the order to apply this sort in if multiple sort fields are specified.
-
delete
(**kwargs)[source]¶ Deletes a record using the
-delete
command. This method internally calls_commit
and is not chainable.You should have either called the
set_record_id()
and/orset_modifier_id()
methods on the manager, or passed inRECORDID
orMODID
as params.Parameters: **kwargs – Any additional parameters to pass into the URL. Return type: filemaker.parser.FMXMLObject
-
edit
(**kwargs)[source]¶ Updates a record using the
-edit
command. This method internally calls_commit
and is not chainable.You should have either called the
set_record_id()
and/orset_modifier_id()
methods on the manager, or passed inRECORDID
orMODID
as params.Parameters: **kwargs – Any additional parameters to pass into the URL. Return type: filemaker.parser.FMXMLObject
-
find
(**kwargs)[source]¶ Performs the -find command. This method internally calls
_commit
and is not chainable.Parameters: **kwargs – Any additional fields to search on, which will be passed directly into the URL parameters. Return type: filemaker.parser.FMXMLObject
-
find_all
(**kwargs)[source]¶ Performs the -findall command to return all records. This method internally calls
_commit
and is not chainable.Parameters: **kwargs – Any additional URL parameters. Return type: filemaker.parser.FMXMLObject
-
new
(**kwargs)[source]¶ Creates a new record using the
-new
command. This method internally calls_commit
and is not chainable.Parameters: **kwargs – Any additional parameters to pass into the URL. Return type: filemaker.parser.FMXMLObject
-
set_group_size
(max)[source]¶ Set the group size to return from FileMaker using the
-max
.This is defaulted to 50 when the manager is initialized.
Parameters: max (integer) – The number of records to return.
-
set_logical_operator
(op)[source]¶ Set the logical operator to be used for this query using the
-op
parameter.Parameters: op – Must be one of and
oror
.
-
set_modifier_id
(modid)[source]¶ Sets the
-modid
parameter.Parameters: modid – The modifier ID to set.
-
The FMXMLObject
response¶
-
class
filemaker.parser.
FMXMLObject
(data)[source]¶ A python container container for results returned from a FileMaker request.
The following attributes are provided:
-
data
¶ Contains the raw XML data returned from filemaker.
-
errorcode
¶ Contains the
errorcode
returned from FileMaker. Note that if this value is not zero when the data is parsed at instantiation, then afilemaker.exceptions.FileMakerServerError
will be raised.
-
product
¶ A dictionary containing the FileMaker product details returned from the server.
-
database
¶ A dictionary containing the FileMaker database information returned from the server.
-
metadata
¶ A dictionary containing any metadata returned by the FileMaker server.
-
resultset
¶ A list containing any results returned from the FileMaker server as
FMDocument
instances.
-
field_names
¶ A list of field names returned by the server.
-
target
¶ The target class used by lxml to parse the XML response from the server. By default this is an instance of
FMXMLTarget
, but this can be overridden in subclasses.
-
The FileMakerModel Manager¶
-
class
filemaker.manager.
Manager
(cls)[source]¶ A manager for use with
filemaker.base.FileMakerModel
classes. Inherits from theRawManager
, but adds some conveniences and field mapping methods for use withfilemaker.base.FileMakerModel
sub-classes.This manager can be treated as an iterator returning instances of the relavent
filemaker.base.FileMakerModel
sub-class returned from the FileMaker server. It also supports slicing etc., although negative indexing is unsupported.-
__init__
(cls)[source]¶ Parameters: cls – The filemaker.base.FileMakerModel
sub-class to use this manager with. It is expected that the modelmeta
dictionary will have aconnection
key to a dictionary with values forurl
,db
, andlayout
.
-
filter
(**kwargs)[source]¶ Filter the queryset by model fields. Model field names are passed in as arguments rather than FileMaker fields.
Queries spanning relationships can be made using a
__
, and operators can be specified at the end of the query. e.g. Given a model:class Foo(FileMakerModel): beans = fields.IntegerField('FM_Beans') meta = { 'abstract': True, ... } class Bar(FileMakerModel): foo = fields.ModelField('BAR_Foo', model=Foo) num = models.IntegerField('FM_Num')) meta = { 'connection': {...}, ... }
To find all instances of a
Bar
withnum == 4
:Bar.objects.filter(num=4)
To find all instances of
Bar
withnum < 4
:Bar.objects.filter(num__lt=4)
To Find all instance of
Bar
with aFoo
withbeans == 4
:Bar.objects.filter(foo__beans=4)
To Find all instance of
Bar
with aFoo
withbeans > 4
:Bar.objects.filter(foo__beans__gt=4)
The
filter
method is also chainable so you can do:Bar.objects.filter(num=4).filter(foo__beans=4)
Parameters: **kwargs – The fields and values to filter on.
-
get
(**kwargs)[source]¶ Returns the first item found by filtering the queryset by
**kwargs
. Will raise theDoesNotExist
exception on the managers model class if no items are found, however, unlike the Django ORM, will silently return the first result if multiple results are found.Parameters: **kwargs – Field and value queries to be passed to filter()
-
order_by
(*args)[source]¶ Add an ordering to the queryset with respect to a field.
If the field name is prepended by a
-
that field will be sorted in reverse. Multiple fields can be specified.This method is also chainable so you can do, e.g.:
Foo.objects.filter(foo='bar').order_by('qux').filter(baz=1)
Parameters: *args – The field names to order by.
-
preprocess_resultset
(resultset)[source]¶ This is a hook you can override on a manager to pre-process a resultset from FileMaker before the data is converted into model instances.
Parameters: resultset – The resultset
attribute of thefilemaker.parser.FMXMLObject
returned from FileMaker
-