コード例 #1
0
ファイル: models.py プロジェクト: xenisys/pydici
 def url(self, name):
     try:
         bill_id = get_bill_id_from_path(name)
         if self.nature == "client":
             return reverse("billing:bill_file", kwargs={"bill_id": bill_id, "nature": "client"})
         else:
             return reverse("billing:bill_file", kwargs={"bill_id": bill_id, "nature": "supplier"})
     except Exception:
         # Don't display URL if Bill does not exist or path is invalid
         return ""
コード例 #2
0
ファイル: models.py プロジェクト: xenisys/pydici
 def save(self, *args, **kwargs):
     super(AbstractBill, self).save(*args, **kwargs)  # Save it
     if self.bill_file:
         bill_id = get_bill_id_from_path(self.bill_file.name)
         if bill_id == "None":
             # Bill file was saved prior ID generation. Let's move it to proper directory name
             old_file_path = self.bill_file.path
             self.bill_file.name = bill_file_path(self, os.path.basename(self.bill_file.name))  # Define new name
             os.makedirs(os.path.dirname(self.bill_file.path), exist_ok=True) # Create dir if needed (it should)
             os.rename(old_file_path, self.bill_file.path)  # Move file
             super(AbstractBill, self).save(*args, **kwargs)  # Save it again with new path