Esempio n. 1
0
    def save(self, commit=True):
        cd = self.cleaned_data
        tool_ids = cd['tools'].split(',')

        obj_dict = {}

        if not self.cleaned_data['tools']:
            return obj_dict

        for tool_id in tool_ids:
            tool = get_object_or_404(Tool, id = tool_id)
            response = tool.loan(cd['employee'], cd['construction_site'])
            try:
                obj_dict[response].append(tool.name)
            except KeyError:
                obj_dict[response] = [tool.name]

        try:
            if cd['employee']:
                # Don't send any messages if we loan to a construction site
                handle_loan_messages(obj_dict[MESSAGES.TOOL_LOAN_SUCCESS], 
                                     cd['employee'])
        except KeyError:
            pass

        return obj_dict
Esempio n. 2
0
    def save(self, commit=True):
        cd = self.cleaned_data

        obj_dict = {}
        response = self.tool.loan(cd['employee'], cd['construction_site'])
        obj_dict[response] = [self.tool.name]

        handle_loan_messages(obj_dict[MESSAGES.TOOL_LOAN_SUCCESS], 
                             cd['employee'])

        return obj_dict