Example #1
0
def index():
    projects = []
    data = list(Project.all())
    for d in data:
        date = arrow.get(d['action_date'])
        d['action_date_str'] = '%s (%s)' % (date.format('YYYY-MM-DD'),
                                            date.humanize(arrow.now()))

    per = 3
    for i in range(int(math.ceil(len(data) / float(per)))):
        projects.append(data[per * i:min([per * (i + 1), len(data)])])

    return render_template('./project_index.html', projects=projects)
Example #2
0
def index():
    ''' Index page '''
    projects = []
    datas = list(Project.all())
    for data in datas:
        date = arrow.get(data['action_date'])
        data[
            'action_date_str'] = f"{date.format('YYYY-MM-DD')} ({date.humanize(arrow.now())})"

    per = 3
    for i in range(int(math.ceil(len(datas) / float(per)))):
        projects.append(datas[per * i:min([per * (i + 1), len(datas)])])

    return render_template('./project_index.html', projects=projects)
def service_sync_mattermost_users_position(sender, **kwargs):
    ''' Sync mattermost users position '''
    # pylint: disable=too-many-locals,too-many-branches
    pids = []
    for project in Project.all():
        if project['action_date'] >= time():
            pids.append(project['_id'])

    if not pids:
        return

    for pid in pids:
        users = {}
        for team in Team.list_by_pid(pid=pid):
            team_name = team['name'].split('-')[0].strip()

            for chief in team['chiefs']:
                if chief not in users:
                    users[chief] = []

                if team['tid'] == 'coordinator':
                    users[chief].append('­ЪїЪуИйтЈг')
                else:
                    users[chief].append(f'РГљ№ИЈухёжЋи@{team_name}')

            team['members'] = set(team['members']) - set(team['chiefs'])
            for member in team['members']:
                if member not in users:
                    users[member] = []

                users[member].append(f'{team_name}(ухётЊА)')

        mmt = MattermostTools(token=setting.MATTERMOST_BOT_TOKEN,
                              base_url=setting.MATTERMOST_BASEURL)
        mmb = MattermostBot(token=setting.MATTERMOST_BOT_TOKEN,
                            base_url=setting.MATTERMOST_BASEURL)

        for uid, value in users.items():
            mid = mmt.find_possible_mid(uid=uid)
            if not mid:
                continue

            position = [
                pid,
            ]
            position.extend(value)
            position.append(f'[{uid}]')
            mmb.put_users_patch(uid=mid, position=' '.join(position))
def service_sync_mattermost_users_position(sender, **kwargs):
    pids = []
    for project in Project.all():
        if project['action_date'] >= time():
            pids.append(project['_id'])

    if not pids:
        return

    for pid in pids:
        users = {}
        for team in Team.list_by_pid(pid=pid):
            team_name = team['name'].split('-')[0].strip()

            for chief in team['chiefs']:
                if chief not in users:
                    users[chief] = []

                if team['tid'] == 'coordinator':
                    users[chief].append('­ЪїЪуИйтЈг')
                else:
                    users[chief].append('РГљ№ИЈухёжЋи@%s' % team_name)

            team['members'] = set(team['members']) - set(team['chiefs'])
            for member in team['members']:
                if member not in users:
                    users[member] = []

                users[member].append('%s(ухётЊА)' % team_name)

        mmt = MattermostTools(token=setting.MATTERMOST_BOT_TOKEN,
                              base_url=setting.MATTERMOST_BASEURL)
        mmb = MattermostBot(token=setting.MATTERMOST_BOT_TOKEN,
                            base_url=setting.MATTERMOST_BASEURL)

        for uid in users:
            mid = mmt.find_possible_mid(uid=uid)
            if not mid:
                continue

            position = [
                pid,
            ]
            position.extend(users[uid])
            position.append('[%s]' % uid)
            mmb.put_users_patch(uid=mid, position=' '.join(position))
Example #5
0
def index() -> Text:
    ''' Index page '''
    if request.method == 'GET':
        if 'tc' not in session:
            session['tc'] = 0

        session['tc'] += 1

        return render_template('./dev_index.html', count=session['tc'])

    if request.method == 'POST':
        data = request.get_json()

        if data:
            if 'casename' in data and data['casename'] == 'get':
                accounts = []
                for user in UsersDB().find():
                    accounts.append(user)

                sessions = []
                for usession in USessionDB().find():
                    sessions.append(usession)

                return jsonify({
                    'sid': session['sid'],
                    'accounts': accounts,
                    'sessions': sessions,
                    'projects': list(Project.all()),
                })

            if 'casename' in data and data['casename'] == 'create_project':
                usession = USessionDB().find_one({'_id': session['sid']})
                if usession:
                    project_data = data['project']
                    Project.create(
                        pid=project_data['pid'],
                        name=project_data['name'],
                        owners=[
                            usession['uid'],
                        ],
                        action_date=project_data['action_date'],
                    )

    return jsonify({})
def service_sync_mattermost_projectuserin_channel(sender, **kwargs):
    pids = {}
    for project in Project.all():
        if project['action_date'] >= time(
        ) and 'mattermost_ch_id' in project and project['mattermost_ch_id']:
            pids[project['_id']] = project['mattermost_ch_id']

    if not pids:
        return

    mmt = MattermostTools(token=setting.MATTERMOST_BOT_TOKEN,
                          base_url=setting.MATTERMOST_BASEURL)
    for pid in pids:
        uids = set()
        for team in Team.list_by_pid(pid=pid):
            uids.update(team['chiefs'])
            uids.update(team['members'])

        for uid in uids:
            mid = mmt.find_possible_mid(uid=uid)
            if mid:
                r = mmt.post_user_to_channel(channel_id=pids[pid], uid=mid)
                logger.info(r.json())