-
Notifications
You must be signed in to change notification settings - Fork 1
SS-1176 Users are able to set a custom default start URL for their apps #249
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
Changes from all commits
4994f10
27b763b
b5e8313
636ff9c
1425fdb
90f2b98
06b74f8
42c1e9f
b5cf2ed
758939e
60002fc
b3860ab
ad3feae
dc37d17
7b0ec61
8d560bd
9ce5d5b
3527fd0
6c4b717
cde08ad
83f9954
47476ce
a9b049b
bbcb968
a329f08
7d84b18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,9 @@ | ||||||||
| from crispy_forms.bootstrap import Accordion, AccordionGroup, PrependedText | ||||||||
| from crispy_forms.layout import HTML, Div, Field, Layout, MultiField | ||||||||
| from django import forms | ||||||||
| from django.core.exceptions import ValidationError | ||||||||
| from django.urls import reverse | ||||||||
| from django.utils.safestring import mark_safe | ||||||||
|
|
||||||||
| from apps.forms.base import AppBaseForm | ||||||||
| from apps.forms.field.common import SRVCommonDivField | ||||||||
|
|
@@ -14,12 +18,23 @@ class CustomAppForm(AppBaseForm): | |||||||
| port = forms.IntegerField(min_value=3000, max_value=9999, required=True) | ||||||||
| image = forms.CharField(max_length=255, required=True) | ||||||||
| path = forms.CharField(max_length=255, required=False) | ||||||||
| default_url_subpath = forms.CharField(max_length=255, required=False, label="Custom URL subpath") | ||||||||
|
|
||||||||
| def _setup_form_fields(self): | ||||||||
| # Handle Volume field | ||||||||
| super()._setup_form_fields() | ||||||||
| self.fields["volume"].initial = None | ||||||||
|
|
||||||||
| self.fields["default_url_subpath"].widget.attrs.update({"class": "textinput form-control"}) | ||||||||
| self.fields["default_url_subpath"].help_text = "Specify a non-default start URL if your app requires that." | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. Modified it. |
||||||||
| apps_url = reverse("portal:apps") | ||||||||
| self.fields["default_url_subpath"].bottom_help_text = mark_safe( | ||||||||
| ( | ||||||||
| f"<span class='fw-bold'>Note:</span> This changes the URL connected to the Open button for an app" | ||||||||
| f" on the Serve <a href='{apps_url}'>Apps & Models</a> page." | ||||||||
| ) | ||||||||
| ) | ||||||||
|
|
||||||||
| def _setup_form_helper(self): | ||||||||
| super()._setup_form_helper() | ||||||||
|
|
||||||||
|
|
@@ -40,6 +55,17 @@ def _setup_form_helper(self): | |||||||
| ), | ||||||||
| SRVCommonDivField("port", placeholder="8000"), | ||||||||
| SRVCommonDivField("image"), | ||||||||
| Accordion( | ||||||||
| AccordionGroup( | ||||||||
| "Advanced settings", | ||||||||
| PrependedText( | ||||||||
| "default_url_subpath", | ||||||||
| mark_safe("<span id='id_custom_default_url_prepend'>Subdomain/</span>"), | ||||||||
| template="apps/partials/srv_prepend_append_input_group.html", | ||||||||
| ), | ||||||||
| active=False, | ||||||||
| ), | ||||||||
| ), | ||||||||
| css_class="card-body", | ||||||||
| ) | ||||||||
| self.helper.layout = Layout(body, self.footer) | ||||||||
|
|
@@ -81,6 +107,7 @@ class Meta: | |||||||
| "port", | ||||||||
| "image", | ||||||||
| "tags", | ||||||||
| "default_url_subpath", | ||||||||
| ] | ||||||||
| labels = { | ||||||||
| "note_on_linkonly_privacy": "Reason for choosing the link only option", | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Generated by Django 5.1.1 on 2024-11-19 13:27 | ||
|
|
||
| import apps.models.app_types.custom.custom | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("apps", "0017_alter_streamlitinstance_port"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="customappinstance", | ||
| name="default_url_subpath", | ||
| field=models.CharField( | ||
| blank=True, | ||
| default="", | ||
| max_length=255, | ||
| validators=[apps.models.app_types.custom.custom.validate_default_url_subpath], | ||
| ), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,11 +1,40 @@ | ||||||||||||
| import regex as re | ||||||||||||
| from django.core.exceptions import ValidationError | ||||||||||||
|
Comment on lines
+1
to
+2
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This should be caught by isort I think
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. Addressed it. |
||||||||||||
| from django.db import models | ||||||||||||
|
|
||||||||||||
| from apps.models import AppInstanceManager, BaseAppInstance | ||||||||||||
|
|
||||||||||||
| from .base import AbstractCustomAppInstance | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def validate_default_url_subpath(candidate): | ||||||||||||
| """ | ||||||||||||
| Validates a custom default url path addition. | ||||||||||||
| The RegexValidator will raise a ValidationError if the input does not match the regular expression. | ||||||||||||
| It is up to the caller to handle the raised exception if desired. | ||||||||||||
| """ | ||||||||||||
| error_message = ( | ||||||||||||
| "Your custom URL subpath is not valid, please correct it. " | ||||||||||||
| "It must be 1-53 characters long." | ||||||||||||
| " It can contain only Unicode letters, digits, hyphens" | ||||||||||||
| " ( - ), forward slashes ( / ), and underscores ( _ )." | ||||||||||||
| " It cannot start or end with a hyphen ( - ) and " | ||||||||||||
| "cannot start with a forward slash ( / )." | ||||||||||||
| " It cannot contain consecutive forward slashes ( // )." | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| pattern = r"^(?!-)(?!/)(?!.*//)[\p{Letter}\p{Mark}0-9-/_]{1,53}(?<!-)$|^$" | ||||||||||||
|
|
||||||||||||
| if not re.match(pattern, candidate): | ||||||||||||
| raise ValidationError(error_message) | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| class CustomAppInstanceManager(AppInstanceManager): | ||||||||||||
| model_type = "customappinstance" | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| class CustomAppInstance(AbstractCustomAppInstance, BaseAppInstance): | ||||||||||||
| default_url_subpath = models.CharField( | ||||||||||||
| validators=[validate_default_url_subpath], max_length=255, default="", blank=True | ||||||||||||
| ) | ||||||||||||
| objects = CustomAppInstanceManager() | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,7 +79,6 @@ def get_unique_apps(queryset, app_ids_to_exclude): | |
| app_orms = (app_model for app_model in APP_REGISTRY.iter_orm_models() if issubclass(app_model, SocialMixin)) | ||
|
|
||
| for app_orm in app_orms: | ||
| logger.info("Processing: %s", app_orm) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to remove this? |
||
| filters = ~Q(app_status__status="Deleted") & Q(access="public") | ||
| if collection: | ||
| filters &= Q(collections__slug=collection) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Addressed it.