Skip to content

Instantly share code, notes, and snippets.

View volgoweb's full-sized avatar

Dima Koldunov Python Developer volgoweb

  • Российская Федерация
View GitHub Profile
@volgoweb
volgoweb / conftest.py
Created February 2, 2022 07:53 — forked from shaypal5/conftest.py
Temp environment variables for pytest
import os
import pytest
try:
from.temp_env_var import TEMP_ENV_VARS, ENV_VARS_TO_SUSPEND
except ImportError:
TEMP_ENV_VARS = {}
ENV_VARS_TO_SUSPEND = []
@volgoweb
volgoweb / money_transfer.py
Created August 19, 2021 14:23
19_08_2021 Interview (Shared)
import uuid
from decimal import Decimal
from django.db import transaction
# send a request to PayPal.com to transfer money
from .services import transfer_money_via_paypal
class BillingAccount(models.Model):
######################################################
# To Do: How can we refactor code to make that faster?
######################################################
def func(user, moderator_ids):
for post in Post.objects.all().order('?'):
if user.pk in moderator_ids:
post.updated_at = timezone.now()
post.save()
@volgoweb
volgoweb / models.py
Created February 11, 2020 08:29
refactor unpublishing the posts
# .. import section ..
class Post(models.Model):
author = models.ForeignKey(CustomUserModel)
title = models.CharField(max_length=200)
text = models.CharField(max_length=15000)
is_published = models.BooleanField()
@volgoweb
volgoweb / celery_1.py
Created February 11, 2020 08:26
Find a mistake in celery task
#################
# Find a mistake:
#################
from django.core.cache import cache
from celery import shared_task
@shared_task()
def clear_blog_item_cache(article):
@volgoweb
volgoweb / custom_pagination.py
Last active November 25, 2019 06:00
pagination frontend with Django
#
# File templatetags/custom_pagination.py
#
from django import template
register = template.Library()
@register.simple_tag
@volgoweb
volgoweb / git-reset-author.sh
Created July 16, 2019 15:19 — forked from bgromov/git-reset-author.sh
Git: reset author for ALL commits
#!/bin/sh
# Credits: http://stackoverflow.com/a/750191
git filter-branch -f --env-filter "
GIT_AUTHOR_NAME='Newname'
GIT_AUTHOR_EMAIL='new@email'
GIT_COMMITTER_NAME='Newname'
GIT_COMMITTER_EMAIL='new@email'
" HEAD
# Generated by Django 2.2 on 2019-06-06 14:38
"""
If you add a migration that uses content types and/or permissions you should apply the functions to fill particular tables in DB.
"""
from django.db import migrations
from django.contrib.contenttypes.management import create_contenttypes
from django.contrib.auth.management import create_permissions
from django.apps import apps as _apps
class BaseDataStructure(object):
"""The class is intended for definition contract objects which might be used as argument for various classes.
The example of using:
class SomeServiceInput(BaseDataStructure):
__accessible__ = {
'email': str,
'template_type': int,
}
from collections import OrderedDict
members = [
#{'name': 'member', 'skills': set('skill1', 'skill2', ...)}
{'name': 'Jan', 'skills': set(('PHP', 'HTML'))},
{'name': 'Bep', 'skills': set(('HTML', 'CSS'))},
{'name': 'Leo', 'skills': set(('CSS', 'PHP'))}
]
project = OrderedDict([
#'task': ['skill', nrhourswork]
('A', ['PHP', 2]),