| Conditions | 8 |
| Total Lines | 76 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # coding: utf-8 |
||
| 85 | def save_data(self, trigger_id, **data): |
||
| 86 | """ |
||
| 87 | let's save the data |
||
| 88 | |||
| 89 | :param trigger_id: trigger ID from which to save data |
||
| 90 | :param data: the data to check to be used and save |
||
| 91 | :type trigger_id: int |
||
| 92 | :type data: dict |
||
| 93 | :return: the status of the save statement |
||
| 94 | :rtype: boolean |
||
| 95 | """ |
||
| 96 | from th_trello.models import Trello |
||
| 97 | |||
| 98 | data['output_format'] = 'md' |
||
| 99 | title, content = super(ServiceTrello, self).save_data(trigger_id, |
||
| 100 | **data) |
||
| 101 | |||
| 102 | if len(title): |
||
| 103 | # get the data of this trigger |
||
| 104 | t = Trello.objects.get(trigger_id=trigger_id) |
||
| 105 | # footer of the card |
||
| 106 | footer = self.set_card_footer(data, t) |
||
| 107 | content += footer |
||
| 108 | |||
| 109 | # 1 - we need to search the list and board where we will |
||
| 110 | # store the card so ... |
||
| 111 | |||
| 112 | # 1.a search the board_id by its name |
||
| 113 | # by retrieving all the boards |
||
| 114 | boards = self.trello_instance.list_boards() |
||
| 115 | |||
| 116 | board_id = '' |
||
| 117 | my_list = '' |
||
| 118 | for board in boards: |
||
| 119 | if t.board_name == board.name: |
||
| 120 | board_id = board.id |
||
| 121 | break |
||
| 122 | |||
| 123 | if board_id: |
||
| 124 | # 1.b search the list_id by its name |
||
| 125 | my_board = self.trello_instance.get_board(board_id) |
||
| 126 | lists = my_board.open_lists() |
||
| 127 | # just get the open list ; not all the archive ones |
||
| 128 | for list_in_board in lists: |
||
| 129 | # search the name of the list we set in the form |
||
| 130 | if t.list_name == list_in_board.name: |
||
| 131 | # return the (trello) list object |
||
| 132 | # to be able to add card at step 3 |
||
| 133 | my_list = my_board.get_list(list_in_board.id) |
||
| 134 | break |
||
| 135 | # we didnt find the list in that board |
||
| 136 | # create it |
||
| 137 | if my_list == '': |
||
| 138 | my_list = my_board.add_list(t.list_name) |
||
| 139 | |||
| 140 | else: |
||
| 141 | # 2 if board_id and/or list_id does not exist, create it/them |
||
| 142 | my_board = self.trello_instance.add_board(t.board_name) |
||
| 143 | # add the list that didnt exists and |
||
| 144 | # return a (trello) list object |
||
| 145 | my_list = my_board.add_list(t.list_name) |
||
| 146 | |||
| 147 | # 3 create the card |
||
| 148 | # create the Trello card |
||
| 149 | my_list.add_card(title, content) |
||
| 150 | |||
| 151 | sentence = str('trello {} created').format(data['link']) |
||
| 152 | logger.debug(sentence) |
||
| 153 | status = True |
||
| 154 | else: |
||
| 155 | sentence = "no token or link provided for trigger ID " \ |
||
| 156 | "{}".format(trigger_id) |
||
| 157 | update_result(trigger_id, msg=sentence, status=False) |
||
| 158 | status = False |
||
| 159 | |||
| 160 | return status |
||
| 161 | |||
| 214 |