Exemplo n.º 1
0
def objects():

    Client = rt.modules.pcsw.Client

    for obj in Client.objects.exclude(card_number=''):
        fn = obj.get_image_path()
        if not os.path.exists(fn):
            src = get_image_path(None)
            #dd.logger.info("20150531 copy %s to %s...", src, fn)
            rt.makedirs_if_missing(os.path.dirname(fn))
            shutil.copyfile(src, fn)
            yield obj  # actually there's no need to save obj, but we
Exemplo n.º 2
0
    def print_multiple(self, ar, qs):
        pdfs = []
        for obj in qs:
            #~ assert isinstance(obj,CachedPrintable)
            if obj.printed_by_id is None:
                obj.build_target(ar)
            pdf = obj.get_target_name()
            assert pdf is not None
            pdfs.append(pdf)

        mf = TmpMediaFile(ar, 'pdf')
        rt.makedirs_if_missing(os.path.dirname(mf.name))
        merge_pdfs(pdfs, mf.name)
        return mf
Exemplo n.º 3
0
    def print_multiple(self, ar, qs):
        pdfs = []
        for obj in qs:
            # assert isinstance(obj,CachedPrintable)
            if obj.printed_by_id is None:
                obj.build_target(ar)
            pdf = obj.get_target_name()
            assert pdf is not None
            pdfs.append(pdf)

        mf = TmpMediaFile(ar, 'pdf')
        rt.makedirs_if_missing(os.path.dirname(mf.name))
        merge_pdfs(pdfs, mf.name)
        return mf
Exemplo n.º 4
0
 def before_build(self, bm, elem):
     """Return the target filename if a document needs to be built,
     otherwise return ``None``.
     """
     elem.before_printable_build(bm)
     filename = bm.get_target_name(self, elem)
     if not filename:
         return
     if os.path.exists(filename):
         logger.debug(u"%s %s -> overwrite existing %s.",
                      bm, elem, filename)
         os.remove(filename)
     else:
         #~ logger.info("20121221 makedirs_if_missing %s",os.path.dirname(filename))
         rt.makedirs_if_missing(os.path.dirname(filename))
     logger.debug(u"%s : %s -> %s", bm, elem, filename)
     return filename
Exemplo n.º 5
0
 def before_build(self, bm, elem):
     """Return the target filename if a document needs to be built,
     otherwise return ``None``.
     """
     elem.before_printable_build(bm)
     filename = bm.get_target_name(self, elem)
     if not filename:
         return
     if os.path.exists(filename):
         logger.debug(u"%s %s -> overwrite existing %s.", bm, elem,
                      filename)
         os.remove(filename)
     else:
         #~ logger.info("20121221 makedirs_if_missing %s",os.path.dirname(filename))
         rt.makedirs_if_missing(os.path.dirname(filename))
     logger.debug(u"%s : %s -> %s", bm, elem, filename)
     return filename
Exemplo n.º 6
0
 def ok(ar2):
     logger.info(
         "%s made local template copy %s", ar.user, local_file)
     rt.makedirs_if_missing(dirname(local_file))
     shutil.copy(filename, local_file)
     doit(ar2)
Exemplo n.º 7
0
    def card2client(self, data):
        """
        Convert the data coming from the card into database fields to be
        stored in the card holder.
        """
        kw = dict()
        # raw_data = data['card_data']

        kw.update(national_id=ssin.format_ssin(str(data.national_number)))
        kw.update(first_name=data.firstnames or '')
        kw.update(middle_name=data.first_letter_of_third_given_name or '')
        kw.update(last_name=data.surname or '')

        card_number = str(data.card_number)
        holder_model = dd.plugins.beid.holder_model

        if data.PHOTO_FILE:
            if not card_number:
                raise Exception("20150730 photo data but no card_number ")

            fn = holder_model.card_number_to_image_path(card_number)
            if not fn.exists():
                # logger.warning("Overwriting existing image file %s.", fn)
                rt.makedirs_if_missing(os.path.dirname(fn))
            try:
                fp = open(fn, 'wb')
                # fp.write(data.PHOTO_FILE)
                fp.write(base64.b64decode(data.PHOTO_FILE))
                fp.close()
            except IOError as e:
                logger.warning("Failed to store image file %s : %s", fn, e)

            #~ print 20121117, repr(data['picture'])
            #~ kw.update(picture_data_encoded=data['picture'])

        if isinstance(data.date_of_birth, six.string_types):
            data.date_of_birth = IncompleteDate.parse(data.date_of_birth)
            # IncompleteDate(
            #     *data.date_of_birth.split('-'))
        kw.update(birth_date=data.date_of_birth)
        kw.update(
            card_valid_from=dateparser.parse(data.validity_begin_date).date())
        kw.update(
            card_valid_until=dateparser.parse(data.validity_end_date).date())

        kw.update(card_number=card_number)
        kw.update(card_issuer=data.issuing_municipality)
        if data.nobility:
            kw.update(noble_condition=data.nobility)
        if data.address_street_and_number:
            kw = street2kw(data.address_street_and_number, **kw)
        if data.address_zip:
            kw.update(zip_code=str(data.address_zip))
        if data.location_of_birth:
            kw.update(birth_place=data.location_of_birth)

        pk = data.eidreader_country
        country = rt.models.countries.Country.objects.get(isocode=pk)
        kw.update(country=country)
        if data.address_municipality:
            kw.update(city=rt.models.countries.Place.lookup_or_create(
                'name', data.address_municipality, country=country))

        msg1 = "BeIdReadCardToClientAction %s" % kw.get('national_id')

        def sex2gender(sex):
            c0 = sex[0].upper()
            if c0 == 'M':
                return dd.Genders.male
            if c0 in 'FWV':
                return dd.Genders.female
            logger.warning("%s : invalid gender code %r", msg1, sex)

        kw.update(gender=sex2gender(data.gender))

        def doctype2cardtype(dt):
            #~ if dt == 1: return BeIdCardTypes.get_by_value("1")
            rv = BeIdCardTypes.get_by_value(str(dt))
            # logger.info("20130103 documentType %r --> %r", dt, rv)
            return rv

        kw.update(card_type=doctype2cardtype(data.document_type))
        return kw
Exemplo n.º 8
0
 def ok(ar2):
     logger.info(
         "%s made local template copy %s", ar.user, local_file)
     rt.makedirs_if_missing(os.path.dirname(local_file))
     shutil.copy(filename, local_file)
     doit(ar2)