This file contains 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 python | |
# | |
# (c) 2015, Edoburu, GPLv3+ licensed | |
# | |
# Based on https://github.com/ansible/ansible-modules-core/blob/devel/web_infrastructure/htpasswd.py | |
# | |
DOCUMENTATION = """ | |
module: htpasswd | |
short_description: manage PgBouncer userlist.txt entries | |
description: |
This file contains 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.db.models import Func, Value | |
class DateTrunc(Func): | |
""" | |
To support using DATE_TRUNC('text', "field") in SQL | |
Example:: | |
order_totals = (orders |
This file contains 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
""" | |
Parent object mixin, also available at: https://gist.github.com/vdboor/7f7865df748ed8949ba5 | |
""" | |
from functools import lru_cache | |
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist | |
from django.db import models | |
from django.http import Http404 | |
from django.urls import reverse |
This file contains 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
""" | |
An create+update view in a single class. | |
""" | |
from django.views.generic.detail import SingleObjectTemplateResponseMixin | |
from django.views.generic.edit import ModelFormMixin, ProcessFormView | |
class BaseCreateOrUpdateView(ModelFormMixin, ProcessFormView): | |
""" | |
Merging the logic of Django's |
This file contains 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.core.exceptions import ImproperlyConfigured | |
from rest_framework import serializers | |
from rest_framework.serializers import SortedDictWithMetadata | |
from .utils import create_translated_fields_serializer | |
class TranslatedFieldsField(serializers.WritableField): | |
""" | |
Exposing translated fields for a TranslatableModel in REST style. | |
""" |
This file contains 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 oscar.apps.catalogue.abstract_models import AbstractProduct, | |
from parler.models import TranslatableModel, TranslatedFields | |
class Product(AbstractProduct, TranslatableModel): | |
""" | |
Add translations to the product model. | |
""" | |
# Provide translated fields. |
This file contains 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
#!/bin/bash | |
# This hook is run after this virtualenv is activated. | |
root="$HOME/Sites/example.org/" | |
# Change to root unless already there. | |
if [[ "`pwd`" != "$root"* ]]; then | |
cd "$root" | |
fi |
This file contains 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
""" | |
Hide permission in the Django admin which are irrelevant, and not used at all. | |
""" | |
from django.contrib import admin | |
from django.contrib.auth.admin import GroupAdmin, UserAdmin | |
from django.contrib.auth.models import Group, User | |
class PermissionFilterMixin(object): | |
def formfield_for_manytomany(self, db_field, request=None, **kwargs): |
This file contains 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
mkdir my-website.com | |
cd my-website.com | |
django-admin.py startproject mywebsite . -e py,rst,example,gitignore --template=https://github.com/edoburu/django-project-template/archive/django-fluent.zip |
This file contains 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
/** | |
* jQuery plugin for Django inlines | |
* | |
* - When a `.js-django-inlines` is present, it will automatically enable this script for it. | |
* - When `.js-add-form` is missing, an add button will be inserted manually. | |
* - Make sure a `.js-remove-form` element is present in the HTML. | |
* | |
* To customize the behavior, use different class names and manually call $formset.djangoInline(). | |
* This can also be used to manually connect the 'add' and 'delete' buttons. | |
* |