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
class PersonalModule(modules.LinkList): | |
title = _('Welcome,') | |
draggable = False | |
deletable = False | |
collapsible = False | |
template = 'ecms_dashboard/modules/personal.html' | |
def init_with_context(self, context): | |
super(PersonalModule, self).init_with_context(context) |
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
class BaseViewMixin(object): | |
def dispatch(self, request, *args, **kwargs): | |
# Set earlier to let get_loggedin_user() and get_context_user() work. | |
# They run before the get() and post() methods are called. | |
self.request = request | |
self.args = args | |
self.kwargs = kwargs | |
# Run checks before entering the view. |
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. | |
* |
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
""" | |
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
#!/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
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
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
""" | |
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
""" | |
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 |
OlderNewer