Code documentation

Caffeine app

caffeine.admin

Django admin classes for the caffeine app.

class caffeine.admin.UserCreationForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)

A form for creating new users. Includes all the required fields, plus a repeated password.

clean_password2()

Check that the two password entries match.

save(commit=True)

Save the provided password in hashed format.

class caffeine.admin.UserChangeForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)

A form for updating users. Includes all the fields on the user, but replaces the password field with admin’s password hash display field.

class caffeine.admin.CaffeineUserAdmin(model, admin_site)

Custom admin page for users.

add_form

alias of UserCreationForm

form

alias of UserChangeForm

caffeine.authbackend

Custom authentication backend for coffeestats.

class caffeine.authbackend.LegacyCoffeestatsAuth

Authentication backend for passwords generated by the original coffeestats PHP implementation.

caffeine.forms

Forms for coffeestats.

class caffeine.forms.CoffeestatsRegistrationForm(*args, **kwargs)

This is the form for registering new users.

clean_username()

Validate that the username is alphanumeric and is not already in use.

class caffeine.forms.SettingsForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, instance=None, use_required_attribute=None, renderer=None)

This is the form for changing a user’s settings.

clean()

Hook for doing any extra form-wide cleaning after Field.clean() has been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named ‘__all__’.

clean_email()

Validate that the supplied email address is unique for the site.

class caffeine.forms.SelectTimeZoneForm(*args, **kwargs)

This is the form for selecting a user’s time zone.

class caffeine.forms.SubmitCaffeineForm(user, ctype, *args, **kwargs)

This is the form for new caffeine submissions.

clean()

Hook for doing any extra form-wide cleaning after Field.clean() has been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named ‘__all__’.

caffeine.middleware

class caffeine.middleware.EnforceTimezoneMiddleware(get_response)

Middleware to enforce that users have a time zone set.

caffeine.models

class caffeine.models.User(*args, **kwargs)

User model.

exception DoesNotExist
exception MultipleObjectsReturned
has_usable_password()

Checks whether the current user has either an old password hash or a valid new password hash.

set_password(password)

Sets the password and creates the authentication token if it is not set.

class caffeine.models.CaffeineManager

Manager class for Caffeine.

daily_caffeine()

Return series of daily coffees and mate in current month for all users.

Returns:result dictionary
daily_caffeine_for_user(user)

Return series of daily coffees and mate in current month for user profile.

Parameters:user (User) – user instance
Returns:result dictionary
get_csv_data(drinktype, user)

Get user records for a specific drink type in CSV format.

Parameters:
  • drinktype (str) – drink type
  • user (User) – user instance
Returns:

list of records in CSV format

hourly_caffeine()

Return series of hourly coffees and mate on current day for all users.

Returns:result dictionary
hourly_caffeine_for_user(user)

Return series of hourly coffees and mate on current day for user profile.

Parameters:user (User) – user instance
Returns:result dictionary
hourly_caffeine_for_user_overall(user)

Return a series of hourly caffeinated drinks for the whole timespan of a user’s membership.

Parameters:user (User) – user instance
Returns:result dictionary
hourly_caffeine_overall()

Return a series of hourly caffeinated drinks for the whole lifetime of the site.

Returns:result dictionary
latest_caffeine_for_user(user, count=10)

Return the latest caffeine entries for the given user.

Parameters:
  • user (User) – user instance
  • count (int) – number of entries
Returns:

list of Caffeine instances

monthly_caffeine_for_user(user)

Return a series of monthly coffees and mate in the current month for user profile.

Parameters:user (User) – user instance
Returns:result dictionary
monthly_caffeine_overall()

Return a series of monthly coffees and mate in the current month for all users.

Returns:result dictionary
total_caffeine()

Return total caffeine for all users.

Returns:result dictionary
total_caffeine_for_user(user)

Return total caffeine for user profile.

Parameters:user (User) – user instance
Returns:result dictionary
weekdaily_caffeine_for_user_overall(user)

Return a series of caffeinated drinks per weekday for the whole timespan of a user’s membership.

Parameters:user (User) – user instance
Returns:result dictionary
weekdaily_caffeine_overall()

Return a series of caffeinated drinks per weekday for the whole lifetime of the site.

Returns:result dictionary
class caffeine.models.Caffeine(*args, **kwargs)

Caffeinated drink model.

exception DoesNotExist
exception MultipleObjectsReturned
clean()

Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.

class caffeine.models.ActionManager

Manager class for actions.

class caffeine.models.Action(*args, **kwargs)

Action model.

exception DoesNotExist
exception MultipleObjectsReturned

caffeine.templatetags.caffeine

caffeine.templatetags.caffeine.publicurl(context, username=None)
caffeine.templatetags.caffeine.ontherunurl(context, user=None)
caffeine.templatetags.caffeine.messagetags(value, tag)

caffeine.views

Todo

document caffeine.views (there are import errors in django-registration)

Caffeine API v1 app

caffeine_api_v1.views.add_drink(request, userinfo, messages, *args, **kwargs)

Submit a caffeinated beverage.

Parameters:
  • request (HttpRequest) – POST request
  • userinfo (User) – caffeine.models.User
  • messages (dict) – message dictionary
Returns:

messages array or django.http.HttpResponseBadRequest

caffeine_api_v1.views.api_token_required(func)

Decorator to force authentication with an on-the-run token.

caffeine_api_v1.views.random_users(request, **_)

Return a list of random user data.

Parameters:request (HttpRequest) – POST request
Returns:list of users

Core app

core.utils.json_response(func)

Decorator for wrapping the result of a function in a JSON response object.