| Conditions | 8 |
| Total Lines | 76 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 74 | def save_data(self, trigger_id, **data): |
||
| 75 | """ |
||
| 76 | let's save the data |
||
| 77 | |||
| 78 | :param trigger_id: trigger ID from which to save data |
||
| 79 | :param data: the data to check to be used and save |
||
| 80 | :type trigger_id: int |
||
| 81 | :type data: dict |
||
| 82 | :return: the status of the save statement |
||
| 83 | :rtype: boolean |
||
| 84 | """ |
||
| 85 | from th_trello.models import Trello |
||
| 86 | |||
| 87 | kwargs = {'output_format': 'md'} |
||
| 88 | title, content = super(ServiceTrello, self).save_data(trigger_id, |
||
| 89 | data, |
||
| 90 | **kwargs) |
||
| 91 | |||
| 92 | if len(title): |
||
| 93 | # get the data of this trigger |
||
| 94 | t = Trello.objects.get(trigger_id=trigger_id) |
||
| 95 | # footer of the card |
||
| 96 | footer = self.set_card_footer(data, t) |
||
| 97 | content += footer |
||
| 98 | |||
| 99 | # 1 - we need to search the list and board where we will |
||
| 100 | # store the card so ... |
||
| 101 | |||
| 102 | # 1.a search the board_id by its name |
||
| 103 | # by retrieving all the boards |
||
| 104 | boards = self.trello_instance.list_boards() |
||
| 105 | |||
| 106 | board_id = '' |
||
| 107 | my_list = '' |
||
| 108 | for board in boards: |
||
| 109 | if t.board_name == board.name.decode('utf-8'): |
||
| 110 | board_id = board.id |
||
| 111 | break |
||
| 112 | |||
| 113 | if board_id: |
||
| 114 | # 1.b search the list_id by its name |
||
| 115 | my_board = self.trello_instance.get_board(board_id) |
||
| 116 | lists = my_board.open_lists() |
||
| 117 | # just get the open list ; not all the archive ones |
||
| 118 | for list_in_board in lists: |
||
| 119 | # search the name of the list we set in the form |
||
| 120 | if t.list_name == list_in_board.name.decode('utf-8'): |
||
| 121 | # return the (trello) list object |
||
| 122 | # to be able to add card at step 3 |
||
| 123 | my_list = my_board.get_list(list_in_board.id) |
||
| 124 | break |
||
| 125 | # we didnt find the list in that board |
||
| 126 | # create it |
||
| 127 | if my_list == '': |
||
| 128 | my_list = my_board.add_list(t.list_name) |
||
| 129 | |||
| 130 | else: |
||
| 131 | # 2 if board_id and/or list_id does not exist, create it/them |
||
| 132 | my_board = self.trello_instance.add_board(t.board_name) |
||
| 133 | # add the list that didnt exists and |
||
| 134 | # return a (trello) list object |
||
| 135 | my_list = my_board.add_list(t.list_name) |
||
| 136 | |||
| 137 | # 3 create the card |
||
| 138 | # create the Trello card |
||
| 139 | my_list.add_card(title, content) |
||
| 140 | |||
| 141 | sentence = str('trello {} created').format(data['link']) |
||
| 142 | logger.debug(sentence) |
||
| 143 | status = True |
||
| 144 | else: |
||
| 145 | sentence = "no token or link provided for trigger ID {}" |
||
| 146 | logger.critical(sentence.format(trigger_id)) |
||
| 147 | status = False |
||
| 148 | |||
| 149 | return status |
||
| 150 | |||
| 205 |