Skip to content

Instantly share code, notes, and snippets.

Avatar

Paulo Alvarado czpython

View GitHub Profile
@czpython
czpython / center_geo.py
Last active Feb 7, 2018 — forked from amites/center_geo.py
calculate center coordinate from a list of latitude, longitude pairs
View center_geo.py
# -*- coding: utf-8 -*-
import math
def center_geolocation(geolocations):
"""
Provide a relatively accurate center lat, lon returned as a list pair, given
a list of list pairs.
ex: in: geolocations = ((lat1,lon1), (lat2,lon2),)
out: (center_lat, center_lon)
View render_plugin.py
from django.contrib.auth.models import AnonymousUser
from django.test.client import RequestFactory
from sekizai.context import SekizaiContext
from cms.toolbar.toolbar import CMSToolbar
def get_request(path='/'):
request = RequestFactory().get(path)
request.current_page = None
request.session = {'cms_edit': False}
View keybase.md

Keybase proof

I hereby claim:

  • I am czpython on github.
  • I am czpython (https://keybase.io/czpython) on keybase.
  • I have a public key ASBm_w1_0dKMIAQ6fdfQff8rBQkC1_W53yll1Qb6jCY1rQo

To claim this, I am signing this object:

View check_for_bad_numchild.py
# -*- coding: utf-8 -*-
from django.core.management.base import NoArgsCommand
from cms.models import CMSPlugin
MESSAGE = """
Found {} corrupt plugins.
Here's their ids:
{}
@czpython
czpython / serialize_filer.py
Last active Jul 12, 2016
create fixture of django filer
View serialize_filer.py
from django.core import serializers
from django.db.models import get_app, get_models
from django.db.models.query import QuerySet
def export_filer_models(output_file=None):
"""
Exports filer models to output_file.
"""
app = get_app('filer')
View list_parent_language_plugin_corruptions.py
# -*- coding: utf-8 -*-
from django.conf import settings
from django.core.management.base import NoArgsCommand
from cms.models import CMSPlugin, Page
class Command(NoArgsCommand):
help = 'Lists plugins whose parent language does not match.'
View fix_parent_placeholder_plugin_corruption.py
# -*- coding: utf-8 -*-
from django.core.management.base import NoArgsCommand
from cms.models import CMSPlugin
class Command(NoArgsCommand):
help = 'Fixes plugins whose parent is in another placeholder'
def handle_noargs(self, **options):
View widgets.py
# -*- coding: utf-8 -*-
from django_select2.widgets import Select2MultipleWidget
class ReadonlySelect2MultipleWidget(Select2MultipleWidget):
def render_inner_js_code(self, id_, *args):
"""
Renders all the JS code required for this widget.
:return: The rendered JS code which will be later enclosed inside ``<script>`` block.
@czpython
czpython / hvad_admin.py
Last active Dec 17, 2015
Hack to display hvad translated fields in the admin's changelist.
View hvad_admin.py
from django.contrib.admin.util import label_for_field
from hvad.admin import TranslatableAdmin as BaseTranslatableAdmin
class TranslatableAdmin(BaseTranslatableAdmin):
"""
Translation friendly admin base class.
Allows user to display translated fields in the admin changelist.
"""
@czpython
czpython / usesthis_interview_parser.py
Created Apr 28, 2013
Parses the interview files provided by http://usesthis.com
View usesthis_interview_parser.py
# -*- coding: utf-8 -*-
from re import match, findall, DOTALL
from os import listdir
from os.path import dirname, abspath
from unipath import Path
import yaml
You can’t perform that action at this time.