Skip to content

Commit

Permalink
fix(barcode): correct default barcode colors and improve test image g…
Browse files Browse the repository at this point in the history
…eneration

- Fixed default color values for barcode generation to ensure visibility.
- Updated tests to handle image generation issues.
- Refactored model styles for consistency and clarity.
  • Loading branch information
MohmdFo committed Sep 7, 2024
1 parent 06bb522 commit 7d8be1d
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 71 deletions.
14 changes: 10 additions & 4 deletions sage_qrcode/models/barcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Barcode(PolymorphicModel, TimeStampMixin):
"""Abstract base class for all QR code types."""

bar_code_image = models.ImageField(
verbose_name=_("Bar Code Image"),
upload_to="bar_codes/",
blank=True,
null=True,
Expand All @@ -20,6 +21,7 @@ class Barcode(PolymorphicModel, TimeStampMixin):
)

title = models.CharField(
verbose_name=_("Title"),
max_length=255,
null=True,
blank=True,
Expand All @@ -28,17 +30,21 @@ class Barcode(PolymorphicModel, TimeStampMixin):
)

color = ColorField(
verbose_name=_("Color"),
format="hex",
help_text=_("Color of the BAR code."),
default="#000000",
null=True,
blank=True,
help_text=_("Color of the BAR code."),
db_comment="The color of the BAR code in hexadecimal format.",
)
second_color = ColorField(
verbose_name=_("Second Color"),
format="hex",
help_text=_("Second color of the QR code."),
default="##FFFFFF",
null=True,
blank=True,
help_text=_("Second color of the QR code."),
db_comment="The second color of the BAR code in hexadecimal format.",
)

Expand All @@ -63,9 +69,9 @@ class BarcodeUrl(Barcode):
"""

url = models.URLField(
verbose_name=_("barcode URL"),
help_text=_("URL of the barcode content."),
db_comment="The URL of the barcode content.",
verbose_name=_("barcode URL"),
)

def __str__(self):
Expand All @@ -90,10 +96,10 @@ class BarcodeText(Barcode):
"""

body = models.TextField(
verbose_name=_("body"),
blank=True,
help_text=_("Body of the barcode."),
db_comment="The body of the barcode.",
verbose_name=_("body"),
)

def __str__(self):
Expand Down
8 changes: 4 additions & 4 deletions sage_qrcode/models/bitcoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,34 @@ class BitcoinQRCode(QRCode):
"""

bitcoin_address = models.CharField(
verbose_name=_("Bitcoin Address"),
max_length=34,
validators=[validate_bitcoin_address],
help_text=_("Bitcoin address. Example: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'"),
db_comment="The Bitcoin address for the payment.",
verbose_name=_("Bitcoin Address"),
)
amount = models.DecimalField(
verbose_name=_("Amount"),
max_digits=10,
decimal_places=8,
null=False,
blank=False,
validators=[MinValueValidator(0.00000001)],
help_text=_("Amount of Bitcoin to send. Example: '0.01'"),
db_comment="The amount of Bitcoin to send.",
verbose_name=_("Amount"),
)
label = models.CharField(
verbose_name=_("Label"),
max_length=255,
blank=True,
help_text=_("Label for the transaction."),
db_comment="An optional label for the transaction.",
verbose_name=_("Label"),
)
message = models.TextField(
verbose_name=_("Message"),
blank=True,
help_text=_("Message for the transaction."),
db_comment="An optional message for the transaction.",
verbose_name=_("Message"),
)

def __str__(self):
Expand Down
14 changes: 7 additions & 7 deletions sage_qrcode/models/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,56 @@ class VCardQRCode(QRCode):
"""

full_name = models.CharField(
verbose_name=_("Full Name"),
max_length=255,
help_text=_("Full name of the individual."),
db_comment="The name of the individual represented in the VCard QR code.",
verbose_name=_("Full Name"),
)
display_name = models.CharField(
verbose_name=_("Display Name"),
max_length=255,
null=True,
blank=True,
help_text=_("Display name of the individual."),
db_comment="An optional display name for the individual.",
verbose_name=_("Display Name"),
)
email = models.EmailField(
verbose_name=_("Email"),
null=True,
blank=True,
help_text=_("Email address of the individual."),
db_comment="The email address of the individual.",
verbose_name=_("Email"),
)
phone = models.CharField(
verbose_name=_("Phone Number"),
max_length=20,
null=True,
blank=True,
validators=[validate_phone_number],
help_text=_("Phone number of the individual."),
db_comment="The phone number of the individual.",
verbose_name=_("Phone Number"),
)
url = models.URLField(
verbose_name=_("Website URL"),
null=True,
blank=True,
help_text=_("URL of the individual's website or profile."),
db_comment="The URL to the individual's website or profile.",
verbose_name=_("Website URL"),
)
org = models.CharField(
verbose_name=_("Organization"),
max_length=255,
null=True,
blank=True,
help_text=_("Name of the organization."),
db_comment="The organization name associated with the individual.",
verbose_name=_("Organization"),
)
address = models.TextField(
verbose_name=_("Address"),
null=True,
blank=True,
help_text=_("Physical address of the individual."),
db_comment="The physical address of the individual.",
verbose_name=_("Address"),
)
phone_number = models.CharField(
_("Phone Number"),
Expand Down
8 changes: 4 additions & 4 deletions sage_qrcode/models/epc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ class EPCQRCode(QRCode):
"""

name = models.CharField(
verbose_name=_("Beneficiary Name"),
max_length=255,
help_text=_("Name of the EPC beneficiary."),
db_comment="The name of the beneficiary for the EPC QR code.",
verbose_name=_("Beneficiary Name"),
)
iban = models.CharField(
verbose_name=_("IBAN"),
max_length=34,
validators=[validate_iban],
help_text=_("IBAN of the EPC beneficiary."),
db_comment="The IBAN of the beneficiary for the EPC QR code.",
verbose_name=_("IBAN"),
)
amount = models.DecimalField(
verbose_name=_("Payment Amount"),
max_digits=10,
decimal_places=2,
validators=[MinValueValidator(0.01)],
help_text=_("Payment amount."),
db_comment="The amount to be paid using the EPC QR code.",
verbose_name=_("Payment Amount"),
)
text = models.TextField(
verbose_name=_("Additional Text"),
blank=True,
help_text=_("Additional text for the EPC QR code."),
db_comment="Optional additional text for the EPC QR code.",
verbose_name=_("Additional Text"),
)

def __str__(self):
Expand Down
15 changes: 11 additions & 4 deletions sage_qrcode/models/qrcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class QRCode(PolymorphicModel, TimeStampMixin):
"""Abstract base class for all QR code types."""

qr_code_image = models.ImageField(
verbose_name=_("QR Code Image"),
upload_to="qr_codes/",
blank=True,
null=True,
Expand All @@ -19,6 +20,7 @@ class QRCode(PolymorphicModel, TimeStampMixin):
db_comment="The image file of the generated QR code.",
)
custom_gif = models.ImageField(
verbose_name=_("Custom GIF"),
upload_to="custom_gifs/",
blank=True,
null=True,
Expand All @@ -27,39 +29,44 @@ class QRCode(PolymorphicModel, TimeStampMixin):
db_comment="An optional custom GIF that can be embedded in the QR code.",
)
title = models.CharField(
verbose_name=_("Title"),
max_length=255,
null=True,
blank=True,
help_text=_("Title of the QR code."),
db_comment="A descriptive title for the QR code.",
)
size = models.PositiveSmallIntegerField(
verbose_name=_("Size"),
validators=[validate_size],
help_text=_("Size of the QR code image."),
null=True,
blank=True,
help_text=_("Size of the QR code image."),
db_comment="The size (dimensions) of the QR code image.",
)
color = ColorField(
verbose_name=_("Color"),
format="hex",
help_text=_("Color of the QR code."),
null=True,
blank=True,
help_text=_("Color of the QR code."),
db_comment="The color of the QR code in hexadecimal format.",
)
second_color = ColorField(
verbose_name=_("Second Color"),
format="hex",
help_text=_("Second color of the QR code."),
null=True,
blank=True,
help_text=_("Second color of the QR code."),
db_comment="The second color of the QR code in hexadecimal format.",
)

third_color = ColorField(
verbose_name=_("Third Color"),
format="hex",
help_text=_("Third color of the QR code."),
null=True,
blank=True,
help_text=_("Third color of the QR code."),
db_comment="The third color of the BAR code in hexadecimal format.",
)

Expand Down
Loading

0 comments on commit 7d8be1d

Please sign in to comment.