Skip to content

Instantly share code, notes, and snippets.

View starsinmypockets's full-sized avatar

Paul Walker starsinmypockets

View GitHub Profile
@starsinmypockets
starsinmypockets / gist:4525889
Last active December 11, 2015 01:48
Ugh I need to iterate over the select options and add some markup to the end of each radio input
# order-form.html
{% load catname %}
<form id = "order-form">
{% for form in forms %}
<div id="gun-{{ forloop.counter }}">
{% for field in form.fields %}
<div id="{{ field }}-item" class="item">
<h3>{{ field|catname }}</h3>
{% for choice in form.field.choices %} {# <-- Help me out here #}
@starsinmypockets
starsinmypockets / myfieldtemplate.html
Last active December 11, 2015 05:59
Basic example of formulation implementation for django modelform
{% block basic %}
{% if not nolabel %}{{ field.label_tag }}{% endif %}
<input type="{{ field_type|default:"text" }}" name="{{ field.html_name }}" id="{{ field.auto_id }}" value="{{ field.value|default:"" }}" class="{{ field.css_classes }} {{ extra_classes }}" />
{{ field.help_text }}
{% endblock %}
@starsinmypockets
starsinmypockets / gist:4556828
Created January 17, 2013 15:38
Underscore to human
from django import template
from django.template.defaultfilters import stringfilter
register = template.Library()
@register.filter
@stringfilter
def catname(cat):
return cat.replace('_', ' ').capitalize()
@starsinmypockets
starsinmypockets / gist:4556831
Created January 17, 2013 15:39
Load text snips
from django import template
from django.conf import settings
from main.models import Verbiage
import logging
register = template.Library()
## @@TODO - add clean method: trim leading/trailing ' or " or whitespace
## @@TODO - exception for bad query
def getverb(parser, token):
@starsinmypockets
starsinmypockets / getradiomagic.py
Last active December 11, 2015 06:08
Pass context variables to template tags.
from django import template
import main.models # @@TODO this might be a reason to put frame components in a separate file some day
import logging
logger = logging.getLogger(__name__)
register = template.Library()
@register.tag(name="getradiomagic")
def getradiomagic(parser, token):
{ 'Category 1' : [
{
'attribute 1' : someVal,
'attribute next' : anotherVal,
'attribute final' : lastVal,
},
{
'attribute 1' : someVal,
'attribute next' : anotherVal,
'attribute final' : lastVal,
@starsinmypockets
starsinmypockets / gist:4617190
Created January 24, 2013 02:31
Get data attribute from radio input and sort containing div.
/**
* Sort by data-position field
*/
$('.sort-inputs > .form-item').each(function () {
$(this).find('.radio-item').each(function () {
$(this).attr('data-position', function () {
return $(this).find('input[type="radio"]').attr('data-position');
});
});
git status # should be clean
git pull unfuddle master # nothing to update
## if this fucks up: git reset --hard
# then add your files and gitignore
git status # gitignore updated
git commit #commit local
git push unfuddle master # push upstream
git pull unfuddle master #redundant
# make sure everything's kosher
@starsinmypockets
starsinmypockets / gist:4644751
Created January 26, 2013 21:31
UWSGI Command Line Jawn
/path/to/env/bin/uwsgi --http :8000 --chdir /path/to/env/proj/proj --wsgi-file /path/to/env/proj/proj/wsgi.py --virtualenv /path/to/env/bin --env DJANGO_SETTINGS_MODULE=proj.settings
""" Imports json in a standard format to Django objects """
import json, re, logging, sqlite3
from redisclg import RedisBayes
logging.basicConfig(filename='/root/py-proj/clg-env/clg_proj/logfile.log',level=logging.DEBUG)
class BaseImporter(object):
# @@TODO add file_path param to init
def __init__(self, src, list_id, db_src="clg_proj.sqlite3"):
self.list_id = list_id