Skip to content

Instantly share code, notes, and snippets.

.progress {
position: fixed;
top: 0;
z-index: 1000;
height: 4px;
width: 100%;
border-radius: 2px;
background-clip: padding-box;
overflow: hidden;
}
@contextmanager
def tenant(value):
"""
Context manager for tenants. Used to set and cleanup tennant.
param, value, can be Tenant object or id.
Using the context context manager
```python
with tenant(1):
Profile.objects.get(pk=1)
class TenantAwareManager(Manager):
def get_queryset(self):
tenant_id = current_tenant_id()
# If the manager was built from a queryset using
# SomeQuerySet.as_manager() or SomeManager.from_queryset(),
# we want to use that queryset instead of TenantAwareQuerySet.
if self._queryset_class != QuerySet:
return super().get_queryset().filter(tenant__id=tenant_id)
@Webreaper
Webreaper / docker-compose.yml
Last active July 26, 2024 13:44
Sample Docker-compose file which shows how to set up Sonarr, Radarr, Prowlarr, Lidarr, QBittorrent and a VPN container so that all all traffic from the containers is routed through the VPN. Also includes Plex and get_iplayer containers, which are not routed through the VPN.
# Docker compose to set up containers for all services you need:
# VPN
# Sonarr, Radarr, Lidarr, Qbittorrent
# Non-VPN
# Plex, get_iplayer
# Before running docker-compose, you should pre-create all of the following folders.
# Folders for Docker State:
# /volume1/dockerdata. - root where this docker-compose.yml should live
# /volume1/dockerdata/plex - Plex config and DB
# /volume1/dockerdata/sonarr - Sonarr config and DB
@marcus-at-localhost
marcus-at-localhost / app.scss
Last active August 17, 2021 17:00
[Standalone Bootstrap 5 Utilities for Bootstrap 4] Use the new Bootstrap 5 utilities in your Bootstrap 4 project https://v5.getbootstrap.com/docs/5.0/utilities/api/ #bootstrap #utilities
/**
* -- Overwrite Bootstrap Vars
*/
$grid-breakpoints: (
xs: 0,
sm: 576px,
@int-ua
int-ua / import_file.py
Created December 28, 2017 19:38
Import management command for django-import-export
# https://gist.github.com/bmihelac/434fceb6ba8e752f08d3
# https://github.com/django-import-export/django-import-export/issues/332
from __future__ import unicode_literals
import mimetypes
from django.core.management.base import BaseCommand, CommandError
from django.utils import termcolors
from django.utils.encoding import force_text
@anschaef
anschaef / bootstrap-4-sass-mixins-cheat-sheet.scss
Last active April 12, 2024 08:49
Bootstrap 4 Sass Mixins [Cheat sheet with examples]
/* -------------------------------------------------------------------------- */
// All Bootstrap 4 Sass Mixins [Cheat sheet]
// Updated to Bootstrap v4.5.x
// @author https://anschaef.de
// @see https://github.com/twbs/bootstrap/tree/master/scss/mixins
/* -------------------------------------------------------------------------- */
/*
// ########################################################################## */
// New cheat sheet for Bootstrap 5:
.bd-callout {
padding: 1.25rem;
margin-top: 1.25rem;
margin-bottom: 1.25rem;
border: 1px solid #eee;
border-left-width: .25rem;
border-radius: .25rem
}
.bd-callout h4 {
@alican
alican / django_field_update_checker.txt
Last active September 17, 2023 08:46
check if django model fields changed after save
class DjangoModel(models.Model):
@classmethod
def from_db(cls, db, field_names, values):
instance = super().from_db(db, field_names, values)
instance._state.adding = False
instance._state.db = db
instance._old_values = dict(zip(field_names, values))
return instance
@webjunkie
webjunkie / forms.py
Last active February 4, 2023 22:12
JSONFieldFormMixin for Django ModelForm with JSON field
# the mixin
class JSONFieldFormMixin(object):
"""
Given that a model has some kind of TextField ``json_storage_field`` with
a string of JSON formatted data inside, this mixin adds handling of this
field to a ModelForm.
It will read the text field, convert to Python dict, fill the form fields
that are given via ``json_fields`` and on saving will write this back to