示例#1
0
def profile_employees():
  from models.account import Account
  from helpers.account import AccountHelper
  
  title = g._t('employees')
  if app.access('profile', action='administer'):
    employees = AccountHelper.listAccounts()
  elif app.access('profile', action='list'):
    employees = AccountHelper.listActiveAccounts()
  else:
    employees = [g.account]
    return redirect(url_for('profile_view', account_id=urllib.quote_plus(str(g.account.id))))
    
  return render_template('profile/employees.html', employees=employees, title=title)
示例#2
0
def _activityHeader(**kwargs):
  from models.account import Account
  from models.project import Project, Component, Membership, Label
  from helpers.account import AccountHelper
  from helpers.project import ProjectHelper
  
  header = {}
  
  if kwargs.has_key('start_date'):
    header['start_date'] = kwargs['start_date']
  else:
    header['start_date'] = request.values.get('start_date', g._constant()['DATE']['MONTH'])
  #start_date = datetime.datetime.strptime(start_datestring, '%Y-%m-%d')
  #start_ts = start_date.strftime('%s')
  
  if kwargs.has_key('end_date'):
    header['end_date'] = kwargs['end_date']
  else:
    header['end_date'] = request.values.get('end_date', g._constant()['DATE']['TODAY'])
  #end_date = datetime.datetime.strptime(end_datestring, '%Y-%m-%d')
  #end_ts = end_date.strftime('%s')
  
  header['employees'] = []
  if kwargs.has_key('employees'):
    header['employees'] = kwargs['employees']
  elif app.access('profile', action='administer'):
    header['employees'] = AccountHelper.listAccounts()
  elif app.access('profile', action='list'):
    header['employees'] = AccountHelper.listActiveAccounts()
  elif app.access('profile', action='read', account=g.account):
    header['employees'] = [g.account]
  else:
    header['employees'] = []
  
  header['skip_projects'] = ProjectHelper.listVacationProjects()
  
  header['projects'] = []
  if kwargs.has_key('projects'):
    header['projects'] = kwargs['projects']
  elif app.access('project', action='administer'):
    header['projects'] = ProjectHelper.listAllComponents()
  elif app.access('project', action='list'):
    header['projects'] = ProjectHelper.listAllActiveComponents()
  elif app.access('membership', account=g.account):
    header['projects'] = ProjectHelper.listAllComponentsForMember(account=g.account)
  else:
    header['projects'] = []
  
  return header
示例#3
0
def project_members(project_id):
  from models.account import Account
  from models.project import Project, Component, Membership, Role
  from helpers.account import AccountHelper
  from helpers.project import ProjectHelper
  
  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)
  
  title = g._t('project members')
  
  breadcrumbs = (
    (g._t('projects'), url_for('project_index')),
    (project.__str__(), url_for('project_view', project_id=urllib.quote_plus(str(project_id)))),
    (title, "#")
  )
  
  if (request.form.get('method') == 'PUT' or request.method == 'PUT') and request.form.get('csrf_token'):
    submittedMembership = Membership.query.filter_by(project=project, id=request.form.get('membership_id')).first()
    if submittedMembership:
      submittedMembership.component = Component.query.filter_by(project=project, id=request.form.get('membership_component_id', None)).first()
      submittedMembership.account = Account.query.filter_by(id=request.form.get('membership_account_id', None)).first()
      submittedMembership.role = Role.query.filter_by(id=request.form.get('membership_role_id', None)).first()
      
      if not submittedMembership.validate():
        submittedMembership.save()
        
        flash( g._t('membership update success'))
        return redirect(url_for('project_members', project_id=urllib.quote_plus(str(project_id))))
    else:
      flash( g._t('membership not found'), 'error')
    
  elif (request.form.get('method') == 'DELETE' or request.method == 'DELETE') and request.form.get('csrf_token'):
    submittedMembership = Membership.query.filter_by(project=project, id=request.form.get('membership_id')).first()
    if submittedMembership:
      submittedMembership.delete()
    
      flash( g._t('membership delete success'))
      return redirect(url_for('project_members', project_id=urllib.quote_plus(str(project_id))))
    else:
      flash( g._t('membership not found'))
    
  elif (request.form.get('method') == 'POST' or request.method == 'POST') and request.form.get('csrf_token'):
    submittedMembership = Membership()
    submittedMembership.project_id = project.id
    component = Component.query.filter_by(project=project, id=request.form.get('membership_component_id', None)).first()
    if component:
      submittedMembership.component_id = component.id
    account = submittedMembership.account_id = Account.query.filter_by(id=request.form.get('membership_account_id', None)).first()
    if account:
      submittedMembership.account_id = account.id
    role = Role.query.filter_by(id=request.form.get('membership_role_id', None)).first()
    if role:
      submittedMembership.role_id = role.id
    
    if not submittedMembership.validate():
      submittedMembership.save()
      
      flash( g._t('membership create success'))
      return redirect(url_for('project_members', project_id=urllib.quote_plus(str(project_id))))
    
  else:
    submittedMembership = Membership()
  
  if app.access('profile', action='administer'):
    accountList =AccountHelper.listAccounts()
  elif app.access('profile', action='list'):
    accountList = AccountHelper.listActiveAccounts()
  else:
    accountList = [g.account]
  
  if app.access('profile', action='administer'):
    componentList = ProjectHelper.listComponents(project=project)
  elif app.access('profile', action='list'):
    componentList = ProjectHelper.listActiveComponents(project=project)
  else:
    componentList = [ProjectHelper.getDefaultComponent(project=project)]
  
  roleList = ProjectHelper.listRoles()
  
  return render_template('project/members.html', project_id=project_id, project=project, accountList=accountList, roleList=roleList, roleDefault=ProjectHelper.getDefaultRole(), submittedMembership=submittedMembership, title=title, breadcrumbs=breadcrumbs)