calingen.models.profile
¶
App-specific user profile.
Beside the actual calingen.models.profile.Profile
model, this module
contains the related implementations of django.db.models.QuerySet
,
django.db.models.Manager
and django.forms.ModelForm
.
Module Contents¶
Classes¶
Represents the app-specific profile. |
|
Used to validate input for creating and updating |
|
App-/model-specific implementation of |
|
App-specific implementation of |
- class calingen.models.profile.Profile(*args, **kwargs)¶
Bases:
django.db.models.Model
Represents the app-specific profile.
Warning
The class documentation only includes code that is actually shipped by the calingen app. Inherited attributes/methods (provided by Django’s
Model
) are not documented here.- property event_provider¶
Get and set the list of
EventProvider
.This method is used to access the
Profile
’sEventProvider
. The returned object will have three attributes,active
,unavailable
andnewly_unavailable
:active
contains the selectedEventProvider
plugins, that are currently active in this project. If the user had selectedEventProvider
plugins, that are currently not available in this project, i.e. because they were deactivated by the administrator, these plugins are moved tounavailable
. Also, these plugins are included innewly_unavailable
and then picked up in theget_context_data()
method to provide messages to the user.Notes
While the implementation of the
getter
involves some logic to perform the operations as described above, thesetter
simply applies the provided value to_event_provider
. This means, that if the user did not actually update its profile, the operation performed by thegetter
is simply discarded.
- _event_provider¶
Manage
EventProvider
plugins for this profile.Notes
This is implemented as a
JSONField
and should be interfaced by its customevent_provider()
getter and setter methods, provided as aproperty
.
- calingen_manager¶
App-/model-specific manager, that provides additional functionality.
This manager is set to
calingen.models.profile.ProfileManager
. Its implementation provides augmentations of Profile objects, by annotating them on database level. This will reduce the number of required database queries, if attributes of the object are accessed.The manager has to be used explicitly.
- objects¶
The model’s default manager.
The default manager is set to
django.db.models.Manager
, which is the default value. In order to add the customcalingen_manager
as an additional manager, the default manager has to be provided explicitly (see topics/db/managers/#default-managers).
- owner¶
Reference to a Django User.
Notes
This is implemented as a
OneToOneField
withon_delete=CASCADE
, meaning: if the referenced User object is deleted, the referencing Profile object is discarded aswell.To keep this application as pluggable as possible, the referenced class is dependent on
AUTH_USER_MODEL
. With this implementation, the project may substitute theUser
model provided by Django without breaking any functionality in calingen (see Reusable Apps and AUTH_USER_MODEL).
- __str__()¶
Return str(self).
- get_absolute_url()¶
Return the absolute URL for instances of this model.
- Returns:
The absolute URL for instances of this model.
- Return type:
- resolve(year=None)¶
Combine all event providers results for a given year into one
CalendarEntryList
.- Parameters:
year (int, optional) – The year to use for resolving the
EventProvider
.- Returns:
A single instance including all events from all active providers.
- Return type:
- class calingen.models.profile.ProfileForm(*args, **kwargs)¶
Bases:
django.forms.ModelForm
Used to validate input for creating and updating
Profile
instances.- event_provider¶
Manually add the model’s
property
to the form.Notes
ModelForm
only includes actual model fields.calingen.models.profile.Profile.event_provider
is actually only aproperty
to interface_event_provider
.The
property
is added here and then applied in the form’ssave()
method.
- save(*args, **kwargs)¶
Inject the value of
event_provider
into the instance and save it.
- class calingen.models.profile.ProfileManager¶
Bases:
django.db.models.Manager
App-/model-specific implementation of
django.db.models.Manager
.Notes
This
Manager
implementation is used as an additional manager ofProfile
(seecalingen.models.profile.Profile.calingen_manager
).This implementation inherits its functionality from
django.db.models.Manager
and provides identical funtionality. Furthermore, it augments the retrieved objects with additional attributes, using the customQuerySet
implementationProfileQuerySet
.- get_profile(user)¶
Retrieve the
Profile
associated with aUser
instance.- Parameters:
user – An instance of the project’s user model, as specified by
AUTH_USER_MODEL
.- Returns:
The
Profile
associated with the givenuser
.- Return type:
- get_queryset()¶
Use the app-/model-specific
ProfileQuerySet
by default.- Returns:
This queryset is provided by
calingen.models.profile.ProfileQuerySet
and applies itsdefault()
method. The retrieved objects will be annotated with additional attributes.- Return type:
django.models.db.QuerySet
- class calingen.models.profile.ProfileQuerySet(model=None, query=None, using=None, hints=None)¶
Bases:
calingen.models.queryset.CalingenQuerySet
App-specific implementation of
django.db.models.QuerySet
.Notes
This
QuerySet
implementation provides app-specific augmentations.The provided methods augment/extend the retrieved
calingen.models.profile.Profile
instances by annotating them with additional information.- _event_count()¶
Annotate each instance with the count of associated
Event
instances.- Returns:
The annotated queryset. The annotation will be available as
event_count
.- Return type:
QuerySet
Notes
This annotation is provided in
default()
.
- _owner()¶
Make
Profile.owner
available.- Returns:
Instances of
Profile
will have theirowner
available without another database query.- Return type:
QuerySet
Notes
This method makes the associated project user (specified by
AUTH_USER_MODEL
and stored inProfile.owner
) available.This annotation is provided in
default()
.
- default()¶
Return a
QuerySet
with annotations.- Returns:
The annotated queryset.
- Return type:
QuerySet
Notes
The following annotations are provided by default:
- filter_by_user(user)¶
Filter the result set by the objects’
owners
.- Parameters:
user – An instance of the project’s user model, as specified by
AUTH_USER_MODEL
.- Returns:
The filtered queryset.
- Return type:
django.db.models.QuerySet
Notes
Effectively, this method is used to ensure, that any user may only access objects, which are owned by him. This is the app’s way of ensuring row-level permissions, because only owners are allowed to view (and modify) their events.