Merge pull request #412 from expsa/zainab_trnas5

Update barcode.py
This commit is contained in:
zainab2097 2024-07-29 10:59:53 +03:00 committed by GitHub
commit 0071d56043
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 11 deletions

View File

@ -43,6 +43,13 @@ class Transaction(models.Model):
img = Image.new("RGBA", (500, 420), "white")
draw = ImageDraw.Draw(img)
font = ImageFont.truetype(font_path, font_size)
transaction_text = " رقم المعاملة : " + (self.name or '')
subject_text = " موضوع : " + (self.subject or '')
h_date =" تاريخ المعاملة الهجري : " +(str(self.transaction_date) if self.transaction_date else '')
datem = " تاريخ المعاملة الميلادي : "+ (str(self.transaction_date) if self.transaction_date else '')
rank = " رتبة المعاملة : "+(str(self.attachment_num) if self.attachment_num else '0')
full_text = transaction_text + "\n" + subject_text.center(30)+"\n"+h_date+'\n'+datem+'\n'+rank.center(50)
def draw_text(draw, text, position, font, alignment="left"):
text_size = draw.textsize(text, font=font)
@ -54,17 +61,9 @@ class Transaction(models.Model):
draw.text(position, text, "black", font=font)
# Draw text elements
# draw_text(draw, (self.name or '')+'رقم المعاملة:', (10, 20), font)
# draw_text(draw, (self.transaction_date_hijri or '').replace('-', '/')+"تاريخ المعاملة الهجري: ", (10, 60), font)
# draw_text(draw,(str(self.transaction_date) if self.transaction_date else '').replace('-', '/')+"تاريخ المعاملة الميلادي: ", (10, 100), font)
# draw_text(draw,(str(self.attachment_num) if self.attachment_num else '0')+ "رتبة المعاملة: " , (10, 140), font)
#
draw_text(draw, " رقم المعاملة : " + (self.name or ''), (10, 20), font)
draw_text(draw, " الموضوع : " + (self.subject or ''), (10, 60), font)
draw_text(draw, " تاريخ المعاملة الهجري : " + (self.transaction_date_hijri or '').replace('-', '/'), (10, 80), font)
draw_text(draw, " تاريخ المعاملة الميلادي : " + (str(self.transaction_date) if self.transaction_date else '').replace('-', '/'), (10, 120), font)
draw_text(draw, " رتبة المعاملة : " + (str(self.attachment_num) if self.attachment_num else '0'), (120, 160), font)
draw_text(draw, full_text, (10, 20), font)
# Generate barcode