Skip to content

Instantly share code, notes, and snippets.

View jordotech's full-sized avatar
🎯
Focusing

jordotech jordotech

🎯
Focusing
  • Austin, TX
  • 07:49 (UTC -05:00)
View GitHub Profile
@jordotech
jordotech / dashboard_section.html
Created December 23, 2018 19:23
Django Jet dashboard sections
<div class="dashboard-container columns_2 cf">
<div class="dashboard-column-wrapper">
<div class="dashboard-column ui-droppable ui-sortable">
<div class="dashboard-item collapsible ">
<div class="dashboard-item-header ui-sortable-handle">
<span class="dashboard-item-header-buttons"></span>
<span class="dashboard-item-header-title">test</span>
<div class="cf"></div>
</div>
<div class="dashboard-item-content" style="height: auto;">
@jordotech
jordotech / kitpart orderitem ids.txt
Created August 31, 2018 14:29
which orderitems are kitparts in the queryset
order_item_ids = [q.get('id') for q in queryset]
kitpart_orderitem_ids = [oid.get('item') for oid in OrderItemDetail.objects.values('item').filter(name='kitparent', id__in=order_item_ids)]
@jordotech
jordotech / test_script.txt
Created July 29, 2018 23:49
Dev must pass these verbal tests
1. Entity value belonging to multiple entities. caesar = food_dressing, food_salad_special.
App should recognizes that we want the salad
Expected flow:
user: "large caesar"
alexa: "Ok, I added one large caesar"
2. "ambiguous" entity asks for clarification
Expected flow:
@jordotech
jordotech / upload_s3.py
Created July 25, 2018 20:48
use boto3 to upload to s3
import boto3
client = boto3.client(
's3',
aws_access_key_id = settings.AWS_ACCESS_KEY_ID,
aws_secret_access_key = settings.AWS_SECRET_ACCESS_KEY,
)
dst = 'media/temp_pdf/somefile.jpg' # This is the destination path inside the bucket
client.upload_file('/my/local/somefile.jpg', 'mybucketname', dst)
@jordotech
jordotech / fix_permissions.py
Created July 16, 2018 23:15
Fix proxy permissions management command Django 1.9
import sys
from django.contrib.auth.management import _get_all_permissions
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.core.management.base import BaseCommand
from django.apps import apps
from django.utils.encoding import smart_unicode
class Command(BaseCommand):
help = "Fix permissions for proxy models."
@jordotech
jordotech / query.txt
Created April 24, 2018 14:09
ER export psql query
SELECT 'postgresql' AS dbms,t.table_catalog,t.table_schema,t.table_name,c.column_name,c.ordinal_position,c.data_type,c.character_maximum_length,n.constraint_type,k2.table_schema,k2.table_name,k2.column_name FROM information_schema.tables t NATURAL LEFT JOIN information_schema.columns c LEFT JOIN(information_schema.key_column_usage k NATURAL JOIN information_schema.table_constraints n NATURAL LEFT JOIN information_schema.referential_constraints r)ON c.table_catalog=k.table_catalog AND c.table_schema=k.table_schema AND c.table_name=k.table_name AND c.column_name=k.column_name LEFT JOIN information_schema.key_column_usage k2 ON k.position_in_unique_constraint=k2.ordinal_position AND r.unique_constraint_catalog=k2.constraint_catalog AND r.unique_constraint_schema=k2.constraint_schema AND r.unique_constraint_name=k2.constraint_name WHERE t.TABLE_TYPE='BASE TABLE' AND t.table_schema NOT IN('information_schema','pg_catalog') \g /tmp/er.txt;
def mc():
from mailchimp3 import MailChimp
api_key = settings.MAILCHIMP_API_KEY
data = {
"id": "store_001",
"list_id": "3dae751fe9",
"name": "Jordan Local",
"domain": "larue.ngrok.io",
"email_address": "[email protected]",
from django.db.models.signals import post_save
import mailchimp3
@receiver(post_save, sender=Cart)
def send_cart_data_to_mailchimp(sender, instance, raw, created, using, **kwargs):
# https://developer.mailchimp.com/documentation/mailchimp/reference/ecommerce/stores/carts/
if not created:
return
data = {
'id':instance.id,
@jordotech
jordotech / g.py
Created October 6, 2017 22:59
geocoder.google()
import geocoder
def get_shop_coordinates(shop):
if len(shop.postalcode) and len(shop.street) > 1:
address_to_check = '%s %s' % (shop.street, shop.postalcode)
g = geocoder.google(address_to_check)
ret = {}
if g.lat <> 0 and g.lng <> 0:
ret['latitude'] = g.lat
ret['longitude'] = g.lng
return ret
@jordotech
jordotech / views.py
Last active September 26, 2017 20:38
pending_orderitem_options view
from product.modules.configurable.models import ConfigurableProduct, ProductVariation
from satchmo_store.shop.models import OrderItem
def pending_orderitem_options(request, product_id):
cp = ConfigurableProduct.objects.get(pk=product_id) # this is the url argument
child_ids = [v.product_id for v in cp.productvariation_set.all()] # find the cp's child product ids
orderitems = OrderItem.objects.filter(product_id__in=child_ids) # find the order items that match any of the children product ids
data = {} # The table in the view will be built from this dictionary
for oi in orderitems: # we step through the order items and build the needed data broken down by variation
v = ProductVariation.objects.get(pk=oi.product_id)