This file contains hidden or 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 string | |
import random | |
from django.db import models | |
def generate_random_number(len: int): | |
return "".join( | |
random.choice(string.ascii_lowercase + string.digits) for _ in range(len) | |
) |
This file contains hidden or 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 time | |
from datetime import datetime | |
import os | |
import boto3 | |
from botocore.exceptions import WaiterError | |
from botocore.waiter import create_waiter_with_client | |
from celery import shared_task | |
from .custom_waiter import waiter_model |
This file contains hidden or 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 sys | |
from django.core import serializers | |
def migrate(model, dest_db, size=2000, start=0, old_db="default"): | |
""" | |
Migrate data from one database to another database in chunks | |
Args: |
This file contains hidden or 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 collections import OrderedDict | |
from rest_framework.response import Response | |
from rest_framework import status | |
from rest_framework.renderers import JSONRenderer | |
class SuccessResponse: | |
'''Standardise API Responses and add additional keys''' |
This file contains hidden or 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 calculate_size(size): | |
""" | |
Calculates storage size and returns the value | |
A single record is 1kb | |
""" | |
for x in ["KB", "MB", "GB", "TB"]: | |
if size < 1000.0: | |
return "%3.1f %s" % (size, x) | |
size /= 1000.0 |
This file contains hidden or 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 base64 | |
from django.core.files.uploadedfile import SimpleUploadedFile | |
def image_to_base64(image) -> str: | |
"""Converts image to base64 string""" | |
return base64.b64encode(image.read()).decode() |
This file contains hidden or 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 typing import Union | |
import csv | |
from django.http import HttpResponse | |
from django.db.models import QuerySet | |
from rest_framework.response import Response | |
from xhtml2pdf import pisa | |
import pandas as pd |