common.helpers package

Module contents

common.helpers.model_form_data(model, form_class, form_kwargs={})[source]

Returns a dict that can be used to instantiate a form object. It fills in the model’s data, but filters out fields that are not on the form. Example:

class Car(models.Model):

brand = CharField(max_length = 50) fuel_tank_size = FloatField() # more fields

class CreateCarForm(forms.ModelForm):

fields = [‘brand’]

my_car = Car(brand=’Nissan’, fuel_tank_size=60)

model_form_data(my_car, CreateCarForm) # returns {‘brand’: ‘Nissan’}

Note that the returned dict does not have a field ‘fuel_tank_size’, because it is not on the form.

common.helpers.random_arxiv_identifier_with_version_number(version_nr='0')[source]
common.helpers.random_arxiv_identifier_without_version_number()[source]
common.helpers.random_scipost_journal()[source]
common.helpers.random_external_journal_abbrev()[source]
common.helpers.random_pub_number()[source]
common.helpers.random_scipost_doi()[source]
common.helpers.random_scipost_report_doi_label()[source]
common.helpers.random_external_doi()[source]

Return a fake/random doi as if all journal abbrev and pub_number are separated by ., which can be helpfull for testing purposes.

common.helpers.random_digits(n)[source]
common.helpers.generate_orcid()[source]
common.helpers.filter_keys(dictionary, keys_to_keep)[source]
common.helpers.get_new_secrets_key(salt='', salt2='')[source]