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
""" | |
# Password validation | |
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators | |
# Your password can’t be too similar to your other personal information. | |
# Your password must contain at least 10 characters. | |
# Your password can’t be a commonly used password. | |
# Your password can’t be entirely numeric. | |
# Your password must contain at least 1 symbol: ()[]{}|\`~!@#$%^&*_-+=;:'",<>./? | |
# Your password must contain at least 1 number, 0-9. |
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
""" | |
To use this decorator, add it to the view function you want to rate limit. | |
from authentication.decorators import dynamic_rate_limit | |
@dynamic_rate_limit() | |
def login_view(request): | |
The values can be changed based on a Config model that stores values in json. | |
""" |
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 time | |
from unittest import skipIf | |
from django.contrib.staticfiles.testing import StaticLiveServerTestCase | |
from django.conf import settings | |
from django.test.client import Client | |
# Selenium imports | |
from selenium import webdriver | |
from selenium.webdriver.common.by import By |
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
package com.myproject.mypackage.config; | |
import org.flywaydb.core.Flyway; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.boot.CommandLineRunner; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
@Configuration |
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
on run argv | |
local basePath | |
set basePath to item 1 of argv | |
tell application "iTerm2" | |
create window with default profile | |
end tell | |
set repos to {"repo-1", "repo-2", "repo-3"} |
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 import template | |
register = template.Library() | |
@register.filter(name="truncate_with_ellipses") | |
def truncate_with_ellipses(value: str, max_length: int) -> str: | |
""" | |
Confine a string to a max length, replace last three characters with ellipses | |
""" | |
if len(value) <= max_length: | |
return value |
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 import template | |
from django.contrib.auth import get_user_model | |
from django.contrib.auth.models import Group | |
register = template.Library() | |
User = get_user_model() | |
@register.filter(name="user_in_group") | |
def user_is_in_group(user: User, allowed_groups: str) -> bool: | |
""" |
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
{### FILTERS ###} | |
<select id="filter1" name="filter1"> | |
<option value="" selected disabled>Filter 1</option> | |
<option value="1">One</option> | |
<option value="2">Two</option> | |
</select> | |
<select id="filter2" name="filter2"> | |
<option value="" selected disabled>Filter 2</option> | |
<option value="1">One</option> | |
<option value="2">Two</option> |
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.db import migrations | |
from myapp.models import MyModel | |
def convert_mymodel_status(apps, schema_editor, reverse: bool | None = False): | |
""" | |
Convert "OLD STATUS" status to "NEW STATUS" | |
Or reverses these changes | |
""" | |
status = "NEW STATUS" if reverse else "OLD STATUS" | |
updated_status = "OLD STATUS" if reverse else "NEW STATUS" |
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.db.models import Count, Min | |
unique_fields = ['field_1', 'field_2'] | |
duplicates = ( | |
MyModel.objects.values(*unique_fields) | |
.order_by() | |
.annotate(min_id=Min('id'), count_id=Count('id')) | |
.filter(count_id__gt=1) | |
) |