Switch to unified view

a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
1
import os, re
1
import os, re
2
import logging
2
import logging
3
import json
3
from urllib import unquote, quote
4
from urllib import unquote, quote
5
from urllib2 import urlopen
4
from itertools import chain, islice
6
from itertools import chain, islice
7
from cStringIO import StringIO
5
8
6
import pkg_resources
9
import pkg_resources
7
import Image
10
import Image
8
from tg import expose, flash, redirect, validate, request, response
11
from tg import expose, flash, redirect, validate, request, response
9
from tg.decorators import with_trailing_slash, without_trailing_slash
12
from tg.decorators import with_trailing_slash, without_trailing_slash
...
...
156
    def register(self, project_unixname=None, project_description=None, project_name=None, neighborhood=None,
159
    def register(self, project_unixname=None, project_description=None, project_name=None, neighborhood=None,
157
                 private_project=None, **kw):
160
                 private_project=None, **kw):
158
        require_access(self.neighborhood, 'register')
161
        require_access(self.neighborhood, 'register')
159
        if private_project:
162
        if private_project:
160
            require_access(self.neighborhood, 'admin')
163
            require_access(self.neighborhood, 'admin')
164
        neighborhood = M.Neighborhood.query.get(name=neighborhood)
165
        project_template = {}
166
        if neighborhood.project_template:
167
            project_template = json.loads(neighborhood.project_template)
168
            if 'private' in project_template:
169
                private_project = project_template['private']
161
        project_description = h.really_unicode(project_description or '').encode('utf-8')
170
        project_description = h.really_unicode(project_description or '').encode('utf-8')
162
        project_name = h.really_unicode(project_name or '').encode('utf-8')
171
        project_name = h.really_unicode(project_name or '').encode('utf-8')
163
        project_unixname = h.really_unicode(project_unixname or '').encode('utf-8').lower()
172
        project_unixname = h.really_unicode(project_unixname or '').encode('utf-8').lower()
164
        neighborhood = M.Neighborhood.query.get(name=neighborhood)
165
        c.project = neighborhood.register_project(project_unixname, project_name=project_name, private_project=private_project)
173
        c.project = neighborhood.register_project(project_unixname, project_name=project_name, private_project=private_project)
166
        if project_description:
174
        if project_description:
167
            c.project.short_description = project_description
175
            c.project.short_description = project_description
168
        ming.orm.ormsession.ThreadLocalORMSession.flush_all()
176
        ming.orm.ormsession.ThreadLocalORMSession.flush_all()
169
        offset = int(c.project.ordered_mounts(include_search=True)[-1]['ordinal']) + 1
177
        offset = int(c.project.ordered_mounts(include_search=True)[-1]['ordinal']) + 1
178
        if 'tools' in project_template:
179
            for i, tool in enumerate(project_template['tools'].keys()):
180
                tool_config = project_template['tools'][tool]
181
                app = c.project.install_app(tool,
182
                    mount_label=tool_config['label'],
183
                    mount_point=tool_config['mount_point'],
184
                    ordinal=i+offset)
185
                if 'options' in tool_config:
186
                    for option in tool_config['options']:
187
                        app.config.options[option] = tool_config['options'][option]
188
        else:
170
        for i, tool in enumerate(kw):
189
            for i, tool in enumerate(kw):
171
            if kw[tool]:
190
                if kw[tool]:
172
                c.project.install_app(tool, ordinal=i+offset)
191
                    c.project.install_app(tool, ordinal=i+offset)
192
        if 'tool_order' in project_template:
193
            for i, tool in enumerate(project_template['tool_order']):
194
                c.project.app_config(tool).options.ordinal = i
195
        if 'labels' in project_template:
196
            c.project.labels = project_template['labels']
197
        if 'trove_cats' in project_template:
198
            for trove_type in project_template['trove_cats'].keys():
199
                troves = getattr(c.project,'trove_%s'%trove_type)
200
                for trove_id in project_template['trove_cats'][trove_type]:
201
                    troves.append(M.TroveCategory.query.get(trove_cat_id=trove_id)._id)
202
        if 'home_options' in project_template:
203
            options = c.project.app_config('home').options
204
            for option in project_template['home_options'].keys():
205
                options[option] = project_template['home_options'][option]
206
        if 'home_text' in project_template:
207
            from forgewiki import model as WM
208
            app = c.project.app_instance('home')
209
            WM.Page.query.get(app_config_id=app.config._id).text = project_template['home_text']
210
        if 'icon' in project_template:
211
            icon_file = StringIO(urlopen(project_template['icon']['url']).read())
212
            M.ProjectFile.save_image(
213
                project_template['icon']['filename'], icon_file,
214
                square=True, thumbnail_size=(48,48),
215
                thumbnail_meta=dict(project_id=c.project._id,category='icon'))
173
        flash('Welcome to the SourceForge Beta System! '
216
        flash('Welcome to the SourceForge Beta System! '
174
              'To get started, fill out some information about your project.')
217
              'To get started, fill out some information about your project.')
175
        redirect(c.project.script_name + 'admin/overview')
218
        redirect(c.project.script_name + 'admin/overview')
176
219
177
    @expose()
220
    @expose()
...
...
433
            grants_count=grants_count,
476
            grants_count=grants_count,
434
            neighborhood=self.neighborhood)
477
            neighborhood=self.neighborhood)
435
478
436
    @expose()
479
    @expose()
437
    @require_post()
480
    @require_post()
438
    def update(self, name=None, css=None, homepage=None, icon=None, **kw):
481
    def update(self, name=None, css=None, homepage=None, project_template=None, icon=None, **kw):
439
        self.neighborhood.name = name
482
        self.neighborhood.name = name
440
        self.neighborhood.redirect = kw.pop('redirect', '')
483
        self.neighborhood.redirect = kw.pop('redirect', '')
441
        self.neighborhood.homepage = homepage
484
        self.neighborhood.homepage = homepage
442
        self.neighborhood.css = css
485
        self.neighborhood.css = css
486
        self.neighborhood.project_template = project_template
443
        self.neighborhood.allow_browse = 'allow_browse' in kw
487
        self.neighborhood.allow_browse = 'allow_browse' in kw
444
        if icon is not None and icon != '':
488
        if icon is not None and icon != '':
445
            if self.neighborhood.icon:
489
            if self.neighborhood.icon:
446
                self.neighborhood.icon.delete()
490
                self.neighborhood.icon.delete()
447
            M.NeighborhoodFile.save_image(
491
            M.NeighborhoodFile.save_image(