System Internal Modules
This section documents the lower-level system modules used to compose site settings, editable translations, profile models, fixture import helpers, and Redis sync behavior.
Context processors
codex_django.system.context_processors
Context processors for project-level system data.
This module injects site settings and editable static content into templates, using the configured Django models and Redis-backed managers when available.
Classes
Functions
site_settings(request)
Expose cached site settings in templates via a safe proxy object.
The processor reads the configured singleton settings model, loads its
cached representation through the Redis-backed manager, and injects the
result into templates as site_settings. Missing configuration or
cache failures degrade to an empty :class:SettingsProxy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
HttpRequest
|
Incoming Django request. The request itself is unused but kept to satisfy the Django context processor contract. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict[str, Any]
|
A template context mapping with the |
|
a |
dict[str, Any]
|
class: |
Source code in src/codex_django/system/context_processors.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
static_content(request)
Expose static translation content as a simple template dictionary.
The processor reads the configured translation model and materializes all
key -> content pairs into the template context as static_content.
Missing configuration or query failures degrade to an empty dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
HttpRequest
|
Incoming Django request. The request itself is unused but kept to satisfy the Django context processor contract. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A template context mapping with the |
Source code in src/codex_django/system/context_processors.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
Settings mixins
codex_django.system.mixins.settings
Reusable mixins for building a project-specific site settings model.
Combine :class:AbstractSiteSettings with the desired field mixins inside the
target project's system app, then point
settings.CODEX_SITE_SETTINGS_MODEL to the concrete model. Instances are
serialized to Redis automatically through :class:SiteSettingsSyncMixin.
Classes
SiteSettingsSyncMixin
Bases: LifecycleModelMixin, Model
Provide Redis synchronization helpers for site settings models.
Notes
Projects usually do not instantiate this mixin directly. Instead it
is inherited through :class:AbstractSiteSettings.
Source code in src/codex_django/system/mixins/settings.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
Functions
to_dict()
Serialize concrete model fields into a Redis-friendly mapping.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary containing concrete non-relational field values. |
dict[str, Any]
|
File fields are converted to their public URL when available. |
Source code in src/codex_django/system/mixins/settings.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
sync_to_redis()
Hook to automatically update Redis cache upon saving.
In DEBUG mode Redis sync is skipped unless CODEX_REDIS_ENABLED=True. This allows local development without a running Redis instance.
Source code in src/codex_django/system/mixins/settings.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
SiteContactSettingsMixin
Bases: Model
Add contact information fields to a site settings model.
Notes
Use this mixin when the project needs a single editable source for phone, email, address, and public contact metadata.
Admin
fieldsets: ( _("Contact Information"), { "fields": ( "phone", "email", "address_street", "address_locality", "address_postal_code", "contact_person", "working_hours", ), }, )
Source code in src/codex_django/system/mixins/settings.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
SiteGeoSettingsMixin
Bases: Model
Add map and geographic metadata fields to a site settings model.
Notes
These fields are useful for map embeds, structured data, and contact pages that need coordinates or provider links.
Admin
fieldsets: (_("Geography & Map"), {"fields": ("google_maps_link", "latitude", "longitude"), "classes": ("collapse",)})
Source code in src/codex_django/system/mixins/settings.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
SiteSocialSettingsMixin
Bases: Model
Add social network URL fields to a site settings model.
Notes
The mixin is intentionally broad so projects can expose only the subset of networks they actually render in templates.
Admin
fieldsets: ( _("Social Networks"), { "fields": ( "instagram_url", "facebook_url", "telegram_url", "whatsapp_url", "youtube_url", "linkedin_url", "tiktok_url", "twitter_url", "pinterest_url", ), "classes": ("collapse",), }, )
Source code in src/codex_django/system/mixins/settings.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
SiteMarketingSettingsMixin
Bases: Model
Add analytics and marketing tracking identifiers.
Notes
These values are typically consumed by template includes that inject analytics and pixel scripts conditionally.
Admin
fieldsets: ( _("Marketing & Analytics"), { "fields": ( "google_analytics_id", "google_tag_manager_id", "facebook_pixel_id", "tiktok_pixel_id", ), "classes": ("collapse",), }, )
Source code in src/codex_django/system/mixins/settings.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
SiteTechnicalSettingsMixin
Bases: Model
Add operational flags and raw script injection fields.
Notes
This mixin is aimed at operational toggles and controlled script injection, not arbitrary long-form content storage.
Admin
fieldsets: ( _("Technical Settings"), { "fields": ("app_mode_enabled", "maintenance_mode", "head_scripts", "body_scripts"), "classes": ("collapse",), }, )
Source code in src/codex_django/system/mixins/settings.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
SiteEmailSettingsMixin
Bases: Model
Add SMTP and email provider configuration fields.
Notes
These fields allow small projects to keep delivery configuration in a single singleton-like settings model.
Admin
fieldsets: ( _("Email Source Settings (SMTP)"), { "fields": ( "smtp_host", "smtp_port", "smtp_user", "smtp_password", "smtp_from_email", "smtp_use_tls", "smtp_use_ssl", "sendgrid_api_key", ), "classes": ("collapse",), }, )
Source code in src/codex_django/system/mixins/settings.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
AbstractSiteSettings
Bases: SiteSettingsSyncMixin, Model
Base abstract site settings model with Redis synchronization only.
Notes
Subclass this model and compose it with the field mixins from this module to build the concrete settings model for a project.
Admin
Typically registered as a singleton-like model combined with the desired fieldset groups from the selected mixins.
Source code in src/codex_django/system/mixins/settings.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
SEO mixins
codex_django.system.mixins.seo
Reusable SEO model mixins for named static pages.
Examples:
Declare a project SEO model in the local system app::
from codex_django.system.mixins.seo import AbstractStaticPageSeo
class StaticPageSeo(AbstractStaticPageSeo):
pass
Classes
AbstractStaticPageSeo
Bases: TimestampMixin, SeoMixin
Store SEO metadata for named static pages with automatic cache invalidation.
Saving the model invalidates the Redis entry managed by
:func:codex_django.core.redis.managers.seo.get_seo_redis_manager.
Admin
list_display: ("page_key", "seo_title", "updated_at") search_fields: ("page_key", "seo_title", "seo_description") readonly_fields: ("created_at", "updated_at")
Source code in src/codex_django/system/mixins/seo.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
Functions
__str__()
Return a readable admin label for the SEO record.
Source code in src/codex_django/system/mixins/seo.py
45 46 47 | |
save(*args, **kwargs)
Persist the SEO record and invalidate the cached page payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments forwarded to |
()
|
**kwargs
|
Any
|
Keyword arguments forwarded to |
{}
|
Source code in src/codex_django/system/mixins/seo.py
49 50 51 52 53 54 55 56 57 58 59 | |
Functions
Translation mixins
codex_django.system.mixins.translations
Reusable model mixin for editable static translations.
Examples:
Keep simple key-value content in a project model::
from codex_django.system.mixins.translations import AbstractStaticTranslation
class StaticTranslation(AbstractStaticTranslation):
pass
Classes
AbstractStaticTranslation
Bases: TimestampMixin
Store editable key-value content fragments managed through Django admin.
This mixin is useful for lightweight static copy that should be editable without introducing a more complex CMS or translation workflow.
Admin
list_display: ("key", "updated_at") search_fields: ("key", "content") readonly_fields: ("created_at", "updated_at")
Source code in src/codex_django/system/mixins/translations.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
Functions
__str__()
Return the translation key for admin and debug output.
Source code in src/codex_django/system/mixins/translations.py
50 51 52 | |
User profile mixins
codex_django.system.mixins.user_profile
Reusable abstract mixin for a project-specific user profile model.
The target project typically subclasses this model in its own concrete
UserProfile implementation, often generated by the cabinet/client
scaffolding flows.
Examples:
Extend the profile with project-specific fields::
from codex_django.system.mixins.user_profile import AbstractUserProfile
class UserProfile(AbstractUserProfile):
loyalty_tier = models.CharField(max_length=32, blank=True)
Classes
AbstractUserProfile
Bases: Model
Reusable abstract profile model linked one-to-one with the auth user.
The scaffolded project can subclass this mixin to keep personal data, acquisition metadata, and presentation helpers in a single profile model.
Admin
list_display: ("id", "user", "last_name", "first_name", "phone", "source", "created_at") search_fields: ("user__username", "user__email", "first_name", "last_name", "phone") list_filter: ("source", "created_at") readonly_fields: ("created_at", "updated_at")
Source code in src/codex_django/system/mixins/user_profile.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
Functions
get_full_name()
Return the profile's full name in Last First Patronymic order.
Returns:
| Type | Description |
|---|---|
str
|
A whitespace-normalized full name string assembled from the |
str
|
available name parts. |
Source code in src/codex_django/system/mixins/user_profile.py
72 73 74 75 76 77 78 79 80 | |
get_initials()
Return up to two uppercase initials built from first and last name.
Returns:
| Type | Description |
|---|---|
str
|
A two-letter initials string when name parts exist, otherwise |
Source code in src/codex_django/system/mixins/user_profile.py
82 83 84 85 86 87 88 89 90 91 92 93 | |
Integration mixins
codex_django.system.mixins.integrations
Integration mixins for storing provider credentials in site settings models.
Compose these mixins with :class:codex_django.system.mixins.settings.AbstractSiteSettings
to keep third-party credentials in a single singleton-like settings object.
Each mixin documents the Django admin wiring that should be added when the
fields are exposed in the project's ModelAdmin.
Classes
GoogleIntegrationsMixin
Bases: Model
Add Google Maps, Business, and reCAPTCHA credentials.
Notes
Secret values that should not be exposed publicly are stored in encrypted fields where appropriate.
Admin
fieldsets: ( _("Google Services"), { "fields": ( "google_maps_api_key", "google_business_api_key", "google_recaptcha_site_key", "google_recaptcha_secret_key", ), "classes": ("collapse",), }, )
Source code in src/codex_django/system/mixins/integrations.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
MetaIntegrationsMixin
Bases: Model
Add Meta platform credentials for Facebook and Instagram integrations.
Notes
This mixin is aimed at ad pixels and app-level integrations rather than content embeds.
Admin
fieldsets: ( _("Meta (Facebook/Instagram)"), { "fields": ("facebook_pixel_id", "facebook_app_id", "facebook_app_secret"), "classes": ("collapse",), }, )
Source code in src/codex_django/system/mixins/integrations.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
StripeIntegrationsMixin
Bases: Model
Add Stripe payment credentials and webhook secrets.
Notes
The secret and webhook fields use encrypted storage because they are server-side credentials.
Admin
fieldsets: ( _("Stripe Payments"), { "fields": ("stripe_public_key", "stripe_secret_key", "stripe_webhook_secret"), "classes": ("collapse",), }, )
Source code in src/codex_django/system/mixins/integrations.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
CrmIntegrationsMixin
Bases: Model
Add a generic CRM endpoint and API key pair.
Notes
This mixin intentionally stays provider-agnostic so projects can wire custom CRM clients around a simple URL + credential contract.
Admin
fieldsets: (_("CRM Integration"), {"fields": ("crm_api_url", "crm_api_key"), "classes": ("collapse",)})
Source code in src/codex_django/system/mixins/integrations.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
TwilioIntegrationsMixin
Bases: Model
Add Twilio credentials for SMS and WhatsApp delivery.
Notes
The mixin stores both SMS and WhatsApp sender configuration because projects often enable them together.
Admin
fieldsets: ( _("Twilio (SMS / WhatsApp)"), { "fields": ( "twilio_account_sid", "twilio_auth_token", "twilio_from_number", "twilio_whatsapp_from", ), "classes": ("collapse",), }, )
Source code in src/codex_django/system/mixins/integrations.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
SevenIoIntegrationsMixin
Bases: Model
Add Seven.io credentials for SMS and WhatsApp delivery.
Notes
Use this mixin as a lightweight alternative to Twilio when Seven.io is the preferred outbound provider.
Admin
fieldsets: (_("Seven.io (SMS / WhatsApp)"), {"fields": ("seven_api_key", "seven_sender_id"), "classes": ("collapse",)})
Source code in src/codex_django/system/mixins/integrations.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
ExtraIntegrationsMixin
Bases: Model
Add a JSON field for custom or project-specific integration settings.
Notes
This field is best used as an extension point for values that do not justify a dedicated strongly typed mixin yet.
Admin
fieldsets: (_("Extra Integrations"), {"fields": ("extra_config",), "classes": ("collapse",)})
Source code in src/codex_django/system/mixins/integrations.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
Base management commands
codex_django.system.management.base_commands
Base classes for content update and fixture import commands.
These command abstractions encapsulate two recurring patterns:
- running several update commands as one orchestration step
- skipping fixture imports when the input files have not changed
Classes
BaseUpdateAllContentCommand
Bases: BaseCommand
Run a predefined sequence of content update subcommands.
Subclasses are expected to populate commands_to_run with Django
management command names. Each subcommand receives the --force flag
when it is provided to the aggregate command.
Source code in src/codex_django/system/management/base_commands.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
Functions
add_arguments(parser)
Register shared command-line arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parser
|
ArgumentParser
|
Django/argparse parser instance for this command. |
required |
Source code in src/codex_django/system/management/base_commands.py
32 33 34 35 36 37 38 | |
handle(*args, **options)
Run each configured subcommand and aggregate failures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments forwarded by Django's command runner. |
()
|
**options
|
Any
|
Parsed command-line options. |
{}
|
Raises:
| Type | Description |
|---|---|
CommandError
|
If one or more subcommands fail. |
Source code in src/codex_django/system/management/base_commands.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
BaseHashProtectedCommand
Bases: BaseCommand
Base class for fixture import commands guarded by a Redis hash check.
The command computes a combined hash for the declared fixture files and
skips the import when the stored hash matches the current one, unless the
caller passes --force.
Source code in src/codex_django/system/management/base_commands.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
Functions
add_arguments(parser)
Register shared command-line arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parser
|
ArgumentParser
|
Django/argparse parser instance for this command. |
required |
Source code in src/codex_django/system/management/base_commands.py
88 89 90 91 92 93 94 | |
get_fixture_paths()
Return the fixture files that define the current content payload.
Returns:
| Type | Description |
|---|---|
list[Path]
|
A list of filesystem paths that should participate in the content |
list[Path]
|
hash calculation. |
Source code in src/codex_django/system/management/base_commands.py
96 97 98 99 100 101 102 103 | |
handle_import(*args, **options)
Execute the actual import operation for the selected fixtures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments forwarded by Django's management command infrastructure. |
()
|
**options
|
Any
|
Parsed command-line options. |
{}
|
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
|
Source code in src/codex_django/system/management/base_commands.py
105 106 107 108 109 110 111 112 113 114 115 116 117 | |
handle(*args, **options)
Skip or execute an import based on the computed fixture hash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments forwarded by Django's command runner. |
()
|
**options
|
Any
|
Parsed command-line options. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the subclass did not set |
Source code in src/codex_django/system/management/base_commands.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
Functions
Fixture Redis manager
codex_django.system.redis.managers.fixtures
Redis-backed helpers for fixture hash tracking.
Classes
FixtureHashManager
Bases: BaseDjangoRedisManager
Store fixture content hashes to skip redundant import operations.
Notes
Each logical fixture group is stored under a fixture:<key> Redis
string so import commands can quickly decide whether work is needed.
Source code in src/codex_django/system/redis/managers/fixtures.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
Functions
aget_hash(fixture_key)
async
Return the stored hash for a logical fixture group, if any.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fixture_key
|
str
|
Logical identifier for the fixture bundle. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The stored hash string or |
Source code in src/codex_django/system/redis/managers/fixtures.py
16 17 18 19 20 21 22 23 24 25 26 27 | |
aset_hash(fixture_key, hash_string)
async
Persist the latest hash for a logical fixture group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fixture_key
|
str
|
Logical identifier for the fixture bundle. |
required |
hash_string
|
str
|
Newly computed content hash to store. |
required |
Source code in src/codex_django/system/redis/managers/fixtures.py
29 30 31 32 33 34 35 36 37 38 | |
get_hash(fixture_key)
Synchronously return the stored hash for a fixture bundle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fixture_key
|
str
|
Logical identifier for the fixture bundle. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The stored hash string or |
Source code in src/codex_django/system/redis/managers/fixtures.py
40 41 42 43 44 45 46 47 48 49 | |
set_hash(fixture_key, hash_string)
Synchronously persist a fixture hash value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fixture_key
|
str
|
Logical identifier for the fixture bundle. |
required |
hash_string
|
str
|
Newly computed content hash to store. |
required |
Source code in src/codex_django/system/redis/managers/fixtures.py
51 52 53 54 55 56 57 58 | |
Functions
get_fixture_hash_manager()
Return a fixture hash manager configured from Django settings.
Returns:
| Type | Description |
|---|---|
FixtureHashManager
|
A ready-to-use :class: |
Source code in src/codex_django/system/redis/managers/fixtures.py
61 62 63 64 65 66 67 | |
Fixture hashing helpers
codex_django.system.utils.fixture_hash
Hash helpers for content and fixture synchronization workflows.
Functions
compute_file_hash(path, chunk_size=8192)
Compute a SHA-256 digest for a single file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Filesystem path to the file that should be hashed. |
required |
chunk_size
|
int
|
Read size used while streaming file contents. |
8192
|
Returns:
| Type | Description |
|---|---|
str
|
Hex-encoded SHA-256 digest for the file contents. |
Source code in src/codex_django/system/utils/fixture_hash.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
compute_paths_hash(paths)
Compute a combined SHA-256 digest for multiple fixture files.
The digest incorporates both file names and file contents so that renames and content changes invalidate the stored value. Non-file paths are ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
list[Path]
|
Candidate filesystem paths to include in the combined hash. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Hex-encoded SHA-256 digest for the ordered set of existing files. |
Source code in src/codex_django/system/utils/fixture_hash.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |