Esempio n. 1
0
def create_fax_entry(metadata):
	from faxcelerate.fax.models import Fax
	def m(key):
		try:
			return metadata[key]
		except KeyError:
			return None
	f = Fax()
	f.comm_id = m('commid')
	f.station_id = m('tsi')
	f.msn = m('msn')
	f.received_on = m('date')
	f.time_to_receive = m('jobduration')
	f.conn_duration = m('connduration')
	f.pages = m('pages')
	f.params = m('params')
	f.reason = m('reason')
	f.filename = m('filename')
	f.caller_id = m('callerid')
	f.save()
	return f
Esempio n. 2
0
    def handle(self, *args, **options):

        if len(args) < 4:
            raise AttributeError

        qfile, devid, commid, msg = map(str.rstrip, args[:4])
        callid = map(str.strip, args[4:])

        logger.info('Processing received fax %s', commid)
        logger.debug('Fax %s in file %s, received on device %s, message: %s', commid, qfile, devid, msg)

        filename = settings.FAX_SPOOL_DIR + '/' + qfile

        fax = Fax()
        fax.received_on = datetime.fromtimestamp(os.path.getmtime(filename))
        fax.filename = qfile
        fax.device = devid
        fax.comm_id = commid
        fax.reason = msg
        fax.status = 1  # Success
        # TODO improve caller_id
        fax.caller_id = str(callid)

        if os.path.isfile(filename):
            fax.update_from_tiff()
        else:
            fax.error = True
            fax.status = 2  # Error
            logging.info("Fax %s has an error; reason: %s", commid, msg)

        fax.update_from_logfile()
        if fax.station_id == fax.caller_id or fax.station_id == '-':
            fax.station_id = None
        fax.set_sender()
        fax.save()
        FaxImage(fax).cache_thumbnails()