Skip to content

Instantly share code, notes, and snippets.

Paulo Alvarado czpython

View GitHub Profile
@czpython
czpython / get_mws_orders.py
Last active Dec 11, 2015
Script to test out the Python MWS API. It takes all orders created on 01/10/2013 and outputs them to a csv file.
View get_mws_orders.py
# -*- coding: utf-8 -*-
"""
Sample script for mws api.
"""
import csv
from collections import OrderedDict
from mws import mws
# A module containing the API credentials
@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
@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.
"""
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 / kill_deleted_files.sh
Created May 18, 2014
Kill processes using deleted files. This frees up memory used by files that were unlinked but are kept open by a process.
View kill_deleted_files.sh
lsof +L1 | grep 'deleted' | awk '{print $2}' | xargs kill -9
@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')
@czpython
czpython / middleware.py
Created Aug 1, 2014
Redirect /en/ to /
View middleware.py
from django.conf import settings
from django.core.urlresolvers import is_valid_path
from django.http import HttpResponseRedirect
from django.middleware.locale import LocaleMiddleware
from django.utils.translation import (
activate as activate_language,
deactivate as deactivate_language,
get_language,
get_language_from_path
)
@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 current_stack_print.py
import traceback
def view_current_stack():
for line in traceback.format_stack():
print line.strip()
@czpython
czpython / view_migration_changes.py
Last active Aug 29, 2015
Script to view any missing migrations for models. Will not work with native django migrations
View view_migration_changes.py
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
from django.conf import settings
from django.core.management.base import NoArgsCommand
from south.exceptions import NoMigrations
from south.migration import Migrations
You can’t perform that action at this time.