calingen.models.event¶
App-specific Event model.
Beside the actual calingen.models.event.Event model, this module
contains the related implementations of django.db.models.QuerySet,
django.db.models.Manager and django.forms.ModelForm.
Module Contents¶
Classes¶
Represents one event in a user's calendar. |
|
Used to validate input for creating and updating Event instances. |
|
App-/model-specific implementation of |
|
App-specific implementation of |
- exception calingen.models.event.EventModelException¶
Bases:
calingen.exceptions.CalingenExceptionBase class for all exceptions related to the
Eventmodel.
- class calingen.models.event.Event(*args, **kwargs)¶
Bases:
django.db.models.ModelRepresents one event in a user’s calendar.
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¶
- unique_together = ['profile', 'title', 'start']¶
- verbose_name¶
- verbose_name_plural¶
- calingen_manager¶
App-/model-specific manager, that provides additional functionality.
This manager is set to
calingen.models.event.EventManager. Its implementation provides augmentations of Event 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.
- category¶
The category of this Event.
Notes
Some functionalities of the Event class depend on the actual
EventCategorystored in this attribute.The attribute is implemented as
CharFieldwith its possible values limited bycalingen.constants.EventCategory.
- 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).
- profile¶
Reference to a
Profileobject.Notes
This is implemented as a
ForeignKeywithon_delete=CASCADE, meaning: if the referencedProfileobject is deleted, all referencingEventobjects are discarded aswell.The backwards relation (see
ForeignKey.related_name) is named"events".
- start¶
Date and time of a recurring event (
datetime.datetime).Warning
The name of this attribute might be misleading at first. calingen will be developed in small steps, of which the first one will be to track annual aniversaries with the Event class. Nevertheless, it is planned to enable calingen to track generic recurring events. In that implementation step, Event instances will have a start and end
datetime.To ease the refactoring, this attribute is already named start.
Notes
The attribute is implemented as
DateTimeField.
- __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:
- class calingen.models.event.EventForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)¶
Bases:
django.forms.ModelFormUsed to validate input for creating and updating Event instances.
- start¶
- class calingen.models.event.EventManager¶
Bases:
django.db.models.ManagerApp-/model-specific implementation of
django.db.models.Manager.Notes
This
Managerimplementation is used as an additional manager ofEvent(seecalingen.models.event.Event.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 customQuerySetimplementationEventQuerySet.- get_calendar_entry_list(user=None, year=None)¶
Return all instances as
CalendarEntryList.- Parameters:
user –
The summary is provided for an actual user, filtered by
calingen.models.event.Event.owner.Most likely you will want to pass
request.userinto the method.- Returns:
All
Eventinstances ofuser, converted into aCalendarEntryList.- Return type:
- get_queryset()¶
Use the app-/model-specific
EventQuerySetby default.- Returns:
This queryset is provided by
calingen.models.event.EventQuerySetand applies itsdefault()method. The retrieved objects will be annotated with additional attributes.- Return type:
django.models.db.QuerySet
- get_user_events_qs(user=None)¶
Provide a
QuerySetcontaining all events of a givenuser.- Parameters:
user –
The summary is provided for an actual user, filtered by
calingen.models.event.Event.owner.Most likely you will want to pass
request.userinto the method.- Returns:
This queryset is provided by
calingen.models.event.EventQuerySetand applies itsfilter_by_user()method.- Return type:
django.models.db.QuerySet
- summary(user=None)¶
Provide a user-specific summary of
Eventinstances.- Parameters:
user –
The summary is provided for an actual user, filtered by
calingen.models.event.Event.owner.Most likely you will want to pass
request.userinto the method.- Returns:
As of now, the method only returns the number of instances.
- Return type:
- class calingen.models.event.EventQuerySet(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.event.Eventinstances by annotating them with additional information.- default()¶
Return a
QuerySetwith annotations.- Returns:
The annotated queryset.
- Return type:
QuerySet
- 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.