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.ModelRepresents 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,unavailableandnewly_unavailable:activecontains the selectedEventProviderplugins, that are currently active in this project. If the user had selectedEventProviderplugins, 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_unavailableand then picked up in theget_context_data()method to provide messages to the user.Notes
While the implementation of the
getterinvolves some logic to perform the operations as described above, thesettersimply applies the provided value to_event_provider. This means, that if the user did not actually update its profile, the operation performed by thegetteris simply discarded.
- _event_provider¶
Manage
EventProviderplugins for this profile.Notes
This is implemented as a
JSONFieldand 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_manageras 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
OneToOneFieldwithon_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 theUsermodel 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.ModelFormUsed to validate input for creating and updating
Profileinstances.- event_provider¶
Manually add the model’s
propertyto the form.Notes
ModelFormonly includes actual model fields.calingen.models.profile.Profile.event_provideris actually only apropertyto interface_event_provider.The
propertyis added here and then applied in the form’ssave()method.
- save(*args, **kwargs)¶
Inject the value of
event_providerinto the instance and save it.
- class calingen.models.profile.ProfileManager¶
Bases:
django.db.models.ManagerApp-/model-specific implementation of
django.db.models.Manager.Notes
This
Managerimplementation is used as an additional manager ofProfile(seecalingen.models.profile.Profile.calingen_manager).This implementation inherits its functionality from
django.db.models.Managerand provides identical funtionality. Furthermore, it augments the retrieved objects with additional attributes, using the customQuerySetimplementationProfileQuerySet.- get_profile(user)¶
Retrieve the
Profileassociated with aUserinstance.- Parameters:
user – An instance of the project’s user model, as specified by
AUTH_USER_MODEL.- Returns:
The
Profileassociated with the givenuser.- Return type:
- get_queryset()¶
Use the app-/model-specific
ProfileQuerySetby default.- Returns:
This queryset is provided by
calingen.models.profile.ProfileQuerySetand 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.CalingenQuerySetApp-specific implementation of
django.db.models.QuerySet.Notes
This
QuerySetimplementation provides app-specific augmentations.The provided methods augment/extend the retrieved
calingen.models.profile.Profileinstances by annotating them with additional information.- _event_count()¶
Annotate each instance with the count of associated
Eventinstances.- 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.owneravailable.- Returns:
Instances of
Profilewill have theirowneravailable without another database query.- Return type:
QuerySet
Notes
This method makes the associated project user (specified by
AUTH_USER_MODELand stored inProfile.owner) available.This annotation is provided in
default().
- default()¶
Return a
QuerySetwith 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.