#7 New Form
* adds EditEcoAccountForm * adds placeholders for some form fields * changes comment card in detail view into rlp-grayish * adds eco account detail view comment box * removes unnecessary loading of dal scripts in view.html * refactors generated identifier for data objects (10 digits to 6 uppercase letter-digit combination) * improves generate_random_string() method by adding more options for generation of strings * adds/updates translations
This commit is contained in:
@@ -76,7 +76,7 @@ class BaseForm(forms.Form):
|
||||
|
||||
def add_placeholder_for_field(self, field: str, val):
|
||||
"""
|
||||
Adds a placeholder to a field after initialization
|
||||
Adds a placeholder to a field after initialization without the need to redefine the form widget
|
||||
|
||||
Args:
|
||||
field (str): Field name
|
||||
|
||||
@@ -191,7 +191,9 @@ class BaseObject(BaseResource):
|
||||
curr_year = str(_now.year)
|
||||
rand_str = generate_random_string(
|
||||
length=definitions[self.__class__]["length"],
|
||||
only_numbers=True,
|
||||
use_numbers=True,
|
||||
use_letters_lc=False,
|
||||
use_letters_uc=True,
|
||||
)
|
||||
_str = "{}{}-{}".format(curr_month, curr_year, rand_str)
|
||||
return definitions[self.__class__]["template"].format(_str)
|
||||
|
||||
@@ -9,14 +9,18 @@ import random
|
||||
import string
|
||||
|
||||
|
||||
def generate_random_string(length: int, only_numbers: bool = False) -> str:
|
||||
def generate_random_string(length: int, use_numbers: bool = False, use_letters_lc: bool = False, use_letters_uc: bool = False) -> str:
|
||||
"""
|
||||
Generates a random string of variable length
|
||||
"""
|
||||
if only_numbers:
|
||||
elements = string.digits
|
||||
else:
|
||||
elements = string.ascii_letters
|
||||
elements = []
|
||||
if use_numbers:
|
||||
elements.append(string.digits)
|
||||
if use_letters_lc:
|
||||
elements.append(string.ascii_lowercase)
|
||||
if use_letters_uc:
|
||||
elements.append(string.ascii_uppercase)
|
||||
|
||||
elements = "".join(elements)
|
||||
ret_val = "".join(random.choice(elements) for i in range(length))
|
||||
return ret_val
|
||||
|
||||
Reference in New Issue
Block a user