Skip to content

Instantly share code, notes, and snippets.

View mkoistinen's full-sized avatar

Martin Koistinen mkoistinen

  • Chapel Hill, NC, USA
View GitHub Profile
@mkoistinen
mkoistinen / language_middleware.py
Last active December 17, 2015 13:59
Redirects requests that are not prefixed with a language segment to the right content in the default language. Also, if a URL is encountered that has a language prefix when it shouldn't, it will remove it. This is originally based on http://ilian.i-n-i.org/language-redirects-for-multilingual-sites-with-django-cms/ but modified to support django-…
# -*- coding: utf-8 -*-
import re
from django.conf import settings
from django.http import HttpResponseRedirect
from django.utils import translation
from django.utils.translation import get_language_from_request
#
@mkoistinen
mkoistinen / gist:7685612
Created November 28, 2013 00:45
This Redmine init script works great for me for my install on unicorn + Nginx + Ubuntu 12.04 LTS. I hacked it up from the GitLab init script.
#! /bin/sh
# REDMINE for Nginx + Unicorn init script
# improvised from the awesome work maintained by the GitLab team:
# Credit to: @randx and others at GitLab
### BEGIN INIT INFO
# Provides: redmine
# Required-Start: $local_fs $remote_fs $network $syslog redis-server
@mkoistinen
mkoistinen / admin.py
Created April 7, 2014 12:45
Effectively adds a "ForeignKey" to a 3rd-party application's model (Post in this example) without monkey-patching the code. This is accomplished by adding a ManyToMany field instead on the other side of the desired relationship on the Item model (in this example), then, removing it from Item's admin and adding a ModelChoice field and Select widg…
# -*- coding: utf-8 -*-
# Django 1.6
from django.contrib import admin
from django.forms import ModelChoiceField
from django.forms.models import ModelForm
from blog.models import Post
from .models import Item
@mkoistinen
mkoistinen / admin.py
Last active August 29, 2015 13:58
Effectively adds a "ForeignKey" to a 3rd-party application's model (Post in this example) without monkey-patching the code. This is accomplished by adding a ManyToMany field instead on the other side of the desired relationship on the Item model (in this example), then, removing it from Item's admin and adding a ModelChoice field and Select widg…
# -*- coding: utf-8 -*-
# Django 1.6
from django.contrib import admin
from django.forms import ModelChoiceField
from django.forms.models import ModelForm
from blog.models import Post
from .models import Item
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/en/staff/cms/page/7/None/preview/
Django Version: 1.6.2
Python Version: 2.7.2
Installed Applications:
('django.contrib.auth',
@mkoistinen
mkoistinen / gist:49ff1181e6720a2324bd
Created May 8, 2014 14:48
settings.py file for the first 5 videos posted at the Google+ community: django CMS Virtual User Group
import os
gettext = lambda s: s
"""
Django settings for project project.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
@mkoistinen
mkoistinen / gist:125e367efe26656cd3b6
Created June 16, 2014 08:06
Detecting 'opacity' of an image for text wrapping or whatever...
function AlphaImage(img){
var threshold = 40,
canvas,
ctx,
width,
height,
imgData;
width = img.width;
height = img.height;
@mkoistinen
mkoistinen / language_chooser.html
Created June 25, 2014 19:16
The custom language choose template I used in the screencast: I18N Apps + django CMS (http://youtu.be/CcADEc80Jps)
{% load i18n menu_tags %}{% get_available_languages as languages %}{% get_language_info for LANGUAGE_CODE as lang %}
<li><span class="current-language">{{ lang.code|upper }}<i class="drop"></i></span>
<ul>{% for language in languages %}
<li class="{% ifequal current_language language.0 %}selected{% endifequal %}"><a href="{% page_language_url language.0 %}">{{ language.0|language_name_local|capfirst }}</a></li>{% endfor %}
</ul>
</li>
### Keybase proof
I hereby claim:
* I am mkoistinen on github.
* I am mkoistinen (https://keybase.io/mkoistinen) on keybase.
* I have a public key whose fingerprint is 9840 EA07 2C83 5E63 0391 9A4D 7864 8B53 2FBC E49C
To claim this, I am signing this object:
@mkoistinen
mkoistinen / gist:a887098974702041bc9c
Created November 19, 2014 15:26
This is like render_model_block but for plugins!
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django import template
from classytags.core import Tag, Options
from classytags.arguments import Argument
register = template.Library()