Exemplo n.º 1
0
    def create(self, data):
        category = BoardCategory()
        category.board_id = data.get('board_id', 0)
        if data.get('name', ''):
            category.name = data.get('name', '')
        if data.get('description', ''):
            category.description = data.get('description', '')
        if data.get('manager_id', 0):
            category.manager_id = data.get('manager_id', 0)
        category.save()

        if data.get('stages', ''):
            for r in data['stages']:
                category_stage = BoardCategoryStage()
                category_stage.board_category_id = category.id
                category_stage.board_stage_id = r['board_stage_id']
                category_stage.manager_id = r['manager_id']
                category_stage.save()

        if data.get('responsibilities', ''):
            for r in data.get('responsibilities'):
                responsibility = BoardCategoryResponsibility()
                responsibility.board_category_id = category.id
                responsibility.user_id = r['user_id']
                responsibility.description = r['description']
                responsibility.save()

        helpers.CommonHelper().update_cell_assignment(category.board_id)

        return category
Exemplo n.º 2
0
    def get_data(self, data):
        story = BoardStory.objects.get(pk=data['id'])
        ##get Logs
        logs = BoardStoryLog.objects.filter(
            story_id=story.id).order_by('-timestamp')[:10]
        arr_logs = []
        for log in logs:
            time_ago = helpers.CommonHelper().diff_time(log.timestamp)
            arr_logs.append({
                'id': log.id,
                'username': log.user.name,
                'user_id': log.user.id,
                'description': log.description,
                'timestamp': time_ago,
                'assignee': log.assignee
            })

        ##get Logs unlimit
        logs = BoardStoryLog.objects.filter(
            story_id=story.id).order_by('-timestamp')
        arr_logs_unlimit = []
        for log in logs:
            time_ago = helpers.CommonHelper().diff_time(log.timestamp)
            arr_logs_unlimit.append({
                'id': log.id,
                'username': log.user.name,
                'user_id': log.user.id,
                'description': log.description,
                'timestamp': time_ago,
                'assignee': log.assignee
            })
        return {
            'story_id': story.id,
            'array_logs': arr_logs,
            'array_log_unlimit': arr_logs_unlimit
        }
Exemplo n.º 3
0
 def get_data(self, data):
     story = BoardStory.objects.get(pk=data['id'])
     ##get Logs
     cmts = BoardStoryComment.objects.filter(story_id=story.id)
     arr_cmts = []
     for cmt in cmts:
         time_ago = helpers.CommonHelper().diff_time(cmt.timestamp)
         arr_cmts.append({
             'id': cmt.id,
             'username': cmt.user.name,
             'description': cmt.description,
             'timestamp': time_ago
         })
     return {
         'story_id': story.id,
         'board_id': story.board_id,
         'arr_cmts': arr_cmts
     }
Exemplo n.º 4
0
    def update(self, data):
        stage = BoardStage.objects.get(pk=data['id'])
        if data.get('name', ''):
            stage.name = data.get('name', '')
        if data.get('description', ''):
            stage.description = data.get('description', '')
        if data.get('sort_order', 0):
            stage.sort_order = data.get('sort_order')

        if data.get('bg_color', '#000000'):
            stage.bg_color = data.get('bg_color', '#000000')
        if data.get('text_color', '#000000'):
            stage.text_color = data.get('text_color', '#000000')
        if data.get('result_code', ''):
            stage.result_code = data.get('result_code', '')

        stage.manager_id = data.get('manager_id', 0)
        stage.save()

        if data.get('instructions', ''):
            BoardStageInstruction.objects.filter(
                board_stage_id=stage.id).delete()
            for r in data.get('instructions'):
                instruction = BoardStageInstruction()
                instruction.board_stage_id = stage.id
                instruction.instruction = r['instruction']
                instruction.save()

        if data.get('responsibilities', ''):
            BoardStageResponsibility.objects.filter(
                board_stage_id=stage.id).delete()
            for r in data.get('responsibilities'):
                responsibility = BoardStageResponsibility()
                responsibility.board_stage_id = stage.id
                responsibility.user_id = r['user_id']
                responsibility.description = r['description']
                responsibility.save()

        helpers.CommonHelper().update_cell_assignment(stage.board_id)

        return stage
Exemplo n.º 5
0
    def create(self, data):
        if data.get('id', 0) == 0:
            return 1

        root_board = Board.objects.get(pk=data.get('id'))
        board = Board()
        board.name = data.get('name', '')
        board.description = data.get('description', '')
        if data.get('status', ''):
            board.status = data.get('status')
        if data.get('start_date', ''):
            board.start_date = data.get('start_date')
        if data.get('end_date', ''):
            board.end_date = data.get('end_date')
        if data.get('is_template', ''):
            board.is_template = data.get('is_template')
        board.save()

        #Tag
        tags = BoardTag.objects.filter(board_id=root_board.id)
        for val in tags:
            new_tag = BoardTag()
            new_tag.board_id = board.id
            new_tag.name = val.name
            new_tag.icon = val.icon
            new_tag.is_visible = val.is_visible
            new_tag.save()

        # - Users
        if data.get('users', ''):
            for user_id in data['users']:
                board_user = BoardUser()
                board_user.board_id = board.id
                board_user.user_id = user_id
                board_user.save()

        # - Responsibility
        if data.get('board_responsibility', ''):
            for resp in data['board_responsibility']:
                board_responsibility = BoardResponsibility()
                board_responsibility.board_id = board.id
                board_responsibility.user_id = resp['manager']
                board_responsibility.description = resp['description']
                board_responsibility.save()

        # - Stages
        try:
            stages = {}
            for r in BoardStage.objects.filter(board_id=root_board.id):
                old_id = int(r.id)
                r.board_id = board.id
                r.pk = None
                r.save()
                new_id = int(r.id)
                stages[old_id] = new_id
        except BoardStage.DoesNotExist:
            pass

        # - Categories
        try:
            categories = {}
            for r in BoardCategory.objects.filter(board_id=root_board.id):
                old_id = int(r.id)
                r.board_id = board.id
                r.pk = None
                r.save()
                new_id = int(r.id)
                categories[old_id] = new_id
        except BoardCategory.DoesNotExist:
            pass

        # - Categories Stage
        try:
            stages_mgrs = root_board.boardstage_set.exclude(
                manager_id=None).values_list('manager_id').distinct()
            category_mgrs = root_board.boardcategory_set.exclude(
                manager_id=None).values_list('manager_id').distinct()
            managers = list(stages_mgrs) + list(category_mgrs)
            for r in BoardCategoryStage.objects.filter(
                    manager_id__in=managers):
                r.board_category_id = categories[r.board_category_id]
                r.board_stage_id = stages[r.board_stage_id]
                r.pk = None
                r.save()
        except BoardCategoryStage.DoesNotExist:
            pass

        # - Assignment
        helpers.CommonHelper().update_cell_assignment(board.id)

        # - Goals
        try:
            for r in BoardGoal.objects.filter(board_id=root_board.id):
                r.board_id = board.id
                r.pk = None
                r.save()
        except BoardGoal.DoesNotExist:
            pass

        return board
Exemplo n.º 6
0
    def get_data(self, data):
        current_user_id = data['user_id']
        arr_stories = []
        arr_your_board = []
        arr_your_goal = []

        ## data board
        arr_board = []
        arr_event = []
        board = Board.objects.get(pk=data['id'])

        today = datetime.now()
        board_events = BoardEvent.objects.filter(
            board_id=board.id, event_date__gte=today).order_by('event_date')
        for event in board_events:
            time_ago = helpers.CommonHelper().diff_time_today(event.event_date)
            arr_event.append({
                'id':
                event.id,
                'event_date':
                event.event_date.strftime('%d-%m-%Y'),
                'event_day':
                event.event_date.strftime("%d"),
                'event_month':
                event.event_date.strftime('%m-%Y'),
                'name':
                event.name,
                'board_id':
                event.board_id,
                'timestamp':
                time_ago
            })

        # Users
        board_users = []
        records = BoardUser.objects.filter(board_id=board.id)
        for r in records:
            board_users.append({
                'id': r.user.id,
                'name': r.user.name,
            })

        ## your goal
        board_goals = BoardGoal.objects.filter(user_id=current_user_id)
        for goal in board_goals:
            arr_your_goal.append({
                'id':
                goal.id,
                'board_id':
                goal.board_id,
                'name':
                goal.name,
                'status':
                goal.status,
                'category':
                goal.board_category.name if goal.board_category else '',
                'username':
                goal.user.name if goal.user else '',
                'user_id':
                goal.user_id
            })

        return {
            'stories': arr_stories,
            'your_board': arr_your_board,
            'your_goal': arr_your_goal,
            'board_users': board_users,
            'event': arr_event
        }