Skip to content

Instantly share code, notes, and snippets.

View Kniyl's full-sized avatar

Mathias Ettinger Kniyl

  • Toulouse / France
View GitHub Profile
@Kniyl
Kniyl / admin.py
Last active August 29, 2015 14:00
reusable django app to create django-modeltranslation fields into mezzanine models
from copy import deepcopy
from django.contrib import admin
from django.utils.translation import activate, get_language
from modeltranslation.admin import TranslationAdmin, TranslationTabularInline
from mezzanine.conf import settings
from mezzanine.core.admin import TabularDynamicInlineAdmin
applications = settings.INSTALLED_APPS
def save_obj_for_every_language(obj):
"""
@Kniyl
Kniyl / conf.diff
Last active August 29, 2015 14:18
Version checker for django 1.8 / modeltranslation 0.8.1
diff --git a/mezzanine/utils/conf.py b/mezzanine/utils/conf.py
index 1f9c321..5d8bef2 100644
--- a/mezzanine/utils/conf.py
+++ b/mezzanine/utils/conf.py
@@ -110,9 +110,15 @@ def set_dynamic_settings(s):
warn("USE_MODETRANSLATION setting is set to True but django-"
"modeltranslation is not installed. Disabling it.")
else:
- # Force i18n so we are assured that modeltranslation is active
- s["USE_I18N"] = True
@Kniyl
Kniyl / translator.diff
Created May 12, 2015 17:38
Quick fix for django-modeltranslation with Django 1.8
diff --git a/modeltranslation/translator.py b/modeltranslation/translator.py
index 18bc743..c6edfb6 100644
--- a/modeltranslation/translator.py
+++ b/modeltranslation/translator.py
@@ -150,7 +150,12 @@ def add_translation_fields(model, opts):
# Rebuild information about parents fields. If there are opts.local_fields, field cache would be
# invalidated (by model._meta.add_field() function). Otherwise, we need to do it manually.
if len(opts.local_fields) == 0:
- model._meta._fill_fields_cache()
+ try:
@Kniyl
Kniyl / fields.diff
Created May 12, 2015 23:08
mezzanine.generic.fields module fix for related_model
diff --git a/mezzanine/generic/fields.py b/mezzanine/generic/fields.py
index 277b04d..cd3160c 100644
--- a/mezzanine/generic/fields.py
+++ b/mezzanine/generic/fields.py
@@ -36,9 +36,6 @@ class BaseGenericRelation(GenericRelation):
attribute for the ``to`` argument.
"""
kwargs.setdefault("object_id_field", "object_pk")
- to = getattr(self, "related_model", None)
- if to:
@Kniyl
Kniyl / conf.py
Last active August 29, 2015 14:21 — forked from stephenmcd/conf.py
# This is the gunicorn config file for the websocket server.
worker_class = "geventwebsocket.gunicorn.workers.GeventWebSocketWorker"
bind = "0.0.0.0:9000"
workers = 1
timeout = 10000000000
loglevel = "error"
proc_name = "websocket-server"
# Modify paths here as required - allows websocket server to run
@Kniyl
Kniyl / models.py
Created July 7, 2015 15:46
Proxy model
class Proxy(Page):
"""
A general content type for creating links to existing pages
in the page menu. Act as a placeholder for the first child
page if no page is explicitely being proxied.
"""
target = models.ForeignKey("Page", related_name="proxies", blank=True, null=True)
class Meta:
class A1(object):
def __init__(self, **kwargs):
for k,v in kwargs.items():
setattr(self, k, v)
class A2(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
class B1(A1):