def _add_child_pictures_to_typo3(self, cr, uid, ids, context=None):
        for child in self.browse(cr, uid, ids, context):

            head_image = child.code + "_h.jpg"
            full_image = child.code + "_f.jpg"

            file_head = open(head_image, "wb")
            file_head.write(base64.b64decode(child.portrait))
            file_head.close()

            file_fullshot = open(full_image, "wb")
            file_fullshot.write(base64.b64decode(child.fullshot))
            file_fullshot.close()

            Sync_typo3.add_child_photos(head_image, full_image)
    def _add_child_pictures_to_typo3(self, cr, uid, ids, context=None):
        for child in self.browse(cr, uid, ids, context):
            head_image = child.local_id + "_h.jpg"
            full_image = child.local_id + "_f.jpg"

            file_head = open(head_image, "wb")
            file_head.write(base64.b64decode(child.portrait))
            file_head.close()

            file_fullshot = open(full_image, "wb")
            file_fullshot.write(base64.b64decode(child.fullshot))
            file_fullshot.close()

            Sync_typo3.add_child_photos(head_image, full_image)
            os.remove(head_image)
            os.remove(full_image)
    def child_remove_from_typo3(self, cr, uid, ids, context=None):
        child_codes = list()

        for child in self.browse(cr, uid, ids, context):
            child_uid = self._get_typo3_child_id(cr, uid, child.code)
            Sync_typo3.request_to_typo3(
                "delete from tx_drechildpoolmanagement_childpools_children_mm"
                " where uid_foreign={0};"
                "delete from tx_drechildpoolmanagement_domain_model_children "
                "where child_key='{1}';".format(child_uid, child.code), 'upd')
            state = 'R' if child.has_been_sponsored else 'N'
            child.write({'state': state})
            child_codes.append(child.code)

        Sync_typo3.delete_child_photos(child_codes)
        return Sync_typo3.sync_typo3_index()
    def child_remove_from_typo3(self, cr, uid, ids, context=None):
        child_codes = list()

        for child in self.browse(cr, uid, ids, context):
            child_uid = self._get_typo3_child_id(cr, uid, child.code)
            Sync_typo3.request_to_typo3(
                "delete from tx_drechildpoolmanagement_childpools_children_mm"
                " where uid_foreign={};"
                "delete from tx_drechildpoolmanagement_domain_model_children "
                "where child_key='{}';".format(child_uid, child.code), 'upd')
            state = 'R' if child.has_been_sponsored else 'N'
            child.write({'state': state})
            child_codes.append(child.code)

        Sync_typo3.delete_child_photos(child_codes)
        return Sync_typo3.sync_typo3_index()
    def project_add_to_typo3(self, cr, uid, ids, context=None):
        # Solve the encoding problems on child's descriptions
        reload(sys)
        sys.setdefaultencoding('UTF8')

        today_ts = calendar.timegm(
            datetime.today().utctimetuple())

        # Returns the german projects (parents) ids on typo3
        res = list()

        for project in self.browse(cr, uid, ids, context):
            project_desc_de = project.description_de.replace('\'', '\'\'')
            project_desc_fr = project.description_fr.replace('\'', '\'\'')
            if not project.country_id:
                project.update_informations()
                project = self.browse(cr, uid, project.id, context)

            # German description (parent)
            Sync_typo3.request_to_typo3(
                "insert into "
                "tx_drechildpoolmanagement_domain_model_projects"
                "(project_key, country, description,"
                "tstamp, crdate, l10n_parent) "
                "values ('{0}','{1}','{2}','{3}','{4}','{5}');".format(
                    project.code, project.country_id.name,
                    project_desc_de, today_ts,
                    today_ts, 0), 'upd')

            parent_id = self.get_project_from_typo3(
                cr, uid, project.code)
            res.append(parent_id)

            # French description
            Sync_typo3.request_to_typo3(
                "insert into "
                "tx_drechildpoolmanagement_domain_model_projects"
                "(project_key, country, description,"
                "tstamp, crdate, l10n_parent, sys_language_uid) "
                "values ('{0}','{1}','{2}','{3}','{4}','{5}',1);".format(
                    project.code, project.country_id.name,
                    project_desc_fr, today_ts,
                    today_ts, parent_id), 'upd')

            return res
    def get_project_from_typo3(self, cr, uid, project_code):
        res = json.loads(Sync_typo3.request_to_typo3(
            "select * "
            "from tx_drechildpoolmanagement_domain_model_projects "
            "where project_key='%s'" % project_code, 'sel'))
        if res:
            return res[0]['uid']

        return False
    def get_project_from_typo3(self, cr, uid, project_code):
        res = json.loads(
            Sync_typo3.request_to_typo3(
                "select * "
                "from tx_drechildpoolmanagement_domain_model_projects "
                "where project_key='%s'" % project_code, 'sel'))
        if res:
            return res[0]['uid']

        return False
    def depart(self, cr, uid, ids, args, context):
        """ add child remove from typo3 (formerly child_depart_wizard.py) """
        child = self.browse(args.get("object_id"))
        res = True
        if child.state == "I":
            res = child.child_remove_from_typo3()

        res = super(compassion_child, self).depart(cr, uid, ids, args, context) and res

        return res or Sync_typo3.typo3_index_error(cr, uid, self, context)
예제 #9
0
    def depart(self, cr, uid, ids, args, context):
        """ add child remove from typo3 (formerly child_depart_wizard.py) """
        child = self.browse(cr, uid, args.get('object_id'), context)
        res = True
        if child.state == 'I':
            res = child.child_remove_from_typo3()

        res = super(compassion_child, self).depart(
            cr, uid, ids, args, context) and res

        return res or Sync_typo3.typo3_index_error(cr, uid, self, context)
예제 #10
0
    def child_remove_from_typo3(self, cr, uid, ids, context=None):
        child_codes = list()

        for child in self.browse(cr, uid, ids, context):
            try:
                child_uid = self._get_typo3_child_id(cr, uid, child.local_id)
                Sync_typo3.request_to_typo3(
                    "delete from tx_drechildpoolmanagement_childpools_"
                    "children_mm where uid_foreign={0};"
                    "delete from tx_drechildpoolmanagement_domain_model_"
                    "children where child_key='{1}';".format(
                        child_uid, child.local_id), 'upd')
            except orm.except_orm:
                logger.error("Child %s is not on internet" % child.local_id)
            state = 'R' if child.has_been_sponsored else 'N'
            child.write({'state': state})
            child_codes.append(child.local_id)

        Sync_typo3.delete_child_photos(child_codes)
        return Sync_typo3.sync_typo3_index()
    def project_add_to_typo3(self, cr, uid, ids, context=None):
        # Solve the encoding problems on child's descriptions
        reload(sys)
        sys.setdefaultencoding('UTF8')

        today_ts = calendar.timegm(datetime.today().utctimetuple())

        # Returns the german projects (parents) ids on typo3
        res = list()

        for project in self.browse(cr, uid, ids, context):
            project_desc_de = project.description_de.replace('\'', '\'\'')
            project_desc_fr = project.description_fr.replace('\'', '\'\'')
            if not project.country_id:
                project.update_informations()
                project = self.browse(cr, uid, project.id, context)

            # German description (parent)
            Sync_typo3.request_to_typo3(
                "insert into "
                "tx_drechildpoolmanagement_domain_model_projects"
                "(project_key, country, description,"
                "tstamp, crdate, l10n_parent) "
                "values ('{0}','{1}','{2}','{3}','{4}','{5}');".format(
                    project.icp_id, project.country_id.name, project_desc_de,
                    today_ts, today_ts, 0), 'upd')

            parent_id = self.get_project_from_typo3(cr, uid, project.icp_id)
            res.append(parent_id)

            # French description
            Sync_typo3.request_to_typo3(
                "insert into "
                "tx_drechildpoolmanagement_domain_model_projects"
                "(project_key, country, description,"
                "tstamp, crdate, l10n_parent, sys_language_uid) "
                "values ('{0}','{1}','{2}','{3}','{4}','{5}',1);".format(
                    project.icp_id, project.country_id.name, project_desc_fr,
                    today_ts, today_ts, parent_id), 'upd')

            return res
    def _get_typo3_child_id(self, cr, uid, child_code):
        res_query = Sync_typo3.request_to_typo3(
            "select * " "from tx_drechildpoolmanagement_domain_model_children " "where child_key='%s';" % child_code,
            "sel",
        )
        res = 0
        try:
            res = json.loads(res_query)[0]["uid"]
        except:
            raise orm.except_orm(_("Typo3 Error"), _("Child %s not found on typo3") % child_code)

        return res
    def _get_typo3_child_id(self, cr, uid, child_code):
        res_query = Sync_typo3.request_to_typo3(
            "select * "
            "from tx_drechildpoolmanagement_domain_model_children "
            "where child_key='%s';" % child_code, 'sel')
        res = 0
        try:
            res = json.loads(res_query)[0]['uid']
        except:
            raise orm.except_orm(_('Typo3 Error'),
                                 _('Child %s not found on typo3') % child_code)

        return res
예제 #14
0
    def child_add_to_typo3(self, cr, uid, ids, context=None):
        self._set_unsponsored_since(cr, uid, ids, context)

        # Solve the encoding problems on child's descriptions
        reload(sys)
        sys.setdefaultencoding('UTF8')

        for child in self.browse(cr, uid, ids, context):
            project_obj = self.pool.get('compassion.project')
            project = project_obj.get_project_from_typo3(
                cr, uid, child.project_id.icp_id)

            if not project:
                project = project_obj.project_add_to_typo3(
                    cr, uid, [child.project_id.id], context)[0]

            child_gender = 1 if child.gender == 'M' else 2
            child_image = \
                child.local_id + "_f.jpg," + child.local_id + "_h.jpg"

            today_ts = calendar.timegm(
                datetime.today().utctimetuple())
            consign_ts = timedelta(days=200).total_seconds()
            if child.birthdate:
                child_birth_date = calendar.timegm(
                    datetime.strptime(child.birthdate, DF).utctimetuple())
            else:
                child_birth_date = 0
            if child.unsponsored_since:
                child_unsponsored_date = calendar.timegm(
                    datetime.strptime(child.unsponsored_since,
                                      DF).utctimetuple())
            else:
                child_unsponsored_date = today_ts

            # Fix ' in description
            child_desc_de = child.desc_de.replace('\'', '\'\'')
            child_desc_fr = child.desc_fr.replace('\'', '\'\'')

            # German description (parent)
            Sync_typo3.request_to_typo3(
                "insert into "
                "tx_drechildpoolmanagement_domain_model_children"
                "(child_key, child_name_full, child_name_personal,"
                " child_gender, child_biography,"
                " consignment_date, tstamp, crdate, consignment_expiry_date,"
                " l10n_parent,image,child_birth_date,"
                " child_unsponsored_since_date,project) "
                "values ('{0}','{1}','{2}','{3}','{4}','{5}',"
                "        '{6}','{7}','{8}','{9}','{10}','{11}',"
                "        '{12}',{13});".format(
                    child.local_id, child.name, child.firstname,
                    child_gender, child_desc_de,
                    today_ts, today_ts, today_ts, today_ts + consign_ts,
                    0, child_image, child_birth_date, child_unsponsored_date,
                    project), 'upd')

            parent_id = self._get_typo3_child_id(cr, uid, child.local_id)

            # French description
            query = ("insert into "
                     "tx_drechildpoolmanagement_domain_model_children"
                     "(child_key,child_name_full,child_name_personal,"
                     " child_gender,child_biography,consignment_date,tstamp,"
                     " crdate,consignment_expiry_date,l10n_parent,image,"
                     " child_birth_date,child_unsponsored_since_date,"
                     " project,sys_language_uid) "
                     "values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}',"
                     "'{7}','{8}','{9}','{10}',"
                     "'{11}','{12}',{13},1);").format(
                child.local_id, child.name, child.firstname,
                child_gender, child_desc_fr,
                today_ts, today_ts, today_ts, today_ts + consign_ts,
                parent_id, child_image, child_birth_date,
                child_unsponsored_date, project)

            # Assign child to childpool
            max_sorting = int(json.loads(Sync_typo3.request_to_typo3(
                "select max(sorting) as max from "
                "tx_drechildpoolmanagement_childpools_children_mm",
                'sel'))[0]['max'])
            query += "insert into " \
                     "tx_drechildpoolmanagement_childpools_children_mm" \
                     "(uid_foreign,sorting) " \
                     "values ({0},{1})".format(parent_id, max_sorting)

            Sync_typo3.request_to_typo3(query, 'upd')

        self._add_child_pictures_to_typo3(cr, uid, ids, context)
        self.write(cr, uid, ids, {'state': 'I'})
        return Sync_typo3.sync_typo3_index()
 def deallocate(self, cr, uid, ids, args, context=None):
     """ Remove from typo3 when child is deallocated """
     res = self.child_remove_from_typo3(cr, uid, args.get('object_id'),
                                        context)
     super(compassion_child, self).deallocate(cr, uid, ids, args, context)
     return res or Sync_typo3.typo3_index_error(cr, uid, self, context)