Constructor for model instances. All named parameters passed to this method are bound to the newly created instance. Any property names provided at this level which are interfering with the predefined class relations (especially for Foreign fields) are prepended “__” to avoid conflicts and to be used by the related relation class. For instance if your class has father = Foreign(Father) and father is provided to the constructor, its value is saved under __father to be used by the Foreign relationship class as the id of the foreign Model.
Constructor also tries to populate the Model._current_path instance variable by formatting Model._path using the arguments provided.
The class variable that holds the bae uel for the API endpoint for the Model. This should be a “full” URL including the scheme, port and the initial path if there is any.
The class variable that holds the path to be used to fetch the instance from the server. It is a format string using the new format notation defined for str.format(). The primary key will be passed under the same name defined in the _pk property and any other named parameters passed to the Model.get() or the class constructor will be available to this string for formatting.
The class variable that holds the default authentication object to be passed to requests. Can be overridden on either class or instance level for convenience.
The class method which receives the class object and the body text of the server response to be parsed. It is expected to return a dictionary object having the properties of the related model. Defaults to a “staticazed” version of json.loads() so it is not necessary to override it if the response type is valid JSON.
The instance variable which is used to determine if the Model instance is filled from the server or not. It can be modified for certain usages but this is not suggested. If _fetched is False when an attribute, that is not in the class dictionary, tried to be accessed, the __fetch() method is called before raising an AttributeError.
The instance variable which holds the additional named get parameters provided to the Model.get() to fetch the instance. It is used internally by the Relation classes to get more info about the current Model instance while fetching its related resources.
The class method which receives the response from the server. This method is expected to return a continuation URL for the fetched resource, if there is any (like the next page’s URL for paginated content) and None otherwise. The default implementation uses the standard HTTP link header and returns the url provided under the label “next” for continuation and None if it cannot find this label.
|Parameters:||response (requests.Response) – The response for the HTTP request made to fetch the resources.|
A property that returns the instance’s primary key value.
The class variable where the attribute name for the primary key for the Model is stored as a string. This property is required and not providing a default is intentional to force developers to explicitly define it on every Model class.
A method which handles all the heavy HTTP stuff by itself. This is actually a private method but to let the instances and derived classes to call it, is made protected using only a single _ prefix.
All undocumented keyword arguments are passed to the HTTP request as keyword arguments such as method, url etc.
|Parameters:||fetch_all (boolean) – (optional) Determines if the function should recursively fetch any “paginated” resource or simply return the downloaded and parsed data along with a continuation URL.|
|Returns:||Returns a tuple where the first part is the parsed data from the server using Model._parser, and the second half is the continuation URL extracted using Model._continuator or None if there isn’t any.|
The class method that fetches and instantiates the resource defined by the provided pk value. Any other extra keyword arguments are used to format the Model._path variable to construct the request URL.
|Parameters:||pk (string) – The primary key value for the requested resource.|
|Return type:||Model or None|
Base class for all relation types.
Class for ‘many’ Relation type which is essentially a collection for a certain model. Needs a base Model for the collection and a path to get the collection from. Falls back to provided model’s Model.path if not provided.
Constructor for Many relation instances.
A function factory method which creates a simple fetcher function for the Many relation, that is used internally. The Model._rest_call() method defined on the models is expected to return the data and a continuation URL if there is any. This method generates a bound, fetcher function that calls the internal Model._rest_call() function on the Model, and processes its results to satisfy the requirements explained above.
|Parameters:||url (unicode) – The url which the fetcher function will be bound to.|
A function factory method which returns a mapping/wrapping function. The returned function creates a new instance of the Model that the Relation is defined with, sets its owner and “automatically fetched” internal flag and returns it.
|Parameters:||owner (Model) – The owner Model for the collection and its items.|
Constructor for the Foreign relations.
Wrapped list implementation to dynamically create models as someone tries to access an item or a slice in the list. Returns a generator instead, when someone tries to iterate over the whole list.
Lazy list implementation for continuous iteration over very large lists such as commits in a large repository. This is essentially a chained and structured generator. No caching and memoization at all since the intended usage is for small number of iterations.