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 datetime | |
def date_range(start_date, end_date): | |
""" | |
Yields each date in a range of dates | |
Source for future reference: http://stackoverflow.com/a/1060330/4694834 | |
:param start_date: date to start the iteration | |
:type start_date: datetime.datetime | |
:param end_date: date to end the iteration |
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 django.db.models import Aggregate | |
class Round(Aggregate): | |
""" | |
Solution source for future reference: http://stackoverflow.com/a/34622417/4694834 | |
""" | |
function = 'ROUND' | |
template = '%(function)s(CAST(%(expressions)s AS NUMERIC), {decimals})' | |
name = 'Round' |
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 os | |
import re | |
from typing import List | |
class DotEnvReader: | |
""" | |
Usage: `DotEnvReader('path').read()` | |
""" |
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 copy import deepcopy | |
from django.contrib.admin import AdminSite | |
from django.test import TestCase | |
from django.utils.translation import ugettext_lazy as _ | |
from rest_framework import status | |
from rest_framework.response import Response | |
from rest_framework.test import APITestCase | |
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 django.conf import settings | |
from django.core.management.commands import compilemessages | |
class Command(compilemessages.Command): | |
def compile_messages(self, locations): | |
# If a received location match a locale set, send to compile | |
if not any(location[0].startswith(locale) for location in locations for locale in settings.LOCALE_PATHS): | |
return | |
super(Command, self).compile_messages(locations) |
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 django.core.management.commands import makemessages | |
class Command(makemessages.Command): | |
def handle(self, *args, **options): | |
options['ignore_patterns'] += ['env', 'venv'] | |
super(Command, self).handle(*args, **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
#!/usr/bin/env bash | |
NC='\033[0m' | |
ERROR='\033[0;31m' | |
SUCCESS='\033[0;32m' | |
SECTION='\033[1;33m' | |
function space () { | |
echo "" | |
printf "${1}${NC}\n" | |
echo "" |
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 datetime import datetime | |
import os | |
from dj_database_url import parse as db_parse | |
from django.conf import settings | |
from django.core.management import BaseCommand | |
from assets.utils import console_log | |
BACKUPS_PATH = os.path.join(settings.BASE_DIR, 'backups') |
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 datetime | |
from re import match | |
date_separator = r'(/|-|.)' | |
time_separator = r'(:|-|.)' | |
date_formats = '"D/M/YYYY" | "D-M-YYYY" | "D.M.YYYY"' | |
datetime_formats = '"D/M/YYYY H:M:S" | "D-M-YYYY H-M-S" | "D.M.YYYY H.M.S"' | |
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 to flatten an array object | |
* Example: [[1, 2, [3]], 4] -> [1, 2, 3, 4] | |
* @param: {Array} array: Array object to be flattened | |
*/ | |
function flatten (array) { | |
return array.reduce((flat, next) => flat.concat(next instanceof Array ? flatten(next) : next), []); | |
} |
OlderNewer