Skip to content

Commit

Permalink
Enforce capital first letter in features and templates forms
Browse files Browse the repository at this point in the history
  • Loading branch information
ldeluigi committed May 2, 2023
1 parent 7eafce5 commit 585b4ad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion backend/spellbook/models/feature.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.db import models
from .validators import FIRST_CAPITAL_LETTER_VALIDATOR


class Feature(models.Model):
name = models.CharField(max_length=255, unique=True, blank=False, help_text='Short name for a produced effect', verbose_name='name of feature')
name = models.CharField(max_length=255, unique=True, blank=False, help_text='Short name for a produced effect', verbose_name='name of feature', validators=[FIRST_CAPITAL_LETTER_VALIDATOR])
description = models.TextField(blank=True, help_text='Long description of a produced effect', verbose_name='description of feature')
created = models.DateTimeField(auto_now_add=True, editable=False)
updated = models.DateTimeField(auto_now=True, editable=False)
Expand Down
4 changes: 2 additions & 2 deletions backend/spellbook/models/template.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from urllib.parse import urlencode
from django.db import models
from django.utils.html import format_html
from .validators import SCRYFALL_QUERY_HELP, SCRYFALL_QUERY_VALIDATOR
from .validators import SCRYFALL_QUERY_HELP, SCRYFALL_QUERY_VALIDATOR, FIRST_CAPITAL_LETTER_VALIDATOR
from .scryfall import SCRYFALL_API_CARD_SEARCH, SCRYFALL_WEBSITE_CARD_SEARCH, SCRYFALL_LEGAL_IN_COMMANDER


class Template(models.Model):
name = models.CharField(max_length=255, blank=False, verbose_name='template name', help_text='short description of the template in natural language')
name = models.CharField(max_length=255, blank=False, verbose_name='template name', help_text='short description of the template in natural language', validators=[FIRST_CAPITAL_LETTER_VALIDATOR])
scryfall_query = models.CharField(max_length=255, blank=False, verbose_name='Scryfall query', help_text=SCRYFALL_QUERY_HELP, validators=[SCRYFALL_QUERY_VALIDATOR])
created = models.DateTimeField(auto_now_add=True, editable=False)
updated = models.DateTimeField(auto_now=True, editable=False)
Expand Down
3 changes: 3 additions & 0 deletions backend/spellbook/models/validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from django.core.validators import RegexValidator, MinLengthValidator

FIRST_CAPITAL_LETTER_REGEX = r'^[A-Z]'
FIRST_CAPITAL_LETTER_VALIDATOR = RegexValidator(regex=FIRST_CAPITAL_LETTER_REGEX, message='Must start with a capital letter.')

MANA_SYMBOL = r'(?:[WUBRG](?:\/P)?|[0-9CPXYZS∞]|[1-9][0-9]{1,2}|(?:2\/[WUBRG]|W\/U|W\/B|B\/R|B\/G|U\/B|U\/R|R\/G|R\/W|G\/W|G\/U)(?:\/P)?)'
MANA_REGEX = r'^(?:(?:\{' + MANA_SYMBOL + r'\})[^\{\}\[\]]*)*$'
MANA_VALIDATOR = RegexValidator(regex=MANA_REGEX, message='Mana needed must be in the {1}{W}{U}{B}{R}{G}{B/P}... format, and must start with mana symbols, but can contain normal text later.')
Expand Down

0 comments on commit 585b4ad

Please sign in to comment.