Ejemplo n.º 1
0
def project_edit(project_id=None):
  from models.account import Account
  from models.project import Project, Label
  
  project = None
  if not project_id:
    project = Project()
    project.status = Project.STATUS_ACTIVE
    if not app.access('project', action='create'):
      abort(403)
  else:
    project_id = urllib.unquote_plus(project_id)
    project = Project.query.filter_by(id=project_id).first()
    if not project:
      abort(404)
    elif not app.access('project', action='update', project=project):
      abort(403)
  
  validationErrors = []
  if request.method == 'POST' and request.form.get('csrf_token', None):
    project.alias = request.form.get('project_alias', project.alias).strip()
    project.title = request.form.get('project_title', project.title).strip()
    project.info = request.form.get('project_info', project.info).strip()
    project.status = int(request.form.get('project_status', project.status).strip())
    
    validationErrors.extend(project.validate())
    if not validationErrors:
      project.save()
      
      if not Label.query.filter_by(project_id=project.id, title=Label.LABEL_DEFAULT).first():
        label = Label()
        label.project_id = project.id
        label.title = Label.LABEL_DEFAULT
        label.save()
      
      flash(g._t('project submit success'))
      return redirect(url_for('project_view', project_id=urllib.quote_plus(str(project.id))))
  
  if project_id:
    title = g._t('edit project')
  else:
    title = g._t('add project')
  
  if project_id:
    breadcrumbs = (
      (g._t('projects'), url_for('project_index')),
      (project.__str__(), url_for('project_view', project_id=urllib.quote_plus(str(project_id)))),
      (title, "#")
    )
  else:
    breadcrumbs = (
      (g._t('projects'), url_for('project_index')),
      (title, "#")
    )
  
  return render_template('project/edit.html', project_id=project_id, project=project, errors=validationErrors, title=title, breadcrumbs=breadcrumbs)
Ejemplo n.º 2
0
def install_migration_projects():
  """Migrate the projects data from the old CouchDB storage"""
  from models.account import Account
  from models.project import Project, Component, Label, Role
  
  for row in __couchdb().view('_design/projects/_view/list'):
    value = row['value']
    
    value['_id'] = value.get('_id', '').replace(':', '/')
    
    # resolve the labels INT or EXT
    value['labels'] = []
    if value.get('_id', '').startswith('INT'):
      value['labels'].append(Label.LABEL_INTERNAL)
    elif value.get('_id', '').startswith('EXT'):
      value['labels'].append(Label.LABEL_EXTERNAL)
    elif value.get('_id', '').startswith('MGM') or value.get('_id', '').startswith('OUT'):
      value['labels'].append(Label.LABEL_VACATION)
    elif value.get('_id', '') == 'NOKIA/OFFICIAL':
      value['labels'].append(Label.LABEL_VACATION)
    
    value['_id'] = value.get('_id', '').replace('EXT/', '').replace('INT/', '')
    project = Project.query.filter_by(alias=value.get('_id', '')).first()
    if not project:
      project = Project()
      project.alias = value.get('_id', '')
      project.title = value.get('title')
      project.info = value.get('description')
      if value.get('deleted', False):
        project.status = Project.STATUS_ACTIVE | Project.STATUS_DELETED
      project.save()
      print '[MIGRATION:PROJECT]', project.__str__()
    
    items = [(None, value.get('title'))]
    for k,v in value.get('partitions', {}).items():
      treeRecursion(k, v, None, items)
    
    for component_alias, component_title in items:
      if not component_alias:
        continue
      component = Component.query.filter_by(project=project, alias=component_alias).first()
      if not component:
        component = Component()
        component.alias = component_alias
        component.title = component_title
        component.project = project
        component.save()
        print '[MIGRATION:COMPONENT]', project.__str__(), component.__str__()
    
    for labelItem in value.get('labels', []):
      label = Label.query.filter_by(title=labelItem, project=project).first()
      if not label:
        label = Label()
        label.title = labelItem
        label.project = project
        label.save()