Skip to content

Instantly share code, notes, and snippets.

View aruseni's full-sized avatar
🟢
Lead Python Software Engineer

aruseni

🟢
Lead Python Software Engineer
View GitHub Profile
@aruseni
aruseni / admin.py
Last active October 19, 2017 18:00
Substituting Django User model
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import ugettext_lazy as _
from .forms import UserChangeForm, UserCreationForm
from .models import User
@aruseni
aruseni / fields.py
Created February 8, 2017 16:23
This is a TextField-based field with TextInput widget. This can be used instead of a CharField whenever you do not want to restrict the length of the content at the DB level (see http://stackoverflow.com/questions/4848964/postgresql-difference-between-text-and-varchar-character-varying for more info).
from django.db import models
from django import forms
class TextInputTextField(models.TextField):
def formfield(self, **kwargs):
kwargs.update({
"widget": forms.TextInput
})
@aruseni
aruseni / replace_text_nodes.py
Created September 19, 2018 14:47
A Python script that replaces all text nodes inside a `template` element with [TXT], used with Vue templates
import argparse
parser = argparse.ArgumentParser(description='Replace text nodes')
parser.add_argument('file', type=str)
args = parser.parse_args()
html = open(args.file).read()
def replace(content):
@aruseni
aruseni / deep_get.py
Created April 4, 2019 09:32
Gets a value following the specified path, if such value exists
def deep_get(dictionary, keys, default=None):
"""
Gets a value following the specified path, if it exists.
The keys are dot-separated.
Example:
deep_get({'most_visited': {'url': 'https://test.com/'}}, 'most_visited.url')
"""