This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
cbv_mixins.py - Provide useful mixins for Django's already useful Class Based Views. | |
* MessageMixin: Automates assigning of success, error messages to POST method | |
""" | |
class MessageMixin(object): | |
"""Automate addition of success/error messages if defined in the view.""" | |
def get_success_message(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Subclass Django admin classes to automate saving created_by, modified_by fields. | |
Requires models being registered have the necesssary fields. | |
""" | |
from django.contrib import admin | |
from django.contrib.contenttypes.admin import GenericTabularInline | |
class UserSaveModelAdmin(admin.ModelAdmin): | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.pagination import PageNumberPagination | |
from rest_framework.response import Response | |
class PageCountPaginator(PageNumberPagination): | |
"""Implements all behaviors from `PageNumberPagination` class but results includet `page_count` value.""" | |
def get_paginated_response(self, data): | |
return Response({ | |
'count': self.page.paginator.count, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ListDetailMixin: | |
""" | |
Encapsulate the selection of separate serializers | |
based on the detail boolean of the View `self.detail`. | |
Requires View (or Viewset) have the following properties: | |
* list_serializer - For returning lists of records | |
* detail_serializer - For returning a single record (usually more fields) | |
""" | |
# For details regarding viewset attrbiutes please refer to the DRF documentation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# wait for RabbitMQ server to start | |
sleep 10 | |
# If we have a stale PID file we need to remove it | |
if [[ -f w1.pid ]]; then | |
rm -f ./w1.pid | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
# DOCKER ENVIRONMENT VARIABLES TEMPLATE # | |
# Many of these settings are automatically used by Docker images when first # | |
# being created in an application. In other situations (like custom Django # | |
# settings) thees values are accessed by the server code through custom calls # | |
# like os.environ.get() # | |
################################################################################ | |
# Django App Container Variables | |
SETTINGS_FILE= # <- SETTING FILE PATH GOES HERE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.http import JsonResponse | |
from django.template.loader import render_to_string | |
class JsonTemplateMixin: | |
""" | |
A mixnin for returning a rendered template as a JSON response, | |
along with a value to indicate to a calling function whether the | |
rendering was successful or not. | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
project.context_processors - Custom designed context processors. | |
These context processors handle setting additional context variables | |
in the Django request/response cycle. | |
Processors: | |
debug_var - This sends the DEBUG setting value to the template context as the `testing_env` variable. | |
""" |