diff --git a/passbook/core/forms/applications.py b/passbook/core/forms/applications.py index c35a6bf7c..e2a97d469 100644 --- a/passbook/core/forms/applications.py +++ b/passbook/core/forms/applications.py @@ -29,7 +29,16 @@ class ApplicationForm(forms.ModelForm): ] widgets = { "name": forms.TextInput(), - "meta_launch_url": forms.TextInput(), + "meta_launch_url": forms.TextInput( + attrs={ + "placeholder": _( + ( + "If left empty, passbook will try to extract the launch URL " + "based on the selected provider." + ) + ) + } + ), "meta_icon_url": forms.TextInput(), "meta_publisher": forms.TextInput(), } diff --git a/passbook/core/models.py b/passbook/core/models.py index db93f8b10..2b5b186c6 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -92,6 +92,12 @@ class Provider(models.Model): objects = InheritanceManager() + @property + def launch_url(self) -> Optional[str]: + """URL to this provider and initiate authorization for the user. + Can return None for providers that are not URL-based""" + return None + def form(self) -> Type[ModelForm]: """Return Form class used to edit this object""" raise NotImplementedError @@ -119,6 +125,14 @@ class Application(PolicyBindingModel): meta_description = models.TextField(default="", blank=True) meta_publisher = models.TextField(default="", blank=True) + def get_launch_url(self) -> Optional[str]: + """Get launch URL if set, otherwise attempt to get launch URL based on provider.""" + if self.meta_launch_url: + return self.meta_launch_url + if self.provider: + return self.provider.launch_url + return None + def get_provider(self) -> Optional[Provider]: """Get casted provider instance""" if not self.provider: diff --git a/passbook/core/templates/overview/index.html b/passbook/core/templates/overview/index.html index a9aaaa069..8330ed2f0 100644 --- a/passbook/core/templates/overview/index.html +++ b/passbook/core/templates/overview/index.html @@ -24,7 +24,7 @@ {% if applications %}