def cat_unique(self, obj): with open(os.path.join(settings.PROJECT_PATH, 'gsb', 'templates', 'export_plist', 'modele_cat.log'), encoding="utf-8")as template: chaine = template.read() # type d'action (IUD) chaine = chaine.replace("{{action}}", "%s" % self.actions[obj['status']]) # device code chaine = chaine.replace("{{device}}", "%s" % self.code_device) # couleur color_hexa = obj['couleur'][1:] if color_hexa == '' or color_hexa == '': color_hexa = "0" color = int(color_hexa, 16) chaine = chaine.replace("{{color}}", "%s" % color) # last update timestamp chaine = chaine.replace("{{last_update}}", "%s" % int(utils.datetotimestamp(obj['lastupdate']))) # pk chaine = chaine.replace("{{pk}}", "%s" % obj['id']) # place if obj['status'] != "D": place = list(models.Cat.objects.order_by('id').values_list('id', flat=True)).index(obj['id']) else: place = 0 chaine = chaine.replace("{{place}}", "%s" % place) # type cat (rd) if obj['type_obj'] == 'r': type_cat = self.type_revenu else: type_cat = self.type_depense chaine = chaine.replace("{{type_cat}}", "%s" % type_cat) # nom cat chaine = chaine.replace("{{nom_cat}}", "%s" % obj['nom']) filename = filename_for_moneyjournal() messages.success(self.request, "dans fichier %s" % filename) with open(filename, 'w', encoding="utf-8", newline='') as f: f.write(chaine)
def filename_for_moneyjournal(): """cree au besoin les repertoire et renvoit un nom de fichier de la forme """ ref_temp = utils.datetotimestamp(utils.now()) directory = os.path.join(settings.DIR_DROPBOX, 'Applications', 'Money Journal', 'log', str(ref_temp)[:3], str(ref_temp)[3:4], str(ref_temp)[4:5]) name = os.path.join(directory, "%d.log" % (ref_temp * 1000)) if not os.path.exists(directory): os.makedirs(directory) if os.path.isfile(name): time.sleep(1) ref_temp = int(utils.datetotimestamp(utils.now())) directory = os.path.join(settings.DIR_DROPBOX, 'Applications', 'Money Journal', 'log', str(ref_temp)[:3], str(ref_temp)[3:4], str(ref_temp)[4:5]) name = os.path.join(directory, "{0:d}.log".format(ref_temp * 1000)) if not os.path.exists(directory): os.makedirs(directory) return name
def ope_unique(self, obj): with open(os.path.join(settings.PROJECT_PATH, 'gsb', 'templates', 'export_plist', 'modele_ope.log'), encoding='utf-8') as template: chaine = template.read() # type d'action (IUD) chaine = chaine.replace("{{action}}", "%s" % self.actions[obj['status']]) # device code chaine = chaine.replace("{{device}}", "%s" % self.code_device) # pk chaine = chaine.replace("{{pk}}", "%s" % obj['id']) if obj['cat_id'] not in (self.ventile, self.virement): montant = obj['montant'] if obj['montant'] > 0: type_ope = 1 if obj['type_cat'] == 'r': categorie_id = obj['cat_id'] else: categorie_id = self.remboursement else: montant = abs(obj['montant']) type_ope = 2 if obj['type_cat'] == 'd': categorie_id = obj['cat_id'] else: categorie_id = self.avance else: # si virement ou ope ventile type_ope = 2 categorie_id = obj['cat_id'] montant = 0 chaine = chaine.replace("{{amount}}", "%s" % montant) chaine = chaine.replace("{{cat_id}}", "%s" % categorie_id) chaine = chaine.replace("{{type_ope}}", "%s" % type_ope) # date_ope if obj['date'] != 0: chaine = chaine.replace("{{jour}}", "%s" % obj['date'].day) chaine = chaine.replace("{{mois}}", "%s" % obj['date'].month) chaine = chaine.replace("{{annee}}", "%s" % obj['date'].year) else: chaine = chaine.replace("{{jour}}", "%s" % '0') chaine = chaine.replace("{{mois}}", "%s" % '0') chaine = chaine.replace("{{annee}}", "%s" % '0') chaine = chaine.replace("{{tiers}}", "%s" % obj['tiers']) # last update timestamp chaine = chaine.replace( "{{last_update}}", "%s" % int(utils.datetotimestamp(obj['lastupdate']))) # compte chaine = chaine.replace("{{compte_id}}", "%s" % obj['compte_id']) filename = filename_for_moneyjournal() with open(filename, 'w', encoding="utf-8", newline='') as f: f.write(smart_text(chaine))
def ope_unique(self, obj): with open(os.path.join(settings.PROJECT_PATH, 'gsb', 'templates', 'export_plist', 'modele_ope.log'), encoding='utf-8')as template: chaine = template.read() # type d'action (IUD) chaine = chaine.replace("{{action}}", "%s" % self.actions[obj['status']]) # device code chaine = chaine.replace("{{device}}", "%s" % self.code_device) # pk chaine = chaine.replace("{{pk}}", "%s" % obj['id']) if obj['cat_id'] not in (self.ventile, self.virement): montant = obj['montant'] if obj['montant'] > 0: type_ope = 1 if obj['type_cat'] == 'r': categorie_id = obj['cat_id'] else: categorie_id = self.remboursement else: montant = abs(obj['montant']) type_ope = 2 if obj['type_cat'] == 'd': categorie_id = obj['cat_id'] else: categorie_id = self.avance else: # si virement ou ope ventile type_ope = 2 categorie_id = obj['cat_id'] montant = 0 chaine = chaine.replace("{{amount}}", "%s" % montant) chaine = chaine.replace("{{cat_id}}", "%s" % categorie_id) chaine = chaine.replace("{{type_ope}}", "%s" % type_ope) # date_ope if obj['date'] != 0: chaine = chaine.replace("{{jour}}", "%s" % obj['date'].day) chaine = chaine.replace("{{mois}}", "%s" % obj['date'].month) chaine = chaine.replace("{{annee}}", "%s" % obj['date'].year) else: chaine = chaine.replace("{{jour}}", "%s" % '0') chaine = chaine.replace("{{mois}}", "%s" % '0') chaine = chaine.replace("{{annee}}", "%s" % '0') chaine = chaine.replace("{{tiers}}", "%s" % obj['tiers']) # last update timestamp chaine = chaine.replace("{{last_update}}", "%s" % int(utils.datetotimestamp(obj['lastupdate']))) # compte chaine = chaine.replace("{{compte_id}}", "%s" % obj['compte_id']) filename = filename_for_moneyjournal() with open(filename, 'w', encoding="utf-8", newline='') as f: f.write(smart_text(chaine))
def compte_unique(self, obj): with open(os.path.join(settings.PROJECT_PATH, 'gsb', 'templates', 'export_plist', 'modele_compte.log'), encoding="utf-8") as template: chaine = template.read() # type d'action (IUD) chaine = chaine.replace("{{action}}", "%s" % self.actions[obj['status']]) # device code chaine = chaine.replace("{{device}}", "%s" % self.code_device) # couleur color_hexa = obj['couleur'][1:] if color_hexa == '' or color_hexa == '': color_hexa = "0" color = int(color_hexa, 16) chaine = chaine.replace("{{color}}", "%s" % color) # last update timestamp chaine = chaine.replace( "{{last_update}}", "%s" % int(utils.datetotimestamp(obj['lastupdate']))) # pk chaine = chaine.replace("{{pk}}", "%s" % obj['id']) # symbol if obj['status'] != "D": symbol = list( models.Compte.objects.order_by('id').values_list( 'id', flat=True)).index(obj['id']) else: symbol = 0 chaine = chaine.replace("{{symbol}}", "%s" % (symbol % 9)) # place if obj['status'] != "D": place = list( models.Compte.objects.order_by('id').values_list( 'id', flat=True)).index(obj['id']) else: place = 0 chaine = chaine.replace("{{place}}", "%s" % place) # nom compte chaine = chaine.replace("{{nom_compte}}", "%s" % obj['nom']) filename = filename_for_moneyjournal() messages.success(self.request, "dans chaine %s" % filename) with open(filename, 'w', encoding="utf-8", newline='') as f: f.write(chaine)