You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2014/04/15 20:54:25 UTC
git commit: [#7309] don't show uninstallable tools on /*/add_project
Repository: allura
Updated Branches:
refs/heads/db/7309 [created] c74f952ba
[#7309] don't show uninstallable tools on /*/add_project
Factor out _installable so it can be called without an App. Constructing
an App wasn't happening before, so the check was invalid. And
constructing an App requires a Project and AppConfig
Also change `fields` from a class to a property so it doesn't run on import
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/c74f952b
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/c74f952b
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/c74f952b
Branch: refs/heads/db/7309
Commit: c74f952baf263a4c4240dc98d08e694b8c5b4c40
Parents: b2cda19
Author: Dave Brondsema <da...@brondsema.net>
Authored: Tue Apr 15 14:51:59 2014 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Tue Apr 15 14:53:55 2014 -0400
----------------------------------------------------------------------
Allura/allura/app.py | 14 ++++++---
Allura/allura/lib/widgets/forms.py | 54 +++++++++++++++------------------
2 files changed, 35 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/c74f952b/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index 315ddc4..79283a3 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -338,11 +338,17 @@ class Application(object):
:rtype: bool
"""
- if self.config.tool_name.lower() in self.project.neighborhood.get_prohibited_tools():
+ return self._installable(self.config.tool_name,
+ self.project.neighborhood,
+ self.project.app_configs,
+ )
+
+ @classmethod
+ def _installable(cls, tool_name, nbhd, project_tools):
+ if tool_name.lower() in nbhd.get_prohibited_tools():
return False
- tools_list = [tool.tool_name.lower()
- for tool in self.project.app_configs]
- return tools_list.count(self.config.tool_name.lower()) < self.max_instances
+ tools_list = [tool.tool_name.lower() for tool in project_tools]
+ return tools_list.count(tool_name.lower()) < cls.max_instances
@classmethod
def validate_mount_point(cls, mount_point):
http://git-wip-us.apache.org/repos/asf/allura/blob/c74f952b/Allura/allura/lib/widgets/forms.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py
index 4489a62..b9bd9de 100644
--- a/Allura/allura/lib/widgets/forms.py
+++ b/Allura/allura/lib/widgets/forms.py
@@ -18,7 +18,7 @@
import logging
import warnings
-from pylons import app_globals as g
+from pylons import app_globals as g, tmpl_context as c
from formencode import validators as fev
import formencode
import ew as ew_core
@@ -849,35 +849,31 @@ class NeighborhoodAddProjectForm(ForgeForm):
submit_text='Start',
neighborhood=None)
- class fields(ew_core.NameList):
- project_description = ew.HiddenField(label='Public Description')
- neighborhood = ew.HiddenField(label='Neighborhood')
- private_project = ew.Checkbox(label="", attrs={'class': 'unlabeled'})
- project_name = ew.InputField(label='Project Name', field_type='text',
- validator=formencode.All(
- fev.UnicodeString(
- not_empty=True, max=40),
- V.MaxBytesValidator(max=40)))
- project_unixname = ew.InputField(
- label='Short Name', field_type='text',
- validator=None) # will be set in __init__
- tools = ew.CheckboxSet(name='tools', options=[
- # Required for Neighborhood functional tests to pass
- ew.Option(label='Wiki', html_value='wiki', selected=True)
- ])
-
- def __init__(self, *args, **kwargs):
- super(NeighborhoodAddProjectForm, self).__init__(*args, **kwargs)
- # get the shortname validator from the provider
+ @property
+ def fields(self):
provider = plugin.ProjectRegistrationProvider.get()
- self.fields.project_unixname.validator = provider.shortname_validator
- # Dynamically generating CheckboxSet of installable tools
- from allura.lib.widgets import forms
- self.fields.tools.options = [
- forms.ew.Option(label=tool.tool_label, html_value=ep)
- for ep, tool in g.entry_points["tool"].iteritems()
- if tool.installable and tool.status == 'production'
- ]
+ tools_options = []
+ for ep, tool in g.entry_points["tool"].iteritems():
+ if tool.status == 'production' and tool._installable(tool_name=ep,
+ nbhd=c.project.neighborhood,
+ project_tools=[]):
+ tools_options.append(ew.Option(label=tool.tool_label, html_value=ep))
+
+ return ew_core.NameList([
+ ew.HiddenField(name='project_description', label='Public Description'),
+ ew.HiddenField(name='neighborhood', label='Neighborhood'),
+ ew.Checkbox(name='private_project', label="", attrs={'class': 'unlabeled'}),
+ ew.InputField(name='project_name', label='Project Name',
+ field_type='text',
+ validator=formencode.All(
+ fev.UnicodeString(not_empty=True, max=40),
+ V.MaxBytesValidator(max=40)),
+ ),
+ ew.InputField(name='project_unixname',
+ label='Short Name', field_type='text',
+ validator=provider.shortname_validator),
+ ew.CheckboxSet(name='tools', options=tools_options),
+ ])
def resources(self):
for r in super(NeighborhoodAddProjectForm, self).resources():