Skip to content

Instantly share code, notes, and snippets.

View darthwade's full-sized avatar

Vadym Petrychenko darthwade

View GitHub Profile
@darthwade
darthwade / email.py
Created July 19, 2020 01:28
Django email templates where subject and text/html body are in the same file
from django.conf import settings
from django.core import mail
from django.template.context import make_context
from django.template.loader import get_template
from django.template.loader_tags import BlockNode, ExtendsNode
class BaseEmailMessage(mail.EmailMultiAlternatives):
template_name = None
context = {}
'use strict';
jest.unmock('../CheckboxWithLabel');
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import CheckboxWithLabel from '../CheckboxWithLabel';
describe('CheckboxWithLabel', () => {
from django.core.urlresolvers import reverse
from rest_framework import status
from rest_framework.test import APITestCase
from foodster.apps.core.models import Account
class AccountTests(APITestCase):
def test_create_account(self):
"""
Ensure we can create a new account object.
"""
@darthwade
darthwade / Makefile
Last active August 29, 2015 14:05
Makefile for django reusable apps
PROJECT := demo
LOCAL_PATH := $(CURDIR)/src
VIRTUAL_ENV := $(CURDIR)/bin
PYTHON_PATH := $(LOCAL_PATH)
PYTHON_BIN := $(VIRTUAL_ENV)/scripts
SETTINGS := development
DJANGO_SETTINGS_MODULE = $(PROJECT).settings.$(SETTINGS)
DJANGO_POSTFIX := --settings=$(DJANGO_SETTINGS_MODULE) --pythonpath=$(PYTHON_PATH)
@darthwade
darthwade / email.py
Created August 15, 2014 14:05
Django Gmail SMTP configuration
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = '{username}@gmail.com'
EMAIL_HOST_PASSWORD = '{password}'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = '{username}@gmail.com'
@darthwade
darthwade / logging.py
Created August 1, 2014 20:25
Django logging configuration.
from __future__ import unicode_literals
import os
from .base import BASE_DIR
LOGS_DIR = os.path.join(BASE_DIR, 'tmp/logs')
LOGGING = {
'version': 2,
'disable_existing_loggers': False,
'filters': {
>>> # Grab geonames from http://download.geonames.org/export/dump/
>>> COUNTRY = 'UA'
>>> DOWNLOAD_URL = 'http://download.geonames.org/export/dump/{country}.zip'.format(country=COUNTRY)
>>> FILENAME = '{country}.txt'.format(country=COUNTRY)
>>> from urllib2 import urlopen
>>> import zipfile
>>> from cStringIO import StringIO
>>> rawzip = urlopen(DOWNLOAD_URL).read()
>>> zipdata = StringIO()
>>> zipdata.write(rawzip)
>>> # Grab timezones from http://download.geonames.org/export/dump/
>>> DOWNLOAD_URL = 'http://download.geonames.org/export/dump/timeZones.txt'
>>> from urllib2 import urlopen
>>> lines = urlopen(DOWNLOAD_URL).read().split('\n')[1:]
>>> from apps.gis.models import TimeZone, Country
>>> for l in lines:
>>> if not len(l): break
>>> country_code, id, gmt_offset, dst_offset, raw_offset = l.split()
>>> try:
>>> country = Country.objects.get(id=country_code)
>>> # Grab countries from https://github.com/umpirsky/country-list/blob/master/country/cldr
>>> LANG = 'uk'
>>> FIELD_SUFFIX = '_uk'
>>> DOWNLOAD_URL = 'https://raw.githubusercontent.com/umpirsky/country-list/master/country/cldr/{lang}/country.txt'
>>> from urllib2 import urlopen
>>> lines = urlopen(DOWNLOAD_URL.format(lang=LANG)).read().split('\n')
>>> from apps.gis.models import Country
>>> for l in lines:
>>> if not len(l): break
>>> l = l.decode('utf-8')
@darthwade
darthwade / settings.py
Last active August 29, 2015 14:04
S3BotoStorage subclass for media and static buckets.
from __future__ import unicode_literals
import os
from boto.s3.connection import SubdomainCallingFormat
# AWS S3
AWS_S3_ACCESS_KEY_ID = os.getenv('AWS_S3_ACCESS_KEY_ID')
AWS_S3_SECRET_ACCESS_KEY = os.getenv('AWS_S3_SECRET_ACCESS_KEY')
AWS_S3_BASE_URL = 's3.amazonaws.com'
# AWS_S3_FILE_BUFFER_SIZE = 5242880