Skip to content

Instantly share code, notes, and snippets.

View christianwgd's full-sized avatar

Christian Wiegand christianwgd

  • Atruvia AG
  • Münster, Germany
View GitHub Profile
@christianwgd
christianwgd / forms.py
Created April 11, 2024 09:10
Use of django-friendly-captcha in a contact form
# -*- coding: utf-8 -*-
import re
from django import forms
from django.conf import settings
from django.utils.translation import gettext_lazy as _
from friendly_captcha.fields import FrcCaptchaField
from contact.models import Filter, ContactMessage
@christianwgd
christianwgd / bs4-2-bs5.sh
Last active August 17, 2023 10:51
Bash script for basic migration from django-bootstrap4 to django-bootstrap5
find . -type f -name \settings.py -exec sed -i '' -e "s|'bootstrap4',|'django_bootstrap5',|g" {} \;
find . -type f -name \*.html -exec sed -i '' -e "s|bootstrap4\/bootstrap4.html|django_bootstrap5\/bootstrap5.html|g" {} \;
find . -type f -name \*.html -exec sed -i '' -e "s|bootstrap4_extra_head|bootstrap5_extra_head|g" {} \;
find . -type f -name \*.html -exec sed -i '' -e "s|bootstrap4_extra_script|bootstrap5_extra_script|g" {} \;
find . -type f -name \*.html -exec sed -i '' -e "s|bootstrap4_title|bootstrap5_title|g" {} \;
find . -type f -name \*.html -exec sed -i '' -e "s|bootstrap4_content|bootstrap5_content|g" {} \;
find . -type f -name \*.html -exec sed -i '' -e "s| bootstrap4 | django_bootstrap5 |g" {} \;
find . -type f -name \*.html -exec sed -i '' -e "s|data-toggle=|data-bs-toggle=|g" {} \;
find . -type f -name \*.html -exec sed -i '' -e "s|data-dismiss=|data-bs-dismiss=|g" {} \;
find . -type f -name \*.html -exec sed -i '' -e "s|data-targe=|data-bs-targe=|g" {} \;
@christianwgd
christianwgd / group_required_mixins.py
Created September 12, 2022 07:14
Django GroupRequiredMixin to check if user is in one or more groups
class GroupRequiredMixin(AccessMixin):
group_required = None
def get_group_required(self):
"""Get which group's membership is required"""
if any([
self.group_required is None,
not isinstance(self.group_required, (list, tuple, str))
]):
raise ImproperlyConfigured(
@christianwgd
christianwgd / middleware
Last active August 1, 2021 16:03
django-request log real ip behind proxy
# -*- coding: utf-8 -*-
from django.conf import settings
from request.middleware import RequestMiddleware
class RequestProxyMiddleware(RequestMiddleware):
"""
Place this middleware to your project directory and
replace the django-request request.middleware.RequestMiddleware
with this middleware in the settings MIDDLEWARE