Skip to content

Instantly share code, notes, and snippets.

View joshcartme's full-sized avatar

Josh Cartmell joshcartme

View GitHub Profile
@joshcartme
joshcartme / forms.py
Created September 10, 2012 18:20
Cartridge OrderForm to work with cartridge-tax
from django.contrib.localflavor.us.forms import USStateSelect
from cartridge.shop import checkout
from cartridge.shop.forms import OrderForm
from mezzanine.conf import settings
class OrderForm(OrderForm):
def __init__(self, request, step, *args,**kwrds):
@joshcartme
joshcartme / gist:3943826
Created October 24, 2012 04:26
cartridge order setup which adds in tax total
def custom_order_setup(self, request):
"""
Set order fields that are stored in the session, item_total
and total based on the given cart, and copy the cart items
to the order. Called in the final step of the checkout process
prior to the payment handler being called.
Adds tax to the order total.
"""
self.key = request.session.session_key
self.user_id = request.user.id
@joshcartme
joshcartme / gist:4179810
Created December 1, 2012 00:46
page_menu which takes a site_id and renders a menu from that site
import os
from mezzanine.pages.templatetags.pages_tags import page_menu
from mezzanine import template
from mezzanine.utils.sites import current_site_id
register = template.Library()
@register.render_tag
@joshcartme
joshcartme / gist:4552317
Last active December 11, 2015 05:28
Monkey patch filebrowser_safe's get_path to return the name specified in THEMES for the current host rather than '' thereby restricting that domain to a sub directory of the uploads dir. The specified directory is created if it does not exist.
import os
from copy import deepcopy
from django.conf import settings
from django.core.files.storage import default_storage
from mezzanine.core.request import current_request
from filebrowser_safe import functions
from filebrowser_safe.settings import DIRECTORY
@joshcartme
joshcartme / gist:4561200
Last active December 11, 2015 06:39
Middleware to enforce a sub directory of the media library is used based on the value associated with a host in the HOST_THEMES dictionary.
import os
from django.conf import settings
from django.http import HttpResponseRedirect
from filebrowser_safe.settings import DIRECTORY
class FilebrowserHostThemesDirectoryMiddleware(object):
@joshcartme
joshcartme / gist:5079906
Created March 4, 2013 04:20
Bootstrap dropdown usability
$(function()
{
var $dropdowns = $('li.dropdown'); // Specifying the element is faster for older browsers
/**
* Mouse events
*
* @description Mimic hoverIntent plugin by waiting for the mouse to 'settle' within the target before triggering
*/
$dropdowns
.on('mouseover', function() // Mouseenter (used with .hover()) does not trigger when user enters from outside document window
@joshcartme
joshcartme / gist:5130702
Last active December 14, 2015 18:39
Mezzanine Form ajax processing
# template tag
from mezzanine import template
from mezzanine.forms.forms import FormForForm
from mezzanine.pages.models import Page
register = template.Library()
@register.as_tag
def form_from_page(slug):
@joshcartme
joshcartme / vimeo_api.py
Created April 19, 2013 20:12
Uploads a video to Vimeo using https://github.com/dkm/python-vimeo
import os
import time
import urllib2
try:
import simplejson as json
except ImportError:
import json
import vimeo
@joshcartme
joshcartme / extend_page_menu.py
Created April 23, 2013 17:16
Pull in a menu from a different site than the current in a Mezzanine multi site setup.
from mezzanine.utils.sites import current_site_id
from mezzanine.pages.templatetags.pages_tags import page_menu
from mezzanine import template
register = template.Library()
@register.render_tag
def page_menu_for_site(context, token):
@joshcartme
joshcartme / editable_form.html
Last active December 28, 2015 06:48
Bootstrap modal Mezzanine editable form
{% load i18n future %}
<style>
.editable-form{
background: none!important;
}
</style>
{# Edit form #}
<form class="editable-form modal fade" method="post"