Skip to content

Instantly share code, notes, and snippets.

View andreif's full-sized avatar
👾
invading spaces

Andrei Fokau andreif

👾
invading spaces
View GitHub Profile
# Django 1.7
class InlineAdminFormsetMixin(object):
inline_admin_formset_class = InlineAdminFormSet
def get_inline_formsets(self, request, formsets, inline_instances,
obj=None):
inline_admin_formsets = []
for inline, formset in zip(inline_instances, formsets):

Export hg repo to github

$ pyenv virtualenv 2.7.14 hg

$ pyenv shell hg

$ pip install "mercurial<4.6" "dulwich<0.19"

$ cat ~/.hgrc
def test_admin(self):
for m, ma in admin.site._registry.items():
pfx = 'admin:%s_%s_' % (m._meta.app_label, m._meta.model_name)
self.client.get(reverse(pfx + 'changelist'))
if ma.has_add_permission(request=mock.Mock(user=self.user)):
self.client.get(reverse(pfx + 'add'))
for pk in m.objects.values_list('id', flat=True):
self.client.get(reverse(pfx + 'change', args=(pk,)))
# coding=utf-8
import json
from urlparse import urljoin
import celery.states
from django import http
from django.conf import settings
from django.conf.urls import url
from django.contrib import admin
from django.http import Http404
# coding=utf-8
from __future__ import absolute_import
import time
from functools import wraps
from django.core.cache import cache
def cached(func=None, ttl=60):
def decorator(func):
version: 2
steps: &steps
steps:
- checkout
- run: {command: sudo pip install tox}
- run: {command: tox}
- persist_to_workspace:
root: .
paths:
@admin.register(models.Some)
class SomeAdmin(ReadOnlyAdminMixin, admin.ModelAdmin):
list_filter = (
'related__field',
input_filter('related_id'),
('other', select_filter(admin.RelatedFieldListFilter)),
('country', select_filter(admin.AllValuesFieldListFilter)),
)
list_display = (
'id',
import os
repo_path = os.path.dirname(os.path.abspath(__file__))
xml_path = repo_path + '/coverage.xml'
with open(xml_path) as fp:
xml = fp.read()
if 'filename="/' not in xml:
xml = xml.replace('filename="', 'filename="' + repo_path + '/')
with open(xml_path, 'w+') as fp:
import logging
from django.template.defaultfilters import filesizeformat
from django.utils import log, termcolors
np = termcolors.PALETTES[termcolors.NOCOLOR_PALETTE]
lp = termcolors.PALETTES[termcolors.LIGHT_PALETTE]
dp = termcolors.PALETTES[termcolors.DARK_PALETTE]
lp['HTTP_SUCCESS']['opts'] = ('bold',)
dp['HTTP_SUCCESS']['opts'] = ('bold',)
from django.contrib import admin
class ReadOnlyAdminMixin:
def get_readonly_fields(self, request, obj=None):
fields = list(self.fields or []) + \
[f.name for f in self.model._meta.fields]
_id = self.model._meta.pk.name
fields = [_id] + list({f: f for f in fields if f != _id}.keys())
return fields