An open source, non-profit web search engine
Minor fixes
Daoud Clarke0436815ba2f1
diff --git a/mwmbl/background.py b/mwmbl/background.pyindex 28d7aee..0415169 100644--- a/mwmbl/background.py+++ b/mwmbl/background.py@@ -2,7 +2,7 @@Script that updates data in a background process.Also contains Django Background Tasks for periodic quota maintenance:- - flush_search_counts: syncs Redis monthly counters → DB every 10 minutes+ - sync_search_counts: syncs Redis monthly counters → DB once per hour"""import loggingimport sys@@ -96,14 +96,14 @@ def sync_search_counts():Step 2 (Redis → Postgres): update UsageBucket with the live Redis countsso Postgres stays current as a durable backup."""- from datetime import datetime+ from datetime import datetime, timezonefrom django.core.cache import cachefrom mwmbl.models import UsageBucketfrom mwmbl.quota import MONTHLY_TTL, _monthly_key, get_all_monthly_keys- now = datetime.utcnow()+ now = datetime.now(timezone.utc)# Step 1: seed Redis from Postgres, taking the max of the two values.# Postgres may lag behind (up to one sync interval), so if Redis already hasdiff --git a/mwmbl/models.py b/mwmbl/models.pyindex f4c25f3..6e2750b 100644--- a/mwmbl/models.py+++ b/mwmbl/models.py@@ -1,4 +1,3 @@-import randomimport secretsfrom django.contrib.postgres.fields import ArrayField@@ -8,237 +7,7 @@ from django.utils import timezonefrom ninja import ModelSchemafrom ninja.orm import create_schema-_ADJECTIVES = [- # A- "able", "abiding", "agile", "airy", "alabaster", "alert", "alpine", "amber",- "ample", "ancient", "ardent", "arctic", "arid", "ashen", "astral", "astute",- "atomic", "auburn", "august", "avid", "azure",- # B- "balmy", "bare", "benevolent", "blazed", "blazing", "blithe", "blissful",- "blooming", "blushing", "bold", "boreal", "boundless", "brave", "breezy",- "bright", "brisk", "broad", "bronze", "buoyant", "burnished",- # C- "calm", "candid", "carefree", "caramel", "cedar", "celestial", "cerulean",- "chatty", "cheerful", "chestnut", "chill", "civic", "clear", "clever",- "clover", "cloudy", "coastal", "cobalt", "comet", "cool", "copper", "coral",- "cordial", "cosmic", "courageous", "cozy", "creative", "crisp", "crystal",- "curly", "cyan",- # D- "dainty", "dapper", "daring", "dark", "dashing", "dauntless", "dawn",- "decisive", "deep", "devoted", "dewy", "diligent", "dim", "drifting",- "durable", "dusty", "dynamic",- # E- "eager", "early", "earnest", "earthy", "easy", "ebony", "effervescent",- "electric", "elegant", "eloquent", "emerald", "empty", "enduring", "endless",- "energetic", "enlightened", "epic", "eternal", "everlasting", "even", "exact",- "exquisite",- # F- "fabled", "fair", "faithful", "famous", "fancy", "far", "farsighted", "fast",- "felicitous", "fern", "fervent", "festive", "fierce", "fiery", "fine", "firm",- "first", "flexible", "flint", "floral", "flourishing", "flowing", "foggy",- "fond", "forest", "forward", "fragrant", "frank", "free", "fresh", "frosty",- "frozen", "full",- # G- "gallant", "gentle", "genuine", "gifted", "gilded", "glacial", "glad",- "gleaming", "glorious", "glowing", "golden", "good", "graceful", "gracious",- "grand", "granite", "grateful", "great", "green", "grey", "grounded",- # H- "halcyon", "hardy", "harmonious", "hazy", "hearty", "heroic", "high",- "hollow", "honest", "hopeful", "humble",- # I- "icy", "idle", "idyllic", "illumined", "imaginative", "immense", "impeccable",- "indigo", "infinite", "ingenious", "inland", "inner", "inspired", "intrepid",- "inventive", "invincible", "iron", "ivory",- # J- "jade", "jolly", "jovial", "joyful", "joyous", "jubilant", "judicious", "just",- # K- "keen", "kind", "kindhearted", "kinetic",- # L- "lambent", "large", "lasting", "lavender", "leafy", "lean", "legendary",- "lemon", "level", "light", "lively", "lone", "long", "loyal", "lucid",- "lucky", "luminous", "lunar", "lush", "lyric",- # M- "magic", "magnanimous", "majestic", "maple", "marble", "mature", "measured",- "meditative", "mellifluous", "mellow", "merciful", "methodical", "mighty",- "mild", "mindful", "misty", "modest", "moonlit", "mossy", "mountainous", "muted",- # N- "narrow", "natural", "neat", "nimble", "noble", "nocturnal", "nordic",- "north", "nurturing",- # O- "oak", "observant", "obsidian", "oceanic", "olive", "open", "opulent",- "optimistic", "orange", "orderly", "outer",- # P- "pale", "passionate", "patient", "peaceful", "pearly", "perennial",- "persevering", "petal", "pine", "pioneering", "plain", "playful", "poised",- "polar", "polished", "pragmatic", "principled", "promising", "proud", "pure",- "purple", "purposeful",- # Q- "quiet", "quickened", "quintessential",- # R- "radiant", "rapid", "rare", "ready", "receptive", "reflective", "refreshing",- "regal", "reliable", "resilient", "resolute", "resourceful", "respectful",- "responsive", "rich", "righteous", "roaming", "robust", "rooted", "rosy",- "rough", "round", "royal", "ruby", "rugged", "running", "rustic", "rustling",- # S- "sacred", "sage", "sandy", "sapphire", "scholarly", "seasoned", "serene",- "seraphic", "sharp", "shining", "silent", "silken", "silver", "simple",- "sincere", "skillful", "sleek", "slender", "slow", "smart", "smooth", "snowy",- "sociable", "solar", "solemn", "solid", "sonic", "soulful", "sovereign",- "spirited", "steadfast", "sterling", "still", "stoic", "stormy", "stout",- "strategic", "strong", "sturdy", "sublime", "subtle", "sunny", "supernal",- "supple", "supportive", "swift",- # T- "talented", "tall", "tawny", "tender", "tenacious", "thoughtful", "thriving",- "tidal", "tidy", "timeless", "timely", "tireless", "tranquil", "transparent",- "triumphant", "true", "trusty", "trusting", "twilight",- # U- "ultra", "unassuming", "undaunted", "unwavering", "upbeat", "uplifting",- "unyielding", "upright",- # V- "valiant", "vast", "velvet", "venerable", "venturous", "verdant", "vernal",- "versatile", "vibrant", "vigilant", "visionary", "vital", "vivacious", "vivid",- # W- "warm", "watchful", "wavy", "whimsical", "wholesome", "willing", "windswept",- "wise", "witty", "wondrous", "worthy", "woven",- # X Y Z- "xenial", "xeric", "yielding", "young", "youthful", "zealous", "zenith",- "zephyr", "zestful", "zippy",- # extras to reach 500- "affable", "aloft", "animated", "artful", "balanced", "bountiful", "bracing",- "candent", "capacious", "certain", "clean", "collected", "composed", "confident",- "conscientious", "considerate", "constant", "deft", "deliberate", "dependable",- "dignified", "discerning", "effulgent", "elevated", "eminent", "endeared",- "equable", "established", "expansive", "expressive", "felicific", "forthright",- "fulsome", "generative", "graced", "hallowed", "idiomatic", "imaginable",- "immovable", "incisive", "inquisitive", "insightful", "integral", "intuitive",- "jaunty", "knowing", "limber", "limpid", "lofty", "manifest",- "masterful", "meticulous", "musing", "nascent", "nuanced",- "openhearted", "ordinate", "pacific", "pellucid", "perceptive", "pious",- "plentiful", "precise", "pristine", "progressing",- "reasoned", "refined", "reposed", "revered", "rhapsodic", "sapient",- "sanguine", "settled", "sheer", "sideral", "spiraling",- "stately", "stellar", "temperate", "thorough", "tonal",- "torchlit", "tractable", "transcendent", "unbounded", "unfailing", "unfettered",-]--_NOUNS = [- # A- "adder", "alder", "algae", "aloe", "anchor", "antler", "anvil", "apex",- "apple", "arch", "arrow", "ash", "aspen", "atlas", "atoll", "aurora",- "autumn", "avalanche", "axe",- # B- "badger", "bark", "barn", "basalt", "basin", "bay", "beacon", "bear",- "beaver", "beech", "bell", "berry", "birch", "bison", "blade", "bloom",- "blossom", "bluebell", "bluff", "boar", "bog", "boulder", "bough", "bramble",- "brant", "bream", "brine", "brook", "buck", "bud", "burrow", "buttercup",- "butte",- # C- "canoe", "canopy", "canyon", "cape", "cardinal", "carp", "catfish", "cave",- "cedar", "channel", "charcoal", "chestnut", "chisel", "chough", "cicada",- "cinder", "cirque", "cirrus", "clam", "cliff", "clover", "cobble", "cobalt",- "cockle", "col", "comet", "compass", "condor", "coral", "cormorant", "corrie",- "cove", "coyote", "crane", "crater", "creek", "crest", "crocus", "crow",- "crystal", "curlew", "current", "cypress",- # D- "dale", "darter", "dawn", "deer", "delta", "dew", "dipper", "dock",- "dolphin", "dormouse", "dotterel", "dove", "dragonfly", "drumlin", "dunlin",- "dune", "dyke",- # E- "eagle", "echo", "eel", "egret", "elder", "elk", "elm", "ember",- "escarpment", "estuary",- # F- "falcon", "fawn", "fern", "field", "fiord", "firecrest", "finch", "fir",- "fjord", "flame", "flint", "flood", "flora", "fluke", "flycatcher", "foam",- "fog", "forest", "forge", "fossil", "fox", "frost", "fulmar",- # G- "gale", "gannet", "garganey", "garnet", "geyser", "glacier", "glade",- "glen", "godwit", "goldcrest", "goldfinch", "goosander", "gorge", "goshawk",- "granite", "gravel", "grove", "grouse", "guillemot", "gulch", "gull", "gust",- # H- "hamster", "hare", "harrier", "hartebeest", "hawk", "hazel", "heath",- "hedgehog", "heron", "hill", "hillside", "holly", "hoopoe", "horizon",- "hornet",- # I- "ibex", "ibis", "inlet", "iris", "island", "ivory",- # J- "jackal", "jackdaw", "jasper", "jay", "juniper",- # K- "kelp", "kestrel", "kingfisher", "kite", "kiwi", "knoll", "knot",- # L- "lagoon", "lake", "lapwing", "larch", "lark", "lava", "leaf", "ledge",- "lemur", "leveret", "lichen", "limestone", "linden", "linnet", "lion",- "loam", "loess", "locust", "lodge", "loon", "lotus", "lynx",- # M- "mackerel", "magpie", "mallard", "maple", "marl", "marsh", "martin",- "meadow", "merganser", "merlin", "mesa", "midstream", "milfoil", "mink",- "mist", "moorland", "moose", "moss", "moth", "mountain", "mudflat",- "mudstone", "muskrat",- # N- "narwhal", "needle", "newt", "nightingale", "nightjar", "noctule", "north",- "nutmeg", "nuthatch",- # O- "oak", "opal", "orca", "osprey", "otter", "outcrop", "owl", "oyster",- "oystercatcher",- # P- "partridge", "pass", "pasture", "peak", "peat", "pebble", "peewit",- "pelican", "pennant", "perch", "peregrine", "petal", "pheasant", "pigeon",- "pine", "pintail", "pipit", "plover", "plume", "pochard", "polecat",- "pond", "poplar", "porcupine", "prairie", "ptarmigan", "puffin",- # Q- "quartz", "quill",- # R- "rabbit", "raven", "reed", "reedbed", "reef", "ridge", "rift", "rill",- "ringlet", "ripple", "robin", "rock", "rockpool", "roe", "roost",- "rosefinch", "root", "rowan", "runnel", "rush", "rushes",- # S- "sage", "salmon", "sandbar", "sandpiper", "sandstone", "sapphire", "scree",- "seabird", "seagrass", "sedge", "serin", "sett", "shale", "shearwater",- "shoal", "shore", "shoveler", "shrew", "shrike", "sierra", "siskin",- "skimmer", "skua", "skylark", "slate", "sluice", "smew", "snipe",- "snowdrop", "snowfield", "snout", "sora", "sorrel", "sparrow", "spire",- "spoonbill", "spruce", "squall", "squirrel", "stag", "starling", "stem",- "steppe", "stoat", "stone", "stonefly", "stork", "storm", "stream",- "stubble", "summit", "sundew", "sunfish", "swallow", "swamp", "swan",- "swift", "sycamore",- # T- "talon", "tanager", "tarpon", "teal", "tern", "thistle", "thorn",- "thornbill", "thicket", "thrush", "tide", "timber", "titlark", "toad",- "torchwood", "torrent", "trail", "treecreeper", "trogon", "trout", "tuatara",- "tumulus", "tundra", "turnstone", "turtle", "twite",- # U- "upland",- # V- "vale", "valley", "veery", "verdure", "vetch", "viburnum", "vireo",- "viper", "vixen", "vole",- # W- "wader", "wagtail", "warbler", "waterfowl", "watershed", "wave", "waxwing",- "weasel", "weir", "wheatear", "whinchat", "whitethroat", "wigeon", "wildcat",- "willow", "wolf", "woodcock", "woodland", "woodpecker", "wormwood", "wren",- "wryneck",- # Y Z- "yarrow", "yellowhammer", "yew", "zander", "zinnia", "zorilla",- # extras to reach 500- "acorn", "agate", "albatross", "alcove", "almond", "alp", "amaranth",- "amethyst", "anemone", "antelope", "arroyo", "azalea", "barnacle", "bayou",- "blizzard", "bracken", "brushwood", "buffalo",- "bulrush", "bunting", "bushtit", "buzzard", "capercaillie", "caribou",- "catkin", "chaffinch", "chalcedony", "chamomile", "cheetah", "cinnabar",- "cistus", "clough", "coho", "columbine", "coppice", "crag", "crake",- "crossbill", "crowberry", "dace", "daisy", "damselfly", "dandelion",- "dewdrop", "dhole", "dingo", "dunock", "earthworm", "echidna", "ermine",- "esker", "fen", "flounder", "flyway", "forb", "gallinule", "garfish",- "gecko", "geode", "gerbil", "gibbon", "ginkgo", "gloaming", "glowworm",- "gneiss", "gnu",-]---def generate_username():- for _ in range(10):- candidate = f"{random.choice(_ADJECTIVES)}_{random.choice(_NOUNS)}_{random.randint(100, 999)}"- if not MwmblUser.objects.filter(username=candidate).exists():- return candidate- # Extremely unlikely fallback- return f"user_{secrets.token_hex(6)}"+from mwmbl.usernames import generate_usernameclass MwmblUser(AbstractUser):@@ -398,6 +167,9 @@ class UsageBucket(models.Model):class Meta:unique_together = [('user', 'year', 'month')]+ indexes = [+ models.Index(fields=['year', 'month']),+ ]class UserBilling(models.Model):diff --git a/mwmbl/platform/api.py b/mwmbl/platform/api.pyindex 21bcc62..aa2b8e2 100644--- a/mwmbl/platform/api.py+++ b/mwmbl/platform/api.py@@ -489,6 +489,8 @@ def create_checkout(request, body: CheckoutRequest):"pro": settings.POLAR_PRODUCT_ID_PRO,}product_id = product_map[body.plan]+ if not product_id:+ raise InvalidRequest(f"Plan '{body.plan}' is not configured. Contact support.", status=503)billing = getattr(request.user, "billing", None)checkout_params = {"products": [product_id],@@ -533,7 +535,7 @@ def polar_webhook(request):billing.polar_customer_id = event.data.customer_id or billing.polar_customer_idbilling.polar_subscription_id = event.data.id or billing.polar_subscription_idbilling.save()- elif event.type == "subscription.revoked":+ elif event.type in ("subscription.revoked", "subscription.canceled"):user_id = event.data.metadata.get("user_id")user = MwmblUser.objects.filter(id=user_id).first()if user:diff --git a/mwmbl/platform/schemas.py b/mwmbl/platform/schemas.pyindex 3d95a6c..edc5f41 100644--- a/mwmbl/platform/schemas.py+++ b/mwmbl/platform/schemas.py@@ -2,6 +2,8 @@ from datetime import datetimefrom typing import Optional, Literalfrom ninja import Schema, ModelSchema, Field+from mwmbl.models import DomainSubmission+class UserProfileResponse(Schema):username: str@@ -36,8 +38,6 @@ class ResetPasswordRequest(Schema):key: strnew_password: str-from mwmbl.models import DomainSubmission-# ---------------------------------------------------------------------------# API key management schemasdiff --git a/mwmbl/quota.py b/mwmbl/quota.pyindex ee377b1..994c85c 100644--- a/mwmbl/quota.py+++ b/mwmbl/quota.py@@ -6,7 +6,7 @@ backend can be swapped without changing this code. The only Redis-specificcall is get_all_monthly_keys(), which uses SCAN via django-redis and is onlycalled by the background flush/reset jobs."""-from datetime import datetime+from datetime import datetime, timezonefrom django.core.cache import cache@@ -19,7 +19,7 @@ MONTHLY_TTL = 60 * 60 * 24 * 35 # 35 days in seconds# ---------------------------------------------------------------------------def _monthly_key(user_id: int, year: int | None = None, month: int | None = None) -> str:- now = datetime.utcnow()+ now = datetime.now(timezone.utc)y = year if year is not None else now.yearm = month if month is not None else now.monthreturn f"search:monthly:{user_id}:{y}:{m:02d}"@@ -39,14 +39,10 @@ def check_rate_limit(user_id: int) -> bool:Returns True if the request is allowed, False if the limit is exceeded."""key = _rate_key(user_id)- # add() sets the key only if it doesn't exist (atomic in Redis)- added = cache.add(key, 0, timeout=1)- if added:- # Key was just created; this is the first request in this window- cache.incr(key)+ # add() is atomic: sets key=1 with TTL only if absent (first request this second)+ if cache.add(key, 1, timeout=1):return True- count = cache.incr(key)- return count <= RATE_LIMIT+ return cache.incr(key) <= RATE_LIMIT# ---------------------------------------------------------------------------@@ -80,7 +76,7 @@ def get_all_monthly_keys() -> list[str]:Uses the underlying Redis SCAN command via django-redis.Only call this from background tasks, not from request handlers."""- now = datetime.utcnow()+ now = datetime.now(timezone.utc)pattern = f"search:monthly:*:{now.year}:{now.month:02d}"from django_redis import get_redis_connectionconn = get_redis_connection("default")diff --git a/mwmbl/tinysearchengine/search.py b/mwmbl/tinysearchengine/search.pyindex 47a82c2..466b499 100644--- a/mwmbl/tinysearchengine/search.py+++ b/mwmbl/tinysearchengine/search.py@@ -256,7 +256,10 @@ def _register_routes(r: Router | NinjaAPI, ranker: HeuristicRanker):"Rate limit exceeded: maximum 5 requests per second. Please slow down.",)- # Monthly quota pre-check (avoid incrementing if already over limit)+ # Monthly quota pre-check (avoid incrementing if already over limit).+ # Concurrent requests near the limit may both pass and slightly over-count —+ # this is intentional; hard enforcement via atomic DB transactions isn't worth+ # the complexity for occasional edge-case overage of a few requests.current_count = get_monthly_count(user.id)if current_count >= monthly_limit:upgrade_msg = _upgrade_message(user.tier)diff --git a/mwmbl/usernames.py b/mwmbl/usernames.pynew file mode 100644index 0000000..8421f35--- /dev/null+++ b/mwmbl/usernames.py@@ -0,0 +1,235 @@+import random+import secrets++_ADJECTIVES = [+ # A+ "able", "abiding", "agile", "airy", "alabaster", "alert", "alpine", "amber",+ "ample", "ancient", "ardent", "arctic", "arid", "ashen", "astral", "astute",+ "atomic", "auburn", "august", "avid", "azure",+ # B+ "balmy", "bare", "benevolent", "blazed", "blazing", "blithe", "blissful",+ "blooming", "blushing", "bold", "boreal", "boundless", "brave", "breezy",+ "bright", "brisk", "broad", "bronze", "buoyant", "burnished",+ # C+ "calm", "candid", "carefree", "caramel", "cedar", "celestial", "cerulean",+ "chatty", "cheerful", "chestnut", "chill", "civic", "clear", "clever",+ "clover", "cloudy", "coastal", "cobalt", "comet", "cool", "copper", "coral",+ "cordial", "cosmic", "courageous", "cozy", "creative", "crisp", "crystal",+ "curly", "cyan",+ # D+ "dainty", "dapper", "daring", "dark", "dashing", "dauntless", "dawn",+ "decisive", "deep", "devoted", "dewy", "diligent", "dim", "drifting",+ "durable", "dusty", "dynamic",+ # E+ "eager", "early", "earnest", "earthy", "easy", "ebony", "effervescent",+ "electric", "elegant", "eloquent", "emerald", "empty", "enduring", "endless",+ "energetic", "enlightened", "epic", "eternal", "everlasting", "even", "exact",+ "exquisite",+ # F+ "fabled", "fair", "faithful", "famous", "fancy", "far", "farsighted", "fast",+ "felicitous", "fern", "fervent", "festive", "fierce", "fiery", "fine", "firm",+ "first", "flexible", "flint", "floral", "flourishing", "flowing", "foggy",+ "fond", "forest", "forward", "fragrant", "frank", "free", "fresh", "frosty",+ "frozen", "full",+ # G+ "gallant", "gentle", "genuine", "gifted", "gilded", "glacial", "glad",+ "gleaming", "glorious", "glowing", "golden", "good", "graceful", "gracious",+ "grand", "granite", "grateful", "great", "green", "grey", "grounded",+ # H+ "halcyon", "hardy", "harmonious", "hazy", "hearty", "heroic", "high",+ "hollow", "honest", "hopeful", "humble",+ # I+ "icy", "idle", "idyllic", "illumined", "imaginative", "immense", "impeccable",+ "indigo", "infinite", "ingenious", "inland", "inner", "inspired", "intrepid",+ "inventive", "invincible", "iron", "ivory",+ # J+ "jade", "jolly", "jovial", "joyful", "joyous", "jubilant", "judicious", "just",+ # K+ "keen", "kind", "kindhearted", "kinetic",+ # L+ "lambent", "large", "lasting", "lavender", "leafy", "lean", "legendary",+ "lemon", "level", "light", "lively", "lone", "long", "loyal", "lucid",+ "lucky", "luminous", "lunar", "lush", "lyric",+ # M+ "magic", "magnanimous", "majestic", "maple", "marble", "mature", "measured",+ "meditative", "mellifluous", "mellow", "merciful", "methodical", "mighty",+ "mild", "mindful", "misty", "modest", "moonlit", "mossy", "mountainous", "muted",+ # N+ "narrow", "natural", "neat", "nimble", "noble", "nocturnal", "nordic",+ "north", "nurturing",+ # O+ "oak", "observant", "obsidian", "oceanic", "olive", "open", "opulent",+ "optimistic", "orange", "orderly", "outer",+ # P+ "pale", "passionate", "patient", "peaceful", "pearly", "perennial",+ "persevering", "petal", "pine", "pioneering", "plain", "playful", "poised",+ "polar", "polished", "pragmatic", "principled", "promising", "proud", "pure",+ "purple", "purposeful",+ # Q+ "quiet", "quickened", "quintessential",+ # R+ "radiant", "rapid", "rare", "ready", "receptive", "reflective", "refreshing",+ "regal", "reliable", "resilient", "resolute", "resourceful", "respectful",+ "responsive", "rich", "righteous", "roaming", "robust", "rooted", "rosy",+ "rough", "round", "royal", "ruby", "rugged", "running", "rustic", "rustling",+ # S+ "sacred", "sage", "sandy", "sapphire", "scholarly", "seasoned", "serene",+ "seraphic", "sharp", "shining", "silent", "silken", "silver", "simple",+ "sincere", "skillful", "sleek", "slender", "slow", "smart", "smooth", "snowy",+ "sociable", "solar", "solemn", "solid", "sonic", "soulful", "sovereign",+ "spirited", "steadfast", "sterling", "still", "stoic", "stormy", "stout",+ "strategic", "strong", "sturdy", "sublime", "subtle", "sunny", "supernal",+ "supple", "supportive", "swift",+ # T+ "talented", "tall", "tawny", "tender", "tenacious", "thoughtful", "thriving",+ "tidal", "tidy", "timeless", "timely", "tireless", "tranquil", "transparent",+ "triumphant", "true", "trusty", "trusting", "twilight",+ # U+ "ultra", "unassuming", "undaunted", "unwavering", "upbeat", "uplifting",+ "unyielding", "upright",+ # V+ "valiant", "vast", "velvet", "venerable", "venturous", "verdant", "vernal",+ "versatile", "vibrant", "vigilant", "visionary", "vital", "vivacious", "vivid",+ # W+ "warm", "watchful", "wavy", "whimsical", "wholesome", "willing", "windswept",+ "wise", "witty", "wondrous", "worthy", "woven",+ # X Y Z+ "xenial", "xeric", "yielding", "young", "youthful", "zealous", "zenith",+ "zephyr", "zestful", "zippy",+ # extras to reach 500+ "affable", "aloft", "animated", "artful", "balanced", "bountiful", "bracing",+ "candent", "capacious", "certain", "clean", "collected", "composed", "confident",+ "conscientious", "considerate", "constant", "deft", "deliberate", "dependable",+ "dignified", "discerning", "effulgent", "elevated", "eminent", "endeared",+ "equable", "established", "expansive", "expressive", "felicific", "forthright",+ "fulsome", "generative", "graced", "hallowed", "idiomatic", "imaginable",+ "immovable", "incisive", "inquisitive", "insightful", "integral", "intuitive",+ "jaunty", "knowing", "limber", "limpid", "lofty", "manifest",+ "masterful", "meticulous", "musing", "nascent", "nuanced",+ "openhearted", "ordinate", "pacific", "pellucid", "perceptive", "pious",+ "plentiful", "precise", "pristine", "progressing",+ "reasoned", "refined", "reposed", "revered", "rhapsodic", "sapient",+ "sanguine", "settled", "sheer", "sideral", "spiraling",+ "stately", "stellar", "temperate", "thorough", "tonal",+ "torchlit", "tractable", "transcendent", "unbounded", "unfailing", "unfettered",+]++_NOUNS = [+ # A+ "adder", "alder", "algae", "aloe", "anchor", "antler", "anvil", "apex",+ "apple", "arch", "arrow", "ash", "aspen", "atlas", "atoll", "aurora",+ "autumn", "avalanche", "axe",+ # B+ "badger", "bark", "barn", "basalt", "basin", "bay", "beacon", "bear",+ "beaver", "beech", "bell", "berry", "birch", "bison", "blade", "bloom",+ "blossom", "bluebell", "bluff", "boar", "bog", "boulder", "bough", "bramble",+ "brant", "bream", "brine", "brook", "buck", "bud", "burrow", "buttercup",+ "butte",+ # C+ "canoe", "canopy", "canyon", "cape", "cardinal", "carp", "catfish", "cave",+ "cedar", "channel", "charcoal", "chestnut", "chisel", "chough", "cicada",+ "cinder", "cirque", "cirrus", "clam", "cliff", "clover", "cobble", "cobalt",+ "cockle", "col", "comet", "compass", "condor", "coral", "cormorant", "corrie",+ "cove", "coyote", "crane", "crater", "creek", "crest", "crocus", "crow",+ "crystal", "curlew", "current", "cypress",+ # D+ "dale", "darter", "dawn", "deer", "delta", "dew", "dipper", "dock",+ "dolphin", "dormouse", "dotterel", "dove", "dragonfly", "drumlin", "dunlin",+ "dune", "dyke",+ # E+ "eagle", "echo", "eel", "egret", "elder", "elk", "elm", "ember",+ "escarpment", "estuary",+ # F+ "falcon", "fawn", "fern", "field", "fiord", "firecrest", "finch", "fir",+ "fjord", "flame", "flint", "flood", "flora", "fluke", "flycatcher", "foam",+ "fog", "forest", "forge", "fossil", "fox", "frost", "fulmar",+ # G+ "gale", "gannet", "garganey", "garnet", "geyser", "glacier", "glade",+ "glen", "godwit", "goldcrest", "goldfinch", "goosander", "gorge", "goshawk",+ "granite", "gravel", "grove", "grouse", "guillemot", "gulch", "gull", "gust",+ # H+ "hamster", "hare", "harrier", "hartebeest", "hawk", "hazel", "heath",+ "hedgehog", "heron", "hill", "hillside", "holly", "hoopoe", "horizon",+ "hornet",+ # I+ "ibex", "ibis", "inlet", "iris", "island", "ivory",+ # J+ "jackal", "jackdaw", "jasper", "jay", "juniper",+ # K+ "kelp", "kestrel", "kingfisher", "kite", "kiwi", "knoll", "knot",+ # L+ "lagoon", "lake", "lapwing", "larch", "lark", "lava", "leaf", "ledge",+ "lemur", "leveret", "lichen", "limestone", "linden", "linnet", "lion",+ "loam", "loess", "locust", "lodge", "loon", "lotus", "lynx",+ # M+ "mackerel", "magpie", "mallard", "maple", "marl", "marsh", "martin",+ "meadow", "merganser", "merlin", "mesa", "midstream", "milfoil", "mink",+ "mist", "moorland", "moose", "moss", "moth", "mountain", "mudflat",+ "mudstone", "muskrat",+ # N+ "narwhal", "needle", "newt", "nightingale", "nightjar", "noctule", "north",+ "nutmeg", "nuthatch",+ # O+ "oak", "opal", "orca", "osprey", "otter", "outcrop", "owl", "oyster",+ "oystercatcher",+ # P+ "partridge", "pass", "pasture", "peak", "peat", "pebble", "peewit",+ "pelican", "pennant", "perch", "peregrine", "petal", "pheasant", "pigeon",+ "pine", "pintail", "pipit", "plover", "plume", "pochard", "polecat",+ "pond", "poplar", "porcupine", "prairie", "ptarmigan", "puffin",+ # Q+ "quartz", "quill",+ # R+ "rabbit", "raven", "reed", "reedbed", "reef", "ridge", "rift", "rill",+ "ringlet", "ripple", "robin", "rock", "rockpool", "roe", "roost",+ "rosefinch", "root", "rowan", "runnel", "rush", "rushes",+ # S+ "sage", "salmon", "sandbar", "sandpiper", "sandstone", "sapphire", "scree",+ "seabird", "seagrass", "sedge", "serin", "sett", "shale", "shearwater",+ "shoal", "shore", "shoveler", "shrew", "shrike", "sierra", "siskin",+ "skimmer", "skua", "skylark", "slate", "sluice", "smew", "snipe",+ "snowdrop", "snowfield", "snout", "sora", "sorrel", "sparrow", "spire",+ "spoonbill", "spruce", "squall", "squirrel", "stag", "starling", "stem",+ "steppe", "stoat", "stone", "stonefly", "stork", "storm", "stream",+ "stubble", "summit", "sundew", "sunfish", "swallow", "swamp", "swan",+ "swift", "sycamore",+ # T+ "talon", "tanager", "tarpon", "teal", "tern", "thistle", "thorn",+ "thornbill", "thicket", "thrush", "tide", "timber", "titlark", "toad",+ "torchwood", "torrent", "trail", "treecreeper", "trogon", "trout", "tuatara",+ "tumulus", "tundra", "turnstone", "turtle", "twite",+ # U+ "upland",+ # V+ "vale", "valley", "veery", "verdure", "vetch", "viburnum", "vireo",+ "viper", "vixen", "vole",+ # W+ "wader", "wagtail", "warbler", "waterfowl", "watershed", "wave", "waxwing",+ "weasel", "weir", "wheatear", "whinchat", "whitethroat", "wigeon", "wildcat",+ "willow", "wolf", "woodcock", "woodland", "woodpecker", "wormwood", "wren",+ "wryneck",+ # Y Z+ "yarrow", "yellowhammer", "yew", "zander", "zinnia", "zorilla",+ # extras to reach 500+ "acorn", "agate", "albatross", "alcove", "almond", "alp", "amaranth",+ "amethyst", "anemone", "antelope", "arroyo", "azalea", "barnacle", "bayou",+ "blizzard", "bracken", "brushwood", "buffalo",+ "bulrush", "bunting", "bushtit", "buzzard", "capercaillie", "caribou",+ "catkin", "chaffinch", "chalcedony", "chamomile", "cheetah", "cinnabar",+ "cistus", "clough", "coho", "columbine", "coppice", "crag", "crake",+ "crossbill", "crowberry", "dace", "daisy", "damselfly", "dandelion",+ "dewdrop", "dhole", "dingo", "dunock", "earthworm", "echidna", "ermine",+ "esker", "fen", "flounder", "flyway", "forb", "gallinule", "garfish",+ "gecko", "geode", "gerbil", "gibbon", "ginkgo", "gloaming", "glowworm",+ "gneiss", "gnu",+]+++def generate_username():+ from mwmbl.models import MwmblUser+ for _ in range(10):+ candidate = f"{random.choice(_ADJECTIVES)}_{random.choice(_NOUNS)}_{random.randint(100, 999)}"+ if not MwmblUser.objects.filter(username=candidate).exists():+ return candidate+ # Extremely unlikely fallback — collision exhausted after 10 attempts+ return f"user_{secrets.token_hex(6)}"