Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting that adds limits to project titles #605

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions coldfront/config/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# Enable Project Review
#------------------------------------------------------------------------------
PROJECT_ENABLE_PROJECT_REVIEW = ENV.bool('PROJECT_ENABLE_PROJECT_REVIEW', default=True)
PROJECT_TITLE_REGEX = ENV.str('PROJECT_TITLE_REGEX', default='.*')
PROJECT_TITLE_REGEX_DESCRIPTION = ENV.str('PROJECT_TITLE_REGEX_DESCRIPTION', default='')

#------------------------------------------------------------------------------
# Allocation related
Expand Down
5 changes: 4 additions & 1 deletion coldfront/core/project/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.core.validators import MinLengthValidator
from django.core.validators import RegexValidator
from django.db import models
from ast import literal_eval
from coldfront.core.utils.validate import AttributeValidator
Expand All @@ -15,6 +16,8 @@
from coldfront.core.utils.common import import_from_settings

PROJECT_ENABLE_PROJECT_REVIEW = import_from_settings('PROJECT_ENABLE_PROJECT_REVIEW', False)
PROJECT_TITLE_REGEX = import_from_settings('PROJECT_TITLE_REGEX', '.*')
PROJECT_TITLE_REGEX_DESCRIPTION = import_from_settings('PROJECT_TITLE_REGEX_DESCRIPTION', '')

class ProjectPermission(Enum):
""" A project permission stores the user, manager, pi, and update fields of a project. """
Expand Down Expand Up @@ -76,7 +79,7 @@ def get_by_natural_key(self, title, pi_username):
We do not have information about your research. Please provide a detailed description of your work and update your field of science. Thank you!
'''

title = models.CharField(max_length=255,)
title = models.CharField(max_length=255, validators=[RegexValidator(PROJECT_TITLE_REGEX, PROJECT_TITLE_REGEX_DESCRIPTION)])
pi = models.ForeignKey(User, on_delete=models.CASCADE,)
description = models.TextField(
default=DEFAULT_DESCRIPTION,
Expand Down
2 changes: 2 additions & 0 deletions docs/pages/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ The following settings are ColdFront specific settings related to the core appli
| CENTER_PROJECT_RENEWAL_HELP_URL | The URL of the article describing project renewals |
| CENTER_BASE_URL | The base URL of your center. |
| PROJECT_ENABLE_PROJECT_REVIEW | Enable or disable project reviews. Default True|
| PROJECT_TITLE_REGEX | Set a regular expression (regex) to limit project titles. Default ".*" (anything)
| PROJECT_TITLE_REGEX_DESCRIPTION | Message that gets displayed to the user when the regex is not followed. Default "" (empty string)
| ALLOCATION_ENABLE_ALLOCATION_RENEWAL | Enable or disable allocation renewals. Default True |
| ALLOCATION_DEFAULT_ALLOCATION_LENGTH | Default number of days an allocation is active for. Default 365 |
| ALLOCATION_ENABLE_CHANGE_REQUESTS_BY_DEFAULT | Enable or disable allocation change requests. Default True |
Expand Down