Пример #1
0
def get_subscriptions_for_project(project_id):
    """
    Return all subscriptions for given project.
    """
    subscriptions = Subscription.query.join(Task).filter(
        Task.project_id == project_id)
    return fields.serialize_list(subscriptions)
Пример #2
0
def get_build_jobs_for_project(project_id):
    """
    Return all build_jobs for given project.
    """
    build_jobs = BuildJob.query.join(Playlist).filter(
        Playlist.project_id == project_id)
    return fields.serialize_list(build_jobs)
Пример #3
0
def get_desktop_login_logs(person_id):
    """
    Get all logs for user desktop logins.
    """
    logs = (DesktopLoginLog.query.filter(
        DesktopLoginLog.person_id == person_id).order_by(
            DesktopLoginLog.date.desc()).all())
    return fields.serialize_list(logs)
Пример #4
0
 def get(self, person_id, year, month):
     user_service.check_person_access(person_id)
     try:
         timespents = time_spents_service.get_time_spents_for_month(
             year, month, person_id=person_id)
         return fields.serialize_list(timespents)
     except WrongDateFormatException:
         abort(404)
Пример #5
0
def delete_news_for_comment(comment_id):
    """
    Delete all news related to comment. It's mandatory to be able to delete the
    comment afterwards.
    """
    news_list = News.get_all_by(comment_id=comment_id)
    for news in news_list:
        news.delete()
    return fields.serialize_list(news_list)
Пример #6
0
def get_time_spents(person_id, date):
    """
    Return time spents for given person and date.
    """
    try:
        time_spents = TimeSpent.query.filter_by(person_id=person_id,
                                                date=date).all()
    except DataError:
        raise WrongDateFormatException
    return fields.serialize_list(time_spents)
Пример #7
0
def delete_news_for_comment(comment_id):
    """
    Delete all news related to comment. It's mandatory to be able to delete the
    comment afterwards.
    """
    news_list = News.get_all_by(comment_id=comment_id)
    if len(news_list) > 0:
        task = tasks_service.get_task(news_list[0].task_id)
        for news in news_list:
            news.delete()
            events.emit("news:delete", {"news_id": news.id},
                        project_id=task["project_id"])
    return fields.serialize_list(news_list)
Пример #8
0
def mark_notifications_as_read():
    """
    Mark all recent notifications for current_user as read. It is useful
    to mark a list of notifications as read after an user retrieved them.
    """
    current_user = persons_service.get_current_user_raw()
    notifications = (Notification.query.filter_by(
        person_id=current_user.id,
        read=False).order_by(Notification.created_at).limit(100).all())

    for notification in notifications:
        notification.update({"read": True})

    return fields.serialize_list(notifications)
Пример #9
0
def get_paginated_results(query, page, relations=False):
    """
    Apply pagination to the query object.
    """
    if page < 1:
        entries = query.all()
        return fields.serialize_list(entries)
    else:
        limit = app.config["NB_RECORDS_PER_PAGE"]
        total = query.count()
        offset = (page - 1) * limit

        nb_pages = int(math.ceil(total / float(limit)))
        query = query.limit(limit)
        query = query.offset(offset)

        if total < offset:
            result = {
                "data": [],
                "total": 0,
                "nb_pages": nb_pages,
                "limit": limit,
                "offset": offset,
                "page": page,
            }
        else:
            models = fields.serialize_models(query.all(), relations=relations)
            result = {
                "data": models,
                "total": total,
                "nb_pages": nb_pages,
                "limit": limit,
                "offset": offset,
                "page": page,
            }
        return result
Пример #10
0
def delete_notifications_for_comment(comment_id):
    notifications = Notification.get_all_by(comment_id=comment_id)
    for notification in notifications:
        notification.delete()
    return fields.serialize_list(notifications)
Пример #11
0
def get_task_statuses():
    """
    Get all available task status.
    """
    return fields.serialize_list(TaskStatus.query.all())
Пример #12
0
 def get(self):
     return fields.serialize_list(Organisation.query.all())
Пример #13
0
def get_schedule_items(project_id):
    """
    Get all project schedule items (mainly for sync purpose).
    """
    schedule_items = ScheduleItem.query.filter_by(project_id=project_id).all()
    return fields.serialize_list(schedule_items)
Пример #14
0
def get_task_statuses():
    return fields.serialize_list(TaskStatus.query.all())