예제 #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