|
a/Allura/allura/command/create_neighborhood.py |
|
b/Allura/allura/command/create_neighborhood.py |
1 |
from . import base
|
1 |
from . import base
|
2 |
|
2 |
|
|
|
3 |
from ming.orm import session
|
|
|
4 |
|
3 |
from allura import model as M
|
5 |
from allura import model as M
|
4 |
from allura.lib import plugin
|
6 |
from allura.lib import plugin, exceptions
|
5 |
|
7 |
|
6 |
class CreateNeighborhoodCommand(base.Command):
|
8 |
class CreateNeighborhoodCommand(base.Command):
|
7 |
min_args=3
|
9 |
min_args=3
|
8 |
max_args=None
|
10 |
max_args=None
|
9 |
usage = '<ini file> <neighborhood_shortname> <admin1> [<admin2>...]'
|
11 |
usage = '<ini file> <neighborhood_shortname> <admin1> [<admin2>...]'
|
|
... |
|
... |
21 |
max_projects = 500,
|
23 |
max_projects = 500,
|
22 |
css = 'none',
|
24 |
css = 'none',
|
23 |
google_analytics = False))
|
25 |
google_analytics = False))
|
24 |
project_reg = plugin.ProjectRegistrationProvider.get()
|
26 |
project_reg = plugin.ProjectRegistrationProvider.get()
|
25 |
project_reg.register_neighborhood_project(n, admins)
|
27 |
project_reg.register_neighborhood_project(n, admins)
|
26 |
print "WARNING! You must restart the webserver before you can use the new neighborhood."
|
28 |
|
|
|
29 |
|
|
|
30 |
class UpdateNeighborhoodCommand(base.Command):
|
|
|
31 |
min_args=3
|
|
|
32 |
max_args=None
|
|
|
33 |
usage = '<ini file> <neighborhood_shortname> <home_tool_active>'
|
|
|
34 |
summary = 'Activate Home application for neighborhood\r\n' \
|
|
|
35 |
'\t<neighborhood> - the neighborhood name\r\n' \
|
|
|
36 |
'\t<value> - boolean value to install/uninstall Home tool\r\n' \
|
|
|
37 |
'\t must be True or False\r\n\r\n' \
|
|
|
38 |
'\tExample:\r\n' \
|
|
|
39 |
'\tpaster update-neighborhood-home-tool development.ini Projects True'
|
|
|
40 |
parser = base.Command.standard_parser(verbose=True)
|
|
|
41 |
|
|
|
42 |
def command(self):
|
|
|
43 |
self.basic_setup()
|
|
|
44 |
shortname = self.args[1]
|
|
|
45 |
nb = M.Neighborhood.query.get(name=shortname)
|
|
|
46 |
if nb is None:
|
|
|
47 |
raise exceptions.NoSuchNeighborhoodError("The neighborhood %s " \
|
|
|
48 |
"could not be found in the database" % shortname)
|
|
|
49 |
tool_value = self.args[2].lower()
|
|
|
50 |
if tool_value[:1] == "t":
|
|
|
51 |
home_tool_active = True
|
|
|
52 |
else:
|
|
|
53 |
home_tool_active = False
|
|
|
54 |
|
|
|
55 |
if home_tool_active == nb.has_home_tool:
|
|
|
56 |
return
|
|
|
57 |
|
|
|
58 |
p = nb.neighborhood_project
|
|
|
59 |
if home_tool_active:
|
|
|
60 |
zero_position_exists = False
|
|
|
61 |
for ac in p.app_configs:
|
|
|
62 |
if ac.options['ordinal'] == 0:
|
|
|
63 |
zero_position_exists = True
|
|
|
64 |
break
|
|
|
65 |
|
|
|
66 |
if zero_position_exists:
|
|
|
67 |
for ac in p.app_configs:
|
|
|
68 |
ac.options['ordinal'] = ac.options['ordinal'] + 1
|
|
|
69 |
p.install_app('home', 'home', 'Home', ordinal=0)
|
|
|
70 |
else:
|
|
|
71 |
app_config = p.app_config('home')
|
|
|
72 |
zero_position_exists = False
|
|
|
73 |
if app_config.options['ordinal'] == 0:
|
|
|
74 |
zero_position_exists = True
|
|
|
75 |
|
|
|
76 |
p.uninstall_app('home')
|
|
|
77 |
if zero_position_exists:
|
|
|
78 |
for ac in p.app_configs:
|
|
|
79 |
ac.options['ordinal'] = ac.options['ordinal'] - 1
|
|
|
80 |
|
|
|
81 |
session(M.AppConfig).flush()
|
|
|
82 |
session(M.Neighborhood).flush()
|