DROP A TABLE django
python manage.py dbshell
\dt drop table
python manage.py migrate --fake <app_name> zero
find . -path "/migrations/.py" -not -name "init.py" -delete
import csv | |
import unicodedata | |
import sys | |
def normalize_and_convert(input_filepath, output_filepath): | |
""" The function manage to open a file with utf and converting safely into cp1252, | |
make adjustments to accept more formats """ | |
# Open the input file with UTF-8 encoding | |
with open(input_filepath, mode='r', encoding='utf-8', newline='') as infile: |
# Copy this lines on <BASE_PROJECT_PATH> | |
echo 'Some lines' > some_file.some_extension | |
echo 'some other lines' >> some_file.some_extension |
HEllo |
import requests | |
from os import getenv | |
class MailgunWrapper: | |
""" Principal mailgun app """ | |
PRIV_KEY = getenv("MAILGUN_PRIV_KEY", "") | |
FROM_EMAIL = getenv("MAILGUN_FROM_EMAIL", "") | |
def __init__(self, *args, **kwargs): |
from tempfile import TemporaryDirectory as TempD | |
import subprocess # nosec | |
from os import path | |
import base64 | |
import shlex | |
def generate_tex_pdf(tex_string): | |
""" Generic Function to convert a template string to pdf """ |
import re | |
import unicodedata | |
def escape_text(s): | |
# Convert from python escape text to latex format. | |
"""^*¨ÑLIOPL:_:(/&%&()=(/&WQ·W$ERTY +´^*Ñ´plqj""" | |
# This block is omited | |
s = s.replace("·", "") | |
s = s.replace("¨", "") |
""" Little snippet for looking for permissions and add them to a group """ | |
from django.contrib.auth.models import Group | |
from django.contrib.auth.models import Permission | |
from <your-model-folder>.models import <MODEL>, <MODEL-N> | |
gp = Group.objects.get(name="<GROUP_NAME>") | |
qs = Permission.objects.filter(codename__icontains="<FOLDER-NAME>") |
DROP A TABLE django
python manage.py dbshell
\dt drop table
python manage.py migrate --fake <app_name> zero
find . -path "/migrations/.py" -not -name "init.py" -delete
""" | |
Pythonic means "coding beautifully in harmony with the language to get the | |
maximum benefits from python" | |
Learn to recognize non-pythonic APIs and to recognize good code. | |
Dont get distracted by PEP8. Focus first on Pythonic vs NonPythonic(P vs NP) | |
When needed, write an adapter class to convert from the former to the latter | |
========================================================== | |
""" |
# Send a file by email with S3 | |
message = EmailMessage(subject, body, from_email, bcc=recipient_list) | |
message.attach(FILENAME, mymodel.myfilefield.read()) |