### Entrypoint Script for Image as Environment Approach Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/how_to/docker.md This shell script serves as the entry point for the container, setting up the application by installing requirements, running migrations, and collecting static files each time the container starts. This method is recommended for those who prefer to manage files on the filesystem. ```shell pip install -r requirements.txt python manage.py migrate python manage.py collectstatic --noinput ``` -------------------------------- ### Install Development Tooling Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/getting_started/install.md Install the development dependencies for the professional template. ```console $ pip install -r requirements-dev.txt ``` -------------------------------- ### Run Development Server Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/getting_started/install.md Start the local development server to view your new website. ```console $ python manage.py runserver ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/coderedcorp/coderedcms/blob/main/coderedcms/project_template/basic/README.md Run this command in your project directory to install all necessary Python packages listed in requirements.txt. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install coderedcms Package Source: https://github.com/coderedcorp/coderedcms/blob/main/README.md Use pip to install the coderedcms package. This is the first step in setting up the extension. ```bash pip install coderedcms ``` -------------------------------- ### Run Initial Migrations Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/how_to/convert_image_model.md Ensure all existing migrations are applied before proceeding with custom model setup. ```console python manage.py migrate python manage.py makemigrations No changes detected ``` -------------------------------- ### Create New Project (Basic) Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/getting_started/install.md Start a new CodeRed CMS project with default settings. The --sitename and --domain flags are optional. ```console $ coderedcms start mysite --sitename "My Company Inc." --domain "www.example.com" ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/coderedcorp/coderedcms/blob/main/coderedcms/project_template/pro/README.md Installs all necessary Python packages for the project and development tooling. ```bash pip install -r requirements.txt -r requirements-dev.txt ``` -------------------------------- ### Run Development Server Source: https://github.com/coderedcorp/coderedcms/blob/main/coderedcms/project_template/basic/README.md Execute this command to start the Django development server. Access the site at http://localhost:8000/ and the admin at http://localhost:8000/admin/. ```bash python manage.py runserver ``` -------------------------------- ### Install CodeRed CMS Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/getting_started/install.md Install the CodeRed CMS package using pip within your activated virtual environment. ```console $ pip install coderedcms ``` -------------------------------- ### Install coderedcms from Local Directory Source: https://github.com/coderedcorp/coderedcms/blob/main/requirements-ci.txt Use this command to install the coderedcms package directly from the local directory. This is useful during development or for specific deployment scenarios. ```bash -e . ``` -------------------------------- ### Basic Product Page Template Setup Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/advanced/advanced02.md Provides the essential template tags for a basic functioning product page template, extending the default CoderedCMS web page template. ```django {% extends "coderedcms/pages/web_page.html" %} {% load wagtailcore_tags wagtailimages_tags coderedcms_tags %} ``` -------------------------------- ### Example CSV Structure for Page Import Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/features/import_export.md This is an example of how your CSV file should be structured for importing pages. Each column header corresponds to a page attribute. ```text title , address , latitude , longitude Store 1 , 123 Street , 20.909 , -15.32 Store 2 , 456 Avenue , 34.223 , 87.2331 ... ... ``` -------------------------------- ### Start a New Wagtail CRX Site Source: https://github.com/coderedcorp/coderedcms/blob/main/README.md Use the coderedcms start command to create a new Django project with Wagtail CRX pre-configured. Optional arguments can pre-populate site name and domain settings. ```bash coderedcms start mysite --sitename "My Company Inc." --domain www.example.com ``` -------------------------------- ### Create New Project (Professional) Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/getting_started/install.md Start a new CodeRed CMS project using the professional template, which includes extra features and tooling. The --sitename and --domain flags are optional. ```console $ coderedcms start mysite --template pro --sitename "My Company Inc." --domain "www.example.com" ``` -------------------------------- ### Start a new Django app Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/how_to/use_custom_image_model.md Use the django-admin command to create a new Django app for your custom models. Ensure this app does not import coderedcms to avoid circular dependencies. ```console $ django-admin startapp mediamodels ``` -------------------------------- ### Navigate to Project Directory Source: https://github.com/coderedcorp/coderedcms/blob/main/README.md Change into the newly created project directory to access its files and run management commands. ```bash cd mysite/ ``` -------------------------------- ### Configure Django Project Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/getting_started/install.md Run Django migrations and create a superuser for your new project. ```console $ python manage.py migrate $ python manage.py createsuperuser ``` -------------------------------- ### Build Documentation with Sphinx Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/contributing/index.md Manually build the project documentation using Sphinx. Output will be located in the `docs/_build/html/` directory. ```console sphinx-build -M html docs/ docs/_build/ -W ``` -------------------------------- ### Make Migrations for Custom Image Model Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/how_to/_custom_image2.md Run this command to create a migration file for your custom image model. This should be done before switching your project to use the new model. ```console python manage.py makemigrations mediamodels ``` -------------------------------- ### Get Subscriber JSON Data Source: https://github.com/coderedcorp/coderedcms/blob/main/coderedcms/templates/coderedcms/formfields/mailchimp/subscriber_integration_js.html Retrieves the subscriber data stored in a hidden input field as a JSON object. ```javascript function get_subscriber_json_data_for_{{ widget_js_name }}(){ return JSON.parse($("input[name='{{ widget_name }}']").val()); } ``` -------------------------------- ### Build Documentation with PowerShell Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/contributing/index.md Run this PowerShell script to build the project documentation and check for errors. This should be done for every code or feature change. ```console ./ci/make-docs.ps1 ``` -------------------------------- ### Make and Apply Mediamodels Migrations Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/how_to/convert_image_model.md Create and apply migrations for your new custom image model app before updating project settings. ```console python manage.py makemigrations mediamodels python manage.py migrate mediamodels ``` -------------------------------- ### Run database migrations Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/releases/v1.0.0.md After updating your code, make and run the necessary database migrations to apply schema changes. ```bash python manage.py makemigrations python manage.py migrate ``` -------------------------------- ### Dockerfile for Image as Environment Approach Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/how_to/docker.md This Dockerfile is used when the container acts as the runtime environment, with code and files stored externally. It copies the entrypoint script and configures the container to run the application. ```dockerfile FROM python:latest ENV PYTHONUNBUFFERED 1 # Set the Django settings to use. ENV DJANGO_ENV "dev" ENV DJANGO_SETTINGS_MODULE "myproject.settings.dev" # Install a WSGI server into the container image. RUN pip install waitress # Code will end up living in /app/ WORKDIR /app/ # Create a "coderedcms" user account to run the appp. RUN useradd coderedcms RUN chown -R coderedcms /app/ USER coderedcms # Copy our entrypoint script. COPY ./docker-entrypoint.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/docker-entrypoint.sh # Finally, run the app on port 8000. EXPOSE 8000 ENTRYPOINT ["docker-entrypoint.sh"] CMD exec waitress serve --listen "*:8000" "myproject.wsgi:application" ``` -------------------------------- ### Run Migrations After Upgrading Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/releases/v0.18.0.md After upgrading, you may need to run these commands to apply database schema changes. ```bash python manage.py makemigrations website ``` ```bash python manage.py migrate ``` -------------------------------- ### Run Database Migrations Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/releases/v2.0.0.md Apply database schema changes after upgrading. Ensure you run these commands in your project's virtual environment. ```text python manage.py makemigrations python manage.py migrate ``` -------------------------------- ### Apply Database Migrations Source: https://github.com/coderedcorp/coderedcms/blob/main/README.md Run Django's migrate command to set up the necessary database tables for Wagtail CRX and its core models. ```bash python manage.py migrate ``` -------------------------------- ### Dockerfile for Versioned Image Approach Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/how_to/docker.md Use this Dockerfile to create a static Docker image that includes all project code. This approach is suitable when using external services for dynamic files like databases or media. ```dockerfile FROM python:latest ENV PYTHONUNBUFFERED 1 # Set the Django settings to use. ENV DJANGO_ENV "dev" ENV DJANGO_SETTINGS_MODULE "myproject.settings.dev" # Install a WSGI server into the container image. RUN pip install waitress # Code will end up living in /app/ WORKDIR /app/ # Copy and install the project requirements. COPY ./requirements.txt /app/requirements.txt RUN pip install -r /app/requirements.txt # Copy the entire project code. COPY . /app/ # Prepare the app. RUN python manage.py migrate RUN python manage.py collectstatic --noinput # Create a "coderedcms" user account to run the app. RUN useradd coderedcms RUN chown -R coderedcms /app/ USER coderedcms # Finally, run the app on port 8000. EXPOSE 8000 CMD exec waitress-serve --listen "*:8000" "myproject.wsgi:application" ``` -------------------------------- ### Build Docker Image Command Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/how_to/docker.md This command builds a Docker image from a specified Dockerfile and project directory. It pulls the latest base image, tags the resulting image as 'myproject:v1', and is used for both versioned image and image as environment approaches. ```console docker build --pull -t myproject:v1 -f /path/to/Dockerfile /path/to/project/ ``` -------------------------------- ### Create Virtual Environment (macOS/Linux) Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/getting_started/install.md Use this command to create a new virtual environment on macOS or Linux. ```console $ python -m venv ./venv/ $ source ./venv/bin/activate ``` -------------------------------- ### Configure Protected Media Upload Whitelist Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/reference/django_settings.md Define allowed file extensions for media uploads to protected directories. Defaults to a blank list. ```python CRX_PROTECTED_MEDIA_UPLOAD_WHITELIST = ['.pdf', '.doc', '.docx', '.txt', '.rtf', '.jpg', '.jpeg', '.png', '.gif'] ``` -------------------------------- ### Upload Documentation to CodeRed Server Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/contributing/index.md Use the `cr` tool to upload the built documentation to the CodeRed docs server. Ensure the path and remote directory are correct. ```console cr upload --path ./docs/_build/html/ --remote /www/wagtail-crx/ docs ``` -------------------------------- ### Run Docker Image with Bind Mount Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/how_to/docker.md This command runs a container from a Docker image and mounts the local directory './' to '/app/' inside the container. This is useful for persisting data created or modified within the container. It also maps port 8000 and detaches the container. ```console $ docker run --publish 8000:8000 --detach --name myproject-run --mount type=bind,source=./,target=/app myproject:v1 ``` -------------------------------- ### Create Superuser Source: https://github.com/coderedcorp/coderedcms/blob/main/README.md Use the createsuperuser command to create an administrator account for accessing the Wagtail admin interface. ```bash python manage.py createsuperuser ``` -------------------------------- ### Build Sass for Website Source: https://github.com/coderedcorp/coderedcms/blob/main/coderedcms/project_template/pro/README.md Compiles the custom Sass file into CSS for the website. Use the --watch option to automatically recompile on file changes, and -t compressed for production builds. ```bash python manage.py sass -g website/static/website/src/custom.scss website/static/website/css/ ``` -------------------------------- ### Create Virtual Environment (Windows) Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/getting_started/install.md Use this command to create a new virtual environment on Windows using PowerShell. ```powershell PS> python -m venv .\venv\ PS> .\venv\Scripts\Activate.ps1 ``` -------------------------------- ### Create Django App Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/how_to/_custom_image1.md Use the django-admin command to create a new, empty Django app for your custom media models. This app should not import coderedcms. ```bash django-admin startapp mediamodels ``` -------------------------------- ### Make initial migrations for custom model Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/how_to/use_custom_image_model.md Before switching the Wagtail setting, create migrations for your custom model. This step is only necessary if the model has not been migrated before. ```console $ python manage.py makemigrations mediamodels ``` -------------------------------- ### Configure Protected Media Upload Blacklist Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/reference/django_settings.md Define disallowed file extensions for media uploads to protected directories. Defaults to a list of potentially harmful file types. ```python CRX_PROTECTED_MEDIA_UPLOAD_BLACKLIST = ['.sh', '.exe', '.bat', '.ps1', '.app', '.jar', '.py', '.php', '.pl', '.rb'] ``` -------------------------------- ### Format Code with Ruff Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/contributing/index.md Format all code according to project standards using the ruff formatter before committing changes. This ensures consistent code style. ```console $ ruff format . ``` -------------------------------- ### Run Versioned Docker Image Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/how_to/docker.md Use this command to run a container from a versioned Docker image. It maps port 8000 and detaches the container. ```console $ docker run --publish 8000:8000 --detach --name myproject-run myproject:v1 ``` -------------------------------- ### Run Unit Tests with PowerShell Script Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/contributing/index.md Conveniently run unit tests using the provided PowerShell script. This script also prints the code coverage percentage to the console. ```powershell $ ./ci/run-tests.ps1 ``` -------------------------------- ### Build Python Package Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/contributing/index.md Use this command to build a publicly consumable pip package from your Python project. ```console python -m build ``` -------------------------------- ### Define Custom Product Page Models Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/advanced/advanced02.md Creates ProductIndexPage and ProductPage models, extending CoderedWebPage. Specifies parent/subpage types and templates for product-related content. ```python class ProductIndexPage(CoderedWebPage): """ Landing page for Products """ class Meta: verbose_name = "Product Landing Page" # Override to specify custom index ordering choice/default. index_query_pagemodel = 'website.ProductPage' # Only allow ProductPages beneath this page. subpage_types = ['website.ProductPage'] template = 'website/pages/product_index_page.html' class ProductPage(CoderedWebPage): """ Custom page for individual products """ class Meta: verbose_name = "Product Page" # Only allow this page to be created beneath an ProductIndexPage. parent_page_types = ['website.ProductIndexPage'] template = "website/pages/product_page.html" ``` -------------------------------- ### Define Base Page Models Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/advanced/advanced02.md Sets up ArticlePage and WebPage models by extending CoderedCMS base classes. Includes meta options and template definitions. ```python from modelcluster.fields import ParentalKey from coderedcms.forms import CoderedFormField from coderedcms.models import ( CoderedArticlePage, CoderedArticleIndexPage, CoderedEmail, CoderedFormPage, CoderedWebPage, ) class ArticlePage(CoderedArticlePage): """ Article, suitable for news or blog content. """ class Meta: verbose_name = "Article" ordering = ["-first_published_at"] # Only allow this page to be created beneath an ArticleIndexPage. parent_page_types = ["website.ArticleIndexPage"] template = "coderedcms/pages/article_page.html" search_template = "coderedcms/pages/article_page.search.html" ## OTHER CLASSES class WebPage(CoderedWebPage): """ General use page with featureful streamfield and SEO attributes. """ class Meta: verbose_name = "Web Page" template = "coderedcms/pages/web_page.html" ``` -------------------------------- ### Lint and Format Code Source: https://github.com/coderedcorp/coderedcms/blob/main/coderedcms/project_template/pro/README.md Runs Ruff for linting and formatting, and MyPy for type checking. Also executes Pytest for running tests. ```bash ruff check --fix . ruff format . mypy . pytest . ``` -------------------------------- ### Build Compressed Sass for Production Source: https://github.com/coderedcorp/coderedcms/blob/main/coderedcms/project_template/pro/README.md Compiles the custom Sass file into a compressed CSS file suitable for production deployment. ```bash python manage.py sass -t compressed website/static/website/src/custom.scss website/static/website/css/ ``` -------------------------------- ### Upload Pip Package to PyPI Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/contributing/index.md After building a pip package, use this command to upload it to the Python Package Index. ```console twine upload dist/* ``` -------------------------------- ### Configure WebP to JPEG Fallback Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/how_to/images.md Use this Django setting to serve JPEG images instead of WebP for browsers that do not support the WebP format. This ensures compatibility with older systems. ```python WAGTAILIMAGES_FORMAT_CONVERSIONS = { "webp": "jpeg", } ``` -------------------------------- ### Compile Sass to CSS Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/getting_started/install.md Compile Sass files into CSS for the professional template. Use the --watch option to automatically recompile on file changes. ```console $ python manage.py sass website/static/website/src/custom.scss website/static/website/css/custom.css ``` -------------------------------- ### Create a custom image model Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/how_to/use_custom_image_model.md Define your custom image model by inheriting from Wagtail's AbstractImage and AbstractRendition. Add any custom fields as needed. ```python from django.db import models from wagtail.images.models import Image, AbstractImage, AbstractRendition class CustomImage(AbstractImage): # Add any extra fields to image here # eg. To add a caption field: # caption = models.CharField(max_length=255, blank=True) admin_form_fields = Image.admin_form_fields + ( # Then add the field names here to make them appear in the form: # 'caption', ) class CustomRendition(AbstractRendition): image = models.ForeignKey(CustomImage, on_delete=models.CASCADE, related_name='renditions') class Meta: unique_together = ( ('image', 'filter_spec', 'focal_point_key'), ) ``` -------------------------------- ### Build Minified CSS Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/contributing/index.md Use pysassc to compile Sass files into a minified CSS file for production. Ensure you are in the correct directory before running the command. ```console pysassc -t compressed scss/crx-front.scss css/crx-front.min.css ``` -------------------------------- ### Add coderedcms_bootstrap4 to INSTALLED_APPS Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/releases/v1.0.0.md When staying on Bootstrap 4, ensure `coderedcms_bootstrap4` is added to your `INSTALLED_APPS` setting, placed above `coderedcms` to maintain correct template loading order. ```python INSTALLED_APPS = [ ..., "coderedcms_bootstrap4", "coderedcms", ..., ] ``` -------------------------------- ### Django Template for Product Landing Page Source: https://github.com/coderedcorp/coderedcms/blob/main/docs/advanced/advanced02.md This template extends a base Wagtail page and overrides the 'index_content' block to display a grid of products. It iterates through child pages, displaying each product's image, title, description, and prescription status. Use this for pages that list multiple items, like products or services. ```Django {% extends "coderedcms/pages/web_page.html" %} {% load wagtailcore_tags wagtailimages_tags coderedcms_tags %} {% block content_pre_body %} {% if self.cover_image %} {% image page.cover_image fill-1600x900 format-webp as cover_image %}
Call your doctor to see if {{page.title}} is right for you!
{% else %}No Prescription Needed!
{% endif %}