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
response_customer = stripe.Customer.create( | |
email=user.email, | |
description=f"EMPLOYER - {user.get_full_name}", | |
name=user.get_full_name, | |
phone=user.profile.phone_number, | |
) | |
user1.stripe_id = response_customer.stripe_id | |
user1.save() |
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
# user 1 - employer | |
user1, _ = User.objects.get_or_create( | |
email="[email protected]", | |
first_name="Employer", | |
last_name="Testowy", | |
city="Białystok", | |
) | |
user1.set_unusable_password() |
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 django.contrib.auth.base_user import AbstractBaseUser | |
from django.db import models | |
class User(AbstractBaseUser): | |
""" | |
User model. | |
""" | |
USERNAME_FIELD = "email" |
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 enum import Enum | |
class BaseEnum(Enum): | |
@classmethod | |
def choices(cls): | |
return [(key.name, key.value) for key in cls] | |
class GroupTypeChoices(BaseEnum): |
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 django.contrib.auth.base_user import BaseUserManager | |
from django.utils.translation import ugettext_lazy as _ | |
class UserManager(BaseUserManager): | |
""" | |
Custom User manager to be used with default auth User model. | |
""" | |
use_in_migrations = True |
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 find(key, dictionary): | |
for k, v in dictionary.items(): | |
if k == key: | |
yield v | |
elif isinstance(v, dict): | |
for result in find(key, v): | |
yield result | |
elif isinstance(v, list): | |
for d in v: | |
if isinstance(d, dict): |
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
sudo useradd -s /bin/bash -d /home/user_name/ -m -G sudo,docker user_name |
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 lxml.html.clean import Cleaner | |
def html_cleaner(response): | |
""" | |
Cleaner for request response. | |
""" | |
cleaner = Cleaner( | |
page_structure=True, | |
meta=True, |
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 os | |
import requests | |
from user_agent import generate_user_agent | |
# pip install user_agent requests | |
img_path = os.path.join('/path/to/your/image') | |
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 pdfminer.pdfdocument import PDFDocument | |
from pdfminer.pdfparser import PDFParser | |
from pdfminer.pdftypes import resolve1 | |
with open('/path/to/file.pdf', 'rb') as f: | |
parser = PDFParser(f) | |
doc = PDFDocument(parser) | |
parser.set_document(doc) | |
pages = resolve1(doc.catalog['Pages') | |
pages_count = pages.get('Count', 0) |