示例#1
0
    def getInteractions(self, force_update=False):
        self.interactions = {}
        case_id = str(self.id)
        int_file = shelve.open('interactions', writeback=True)

        if force_update:
            self.logger.debug('Updating interactions for case #%s...' % case_id)
            res, content = fn.getFromDesk('interactions', case_id=self.id)
            int_file[case_id] = data = content
        else:
            try:
                data = int_file[case_id]
            except KeyError:
                self.logger.debug(
                    'Downloading interactions for case #%s...' % case_id)
                res, content = fn.getFromDesk('interactions', case_id=self.id)
                int_file[case_id] = data = content
            finally:
                int_file.close()
        try:
            for result in data['results']:
                theInteraction = result['interaction']
                interaction_id = theInteraction['id']
                self.interactions[interaction_id] = Interaction(theInteraction)
            return self.interactions
        except:
            self.logger.error('Status: %s' % res['status'])
            sys.exit()
示例#2
0
    def __init__(self, case_id=None, data=None, force_update=False):
        # Only accept values for one of either case_id or data, not neither/both
        self.logger = logging.getLogger('desk.classes.Case')
        self.logger.debug('creating an instance of Case')

        if not (case_id or data):
            self.logger.error('When instantiating a Case you must specify '
                'either the case data or case ID.')
            sys.exit()
        pref_attrs = {'case_status_type': 'status'}
        case_file = shelve.open('cases', writeback=True)

        try:
            # If possible, convert case id to string. 'int' is used to avoid
            # converting None to a string, which is bad.
            case_id = str(int(case_id))
        except:
            # But no big deal if you can't, we'll catch the error elsewhere.
            pass

        if force_update:
            try:
                # Re-download the case from Desk using the case id.
                self.logger.debug('Updating case #%s...' % case_id)
                res, content = fn.getFromDesk('cases/'+case_id)
                case_file[case_id] = data = content['case']
            except NameError:
                # Catch errors due to no case id specified.
                self.logger.error('When specifying force_update in a case '
                        'instantiation, make sure to specify id_num too.')
                sys.exit()
            finally:
                case_file.close()
        else:
            try:
                # Try to grab case data from cache.
                data = case_file[case_id]
            except TypeError:
                # Data provided but ID not included. Store case using data from
                # case search.
                self.logger.debug("We have data for this case and we don't "
                        "have the case yet so let's use the data")
            except KeyError:
                # ID but no data passed. Data not in cache. Download from Desk.
                self.logger.debug('Downloading case #%s...' % case_id)
                res, content = fn.getFromDesk('cases/'+case_id)
                case_file[case_id] = data = content['case']
            finally:
                case_file.close()

        super(Case, self).__init__(data, pref_attrs=pref_attrs)
示例#3
0
    def __init__(self, force_update=False, **params):
        self.logger = logging.getLogger('desk.classes.CaseSearch')
        self.logger.debug('creating an instance of CaseSearch')

        res, content = fn.getFromDesk('cases', **params)
        self.data = content
        self.params = params
        try:
            super(CaseSearch, self).__init__(self.data)
        except:
            self.logger.error('Status: %s' % res['status'])
        
        new, updated, old = fn.updateSieve(self)        
        self.cases = self.new = self.updated = self.old = {}

        for result in self.results:
            case_id = result['case']['id']
            if force_update:
                self.logger.debug('Update forced on %s' % case_id)
                self.cases[case_id] = self.updated[case_id] = Case(
                    case_id=case_id, force_update=True)
            elif str(case_id) in old:
                self.logger.debug('No update needed for %s' % case_id)
                self.cases[case_id] = self.old[case_id] = Case(case_id=case_id)
            elif str(case_id) in updated:
                self.logger.debug('Update needed for %s' % case_id)
                self.cases[case_id] = self.updated[case_id] = Case(
                    case_id=case_id, force_update=True)
            elif str(case_id) in new:
                self.logger.debug('Data needed for new case %s' % case_id)
                self.cases[case_id] = self.new[case_id] = Case(
                        data=result['case'])