Configuration

class AppSettings(prefix)[source]

This class holds guest user settings.

Each property corresponds to a setting in the Django project prefixed with GUEST_USER_.

property NAME_GENERATOR: str

Import path to the name generator function for temporary guest usernames.

Included with the package are three generators:

  • guest_user.functions.generate_uuid_username (default)

    Generates a UUID4 as a username. Not intended to be shown to the visitor. This is the option with the smallest chance for collisions.

  • guest_user.functions.generate_numbered_username

    Will create a random number with GUEST_USER_NAME_SUFFIX_DIGITS digits prefixed by GUEST_USER_NAME_PREFIX.

    By default this looks like Guest4810, Guest0588, etc.

  • guest_user.functions.generate_friendly_username

    Creates a friendly and easy to remember username by combining an adjective, noun and number. Requires the random_username (PyPI) package.

If the generator creates a username that already exists, a new one will be tried until a unique username has been found.

property NAME_PREFIX: str

Random username prefix used with generate_numbered_username.

Default:

"Guest"

property NAME_SUFFIX_DIGITS: int

Number of digits to append to usernames generated by generate_numbered_username.

Default:

4

property MAX_AGE: int

Maximum age in seconds for guest sessions to stay valid.

After this time the session may get deleted by background tasks.

Default:

django:ref/settings:``session_cookie_age``

property CONVERT_FORM: str

Import path for the form used to convert a guest to a real user.

The form must have a method get_credentials to authenticate the user after registering.

Default:

guest_user.forms.UserCreationForm

property CONVERT_PREFILL_USERNAME: bool

Prefill the generated username in the conversion form.

Default:

False

property CONVERT_URL: str

URL name for the convert view.

Default:

"guest_user_convert"

property CONVERT_REDIRECT_URL: str

URL to redirect to after a successful conversion.

This setting has no effect if a user starts the conversion process from a page where they were redirected from with a ?next=/url/ query string.

Default:

"guest_user_convert_success"

property REQUIRED_ANON_URL: str

Default redirect target when an anonymous visitor tries to access a view where a guest user is required.

Default:

django:ref/settings:``login_url``

property REQUIRED_USER_URL: str

Default redirect target when a registered user tries to access a view where a guest user is required.

Default:

django:ref/settings:``login_redirect_url``

property BLOCKED_USER_AGENTS: List[str]

A list of ignored user agents that will not create guest users.

Items will be compiled together as a regular expression so you may use regex syntax.

Default:

Googlebot, Mediapartners-Google, Bingbot, Slurp, DuckDuckBot, Baiduspider, Yandex(Mobile)?Bot, Sogou, Exabot, facebot, facebookexternalhit, ia_archiver

property ENABLED: bool

Disable guest users with this setting.

Default:

True

Warning

The @allow_guest_user decorator will not enforce users to be authenticated if this setting is False.

property MODEL: str

Specify a different model to use for temporary guest users.

Default:

"guest_user.Guest"