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

Profile

Represents the app-specific profile.

ProfileForm

Used to validate input for creating and updating Profile instances.

ProfileManager

App-/model-specific implementation of django.db.models.Manager.

ProfileQuerySet

App-specific implementation of django.db.models.QuerySet.

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.

class Meta
app_label = calingen
verbose_name
verbose_name_plural
property event_provider

Get and set the list of EventProvider.

This method is used to access the Profile’s EventProvider. The returned object will have three attributes, active, unavailable and newly_unavailable: active contains the selected EventProvider plugins, that are currently active in this project. If the user had selected EventProvider plugins, that are currently not available in this project, i.e. because they were deactivated by the administrator, these plugins are moved to unavailable. Also, these plugins are included in newly_unavailable and then picked up in the get_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, the setter simply applies the provided value to _event_provider. This means, that if the user did not actually update its profile, the operation performed by the getter is simply discarded.

_event_provider

Manage EventProvider plugins for this profile.

Notes

This is implemented as a JSONField and should be interfaced by its custom event_provider() getter and setter methods, provided as a property.

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 custom calingen_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 with on_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 the User 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:

str

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:

CalendarEntryList

class calingen.models.profile.ProfileForm(*args, **kwargs)

Bases: django.forms.ModelForm

Used to validate input for creating and updating Profile instances.

class Meta
fields = ['event_provider']
model
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 a property to interface _event_provider.

The property is added here and then applied in the form’s save() 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 of Profile (see calingen.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 custom QuerySet implementation ProfileQuerySet.

get_profile(user)

Retrieve the Profile associated with a User instance.

Parameters:

user – An instance of the project’s user model, as specified by AUTH_USER_MODEL.

Returns:

The Profile associated with the given user.

Return type:

calingen.models.profile.Profile

get_queryset()

Use the app-/model-specific ProfileQuerySet by default.

Returns:

This queryset is provided by calingen.models.profile.ProfileQuerySet and applies its default() 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 their owner available without another database query.

Return type:

QuerySet

Notes

This method makes the associated project user (specified by AUTH_USER_MODEL and stored in Profile.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.