View migration_file.py
# -*- coding: utf-8 -*- | |
# Generated by Django 1.9.9 on 2017-02-11 16:54 | |
from __future__ import unicode_literals | |
from django.db import migrations, models | |
from django.template.defaultfilters import slugify | |
def migrate_docs_forward(apps, schema_editor): | |
documents = apps.get_model("documents", "Documents") |
View validators.py
# @brief | |
# Performs file upload validation for django. The original version implemented | |
# by dokterbob had some problems with determining the correct mimetype and | |
# determining the size of the file uploaded (at least within my Django application | |
# that is). | |
# @author dokterbob | |
# @author jrosebr1 | |
import mimetypes |
View views.py
class JSONResponseMixin(object): | |
''' | |
This is a slightly modified version from django-braces project | |
(https://github.com/brack3t/django-braces) | |
''' | |
content_type = None | |
json_dumps_kwargs = None | |
def get_content_type(self): # pragma: no cover | |
return self.content_type or "application/json" |
View reset_app.py
from io import StringIO | |
from optparse import make_option | |
from django.apps import apps | |
from django.core.management.base import AppCommand, CommandError | |
from django.core.management.color import no_style | |
from django.core.management import call_command | |
from django.db import connections, transaction, DEFAULT_DB_ALIAS |
View wordpress_fabfile.py
import os | |
from time import time | |
from fabric.api import sudo, run, task, env, cd, get, local | |
from fabric.context_managers import shell_env | |
env.hosts = ['yourhost'] | |
env.user = 'yoursshuser' | |
env.password = 'yoursshpassword' | |
# env.key_filename = '~/yourkey.pem' |
View bulk_users_from_csv.py
import csv | |
from django.core.management.base import BaseCommand, CommandError | |
from django.contrib.auth import get_user_model | |
from django.utils.crypto import get_random_string | |
class Command(BaseCommand): | |
"""manage.py import_users --csv='/Users/user/usuariosweb.csv' --encoding='iso-8859-1'""" | |
help = 'Imports users based on a CSV file' |
View async_download_files.py
import os | |
import asyncio | |
import aiohttp # pip install aiohttp | |
import aiofiles # pip install aiofiles | |
REPORTS_FOLDER = "reports" | |
FILES_PATH = os.path.join(REPORTS_FOLDER, "files") | |
def download_files_from_report(urls): |