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

Event

Represents one event in a user's calendar.

EventForm

Used to validate input for creating and updating Event instances.

EventManager

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

EventQuerySet

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

exception calingen.models.event.EventModelException

Bases: calingen.exceptions.CalingenException

Base class for all exceptions related to the Event model.

class calingen.models.event.Event(*args, **kwargs)

Bases: django.db.models.Model

Represents 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 EventCategory stored in this attribute.

The attribute is implemented as CharField with its possible values limited by calingen.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 custom calingen_manager as an additional manager, the default manager has to be provided explicitly (see topics/db/managers/#default-managers).

profile

Reference to a Profile object.

Notes

This is implemented as a ForeignKey with on_delete=CASCADE, meaning: if the referenced Profile object is deleted, all referencing Event objects 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.

title

The actual title of this Event (str).

Notes

The attribute is implemented as CharField.

__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)

Resolve this object’s start for a given year.

Parameters:

year (int, optional) – The year to resolve for. Will use the current year if not specified.

Returns:

The method returns a CalendarEntryList with entries for the given year.

Return type:

CalendarEntryList

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.ModelForm

Used to validate input for creating and updating Event instances.

class Meta
fields = ['category', 'title', 'start']
model
start
class calingen.models.event.EventManager

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 Event (see calingen.models.event.Event.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 EventQuerySet.

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.user into the method.

Returns:

All Event instances of user, converted into a CalendarEntryList.

Return type:

CalendarEntryList

get_queryset()

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

Returns:

This queryset is provided by calingen.models.event.EventQuerySet and applies its default() method. The retrieved objects will be annotated with additional attributes.

Return type:

django.models.db.QuerySet

get_user_events_qs(user=None)

Provide a QuerySet containing all events of a given user.

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.user into the method.

Returns:

This queryset is provided by calingen.models.event.EventQuerySet and applies its filter_by_user() method.

Return type:

django.models.db.QuerySet

summary(user=None)

Provide a user-specific summary of Event instances.

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.user into the method.

Returns:

As of now, the method only returns the number of instances.

Return type:

int

class calingen.models.event.EventQuerySet(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.event.Event instances by annotating them with additional information.

default()

Return a QuerySet with 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.