Exemplo n.º 1
0
def create_time_log(request):
    """runs when creating a time_log
    """
    logger.debug('create_time_log method starts')
    task_id = request.params.get('task_id')

    logger.debug('task_id : %s' % task_id)

    task = Task.query.filter(Task.id == task_id).first()

    if not task:
        return Response('No task with id %s found' % task_id, 500)

    #**************************************************************************
    # collect data
    resource_id = request.params.get('resource_id', None)
    resource = User.query.filter(User.id == resource_id).first()

    start_date = get_date(request, 'start')
    end_date = get_date(request, 'end')

    description = request.params.get('description', '')

    logger.debug('task_id     : %s' % task_id)
    logger.debug('task        : %s' % task)
    logger.debug('resource_id : %s' % resource_id)
    logger.debug('start_date  : %s' % start_date)
    logger.debug('end_date    : %s' % end_date)

    if task and resource and start_date and end_date:
        # we are ready to create the time log
        # TimeLog should handle the extension of the effort
        logger.debug('got all the data')
        try:
            assert isinstance(task, Task)
            task.create_time_log(resource, start_date, end_date)
        except (OverBookedError, TypeError, DependencyViolationError) as e:
            converter = StdErrToHTMLConverter(e)
            response = Response(converter.html(), 500)
            transaction.abort()
            return response
        else:
            request.session.flash(
                'success: Time log for <strong>%s</strong> is saved for '
                'resource <strong>%s</strong>.' % (task.name,resource.name)
            )
        logger.debug('no problem here!')
    else:
        response = Response(
            'There are missing parameters: '
            'task_id: %s, resource_id: %s' % (task_id, resource_id), 500
        )
        transaction.abort()
        return response

    logger.debug('successfully created time log!')
    response = Response('successfully created time log!')

    return response
Exemplo n.º 2
0
def update_project(request):
    """called when updating a Project
    """
    logged_in_user = get_logged_in_user(request)

    # parameters
    project_id = request.params.get('project_id', -1)
    project = Project.query.filter_by(id=project_id).first()

    name = request.params.get('name')

    fps = int(request.params.get('fps'))

    imf_id = request.params.get('image_format', -1)
    imf = ImageFormat.query.filter_by(id=imf_id).first()

    repo_id = request.params.get('repository_id', -1)
    repo = Repository.query.filter_by(id=repo_id).first()

    structure_id = request.params.get('structure_id', -1)
    structure = Structure.query.filter_by(id=structure_id).first()

    lead_id = request.params.get('lead_id', -1)
    lead = User.query.filter_by(id=lead_id).first()

    status_id = request.params.get('status_id', -1)
    status = Status.query.filter_by(id=status_id).first()

    # get the dates
    start = get_date(request, 'start')
    end = get_date(request, 'end')

    if project and name and imf and repo and structure and lead and \
            status:

        project.name = name
        project.image_format = imf
        project.repository = repo
        project.updated_by = logged_in_user
        project.date_updated = datetime.datetime.now()
        project.fps = fps
        project.structure = structure
        project.lead = lead
        project.status = status
        project.start = start
        project.end = end

        DBSession.add(project)

    else:
        logger.debug('there are missing parameters')
        HTTPServerError()

    return HTTPOk()
Exemplo n.º 3
0
def update_time_log(request):
    """runs when updating a time_log
    """
    logger.debug('inside update_time_log')
    # time_log_id = int(request.params.get('time_log_id'))
    time_log_id = request.matchdict.get('id', -1)
    time_log = TimeLog.query.filter_by(id=time_log_id).first()

    #**************************************************************************
    # collect data
    resource_id = int(request.params.get('resource_id', None))
    resource = User.query.filter(User.id == resource_id).first()

    start_date = get_date(request, 'start')
    end_date = get_date(request, 'end')

    description = request.params.get('description', '')

    logger.debug('time_log_id : %s' % time_log_id)
    logger.debug('resource_id : %s' % resource_id)
    logger.debug('start         : %s' % start_date)
    logger.debug('end           : %s' % end_date)

    if time_log and resource and start_date and end_date:
        # we are ready to create the time log
        # TimeLog should handle the extension of the effort

        try:
            time_log.start = start_date
            time_log.end = end_date
            time_log.description = description
            time_log.resource = resource
        except OverBookedError as e:
            logger.debug('e.message: %s' % str(e))
            response = Response(str(e), 500)
            transaction.abort()
            return response
        else:
            DBSession.add(time_log)
            request.session.flash(
                'success:Time log for <strong>%s</strong> is updated..'
                % time_log.task.name
            )
            logger.debug('successfully updated time log!')

    return Response('TimeLog has been updated successfully')