This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'woocommerce_shipping_init', 'set_default_product_weight', 1 ); | |
function set_default_product_weight( ) { | |
if ( ! is_admin() ) { | |
foreach ( WC()->cart->get_cart() as $item_id => $values ) { | |
$_product = $values['data']; | |
if ( empty( $_product->weight ) ) { | |
$_product->weight = 1.00; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function register_teams_taxonomy() { | |
$labels = array( | |
'name' => __( 'Teams', 'taxonomy general name' ), | |
'singular_name' => __( 'Team', 'taxonomy singular name' ), | |
'search_items' => __( 'Search Teams' ), | |
'all_items' => __( 'All Teams' ), | |
'parent_item' => __( 'Parent Team' ), | |
'parent_item_colon' => __( 'Parent Team:' ), | |
'edit_item' => __( 'Edit Team' ), | |
'update_item' => __( 'Update Team' ), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Filter team products from main shop only on frontend on shop, category, and tag archives | |
*/ | |
function exclude_team_products( $query ) { | |
$archive_query = $query->is_post_type_archive('product') && $query->is_main_query(); | |
$cat_tag_query = $query->is_tax( array('product_cat', 'product_tag') ) && $query->is_main_query(); | |
if ( !is_admin() && $archive_query || !is_admin() && $cat_tag_query ) { | |
$taxquery = array( | |
array( | |
'taxonomy' => 'product_team', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
====================================== | |
Setting up Nginx, uWSGI and Python3 | |
====================================== | |
First off, I'm traditionally a PHP developer, but am looking at moving across to Python. I really struggled to find decent documentation on how to get a server up and running for deploying Python web applications from the point of view of someone coming from PHP. The main problems I came across with documentation were: | |
1) Only showed you how to run the server for a single web application. | |
2) Only showed you how to configure the app, not the server it was running on. | |
My preferred workflow for development is by setting up a new VM in VMware Fusion and then forwarding through all requests to that VM via /etc/hosts. This might not be the optimal way to get things up and running, but it works for me. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from premailer import Premailer | |
from django.conf import settings | |
from django.core.mail import EmailMultiAlternatives | |
from django.dispatch import receiver, Signal | |
from django.shortcuts import get_object_or_404 | |
from django.template import loader | |
from django.template.loader import get_template | |
from django.contrib.auth.models import User |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get(self, request, company_id, **kwargs): | |
company_id = self.kwargs['company_id'] | |
company = get_object_or_404(Company, pk=company_id) | |
company_timezone = timezone.activate(company.timezone) | |
range_from = timezone.now() + timedelta(days=-30) | |
if 'from' in request.GET: | |
range_from = datetime.strptime( | |
request.GET['from'], | |
'%m-%d-%Y' | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from premailer import Premailer | |
from django.conf import settings | |
from django.core.mail import EmailMultiAlternatives | |
from django.dispatch import receiver, Signal | |
from django.template import loader | |
@receiver(welcome_notification) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
accounts = Account.objects.annotate(client_count=Count('client'), users_count=Count('users')) | |
account_data = [] | |
for account in accounts: | |
account_data.append( | |
{ | |
'id': account.id, | |
'name': account.name, | |
'clients': account.client_count, | |
'users': account.users_count | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
version: '2' | |
services: | |
nginx: | |
image: "#####.dkr.ecr.us-east-1.amazonaws.com/nginx:latest" | |
cpu_shares: 50 | |
mem_limit: 104857600 | |
logging: | |
driver: awslogs | |
options: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ModelDiffMixin(object): | |
""" | |
Ref: https://stackoverflow.com/questions/1355150/django-when-saving-how-can-you-check-if-a-field-has-changed | |
""" | |
def __init__(self, *args, **kwargs): | |
super(ModelDiffMixin, self).__init__(*args, **kwargs) | |
self.__initial = self._dict | |
@property | |
def _dict(self): |