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 / 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()
@mkoistinen
mkoistinen / _Instruction.md
Last active August 29, 2015 14:12
Automatically start MySQL on system start on Yosemite

The Official MySQL Installer for Yosemite doesn't work.

See/monitor: http://bugs.mysql.com/bug.php?id=74434

It appears they're working on a fix, in the meantime, you can set MySQL to automatically start on system start by:

Instructions:

  1. Put the adjoining file com.oracle.mysql.plist into /System/Library/LaunchDaemons
  2. Adjust [machinename] in line 17 of the plist accordingly.
  3. Set the perms to root:wheel and 0644.
@mkoistinen
mkoistinen / README.TXT
Last active August 29, 2015 14:15
TemplateTag: render_model_add_block
# templatetag: render_model_add_block
## Description
Currently django CMS has a templatetag: render_model_add, which is used like this: `{% render_model_add mymodel_instance %}`. Which then renders an icon of a "plus" symbol onto the page. This plus symbol is bound to a double-click handler which, which double-clicked, renders a modal dialog for creating a new instance of the model that `mymodel_instances` was created from.
This is great, but offers limited flexibility when creating front-end operator UX for projects.
This re-implementation is extremely similar, but instead of linking the modal dialog add-form to a plus icon, it allows the developer to wrap any arbitrary content. This could be as simple as text, but could also be a generic representation of the type of content that the operator wishes to create.