Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
MBetterc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mbetter
MBetterc
Commits
3b50b307
Commit
3b50b307
authored
Dec 23, 2025
by
Stefy Lanza (nextime / spora )
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New routeNes
parent
d0d28ab3
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
566 additions
and
429 deletions
+566
-429
barcode_utils.py
mbetterclient/utils/barcode_utils.py
+20
-21
routes.py
mbetterclient/web_dashboard/routes.py
+3
-8
admin_bet_details.html
.../web_dashboard/templates/dashboard/admin_bet_details.html
+136
-96
admin_bets.html
...rclient/web_dashboard/templates/dashboard/admin_bets.html
+129
-100
bet_details.html
...client/web_dashboard/templates/dashboard/bet_details.html
+149
-104
bets.html
mbetterclient/web_dashboard/templates/dashboard/bets.html
+129
-100
No files found.
mbetterclient/utils/barcode_utils.py
View file @
3b50b307
...
@@ -92,19 +92,19 @@ def validate_barcode_data(data: str, standard: str) -> bool:
...
@@ -92,19 +92,19 @@ def validate_barcode_data(data: str, standard: str) -> bool:
def
generate_barcode_image
(
data
:
str
,
standard
:
str
,
width
:
int
=
300
,
height
:
int
=
100
)
->
Optional
[
bytes
]:
def
generate_barcode_image
(
data
:
str
,
standard
:
str
,
width
:
int
=
300
,
height
:
int
=
100
)
->
Optional
[
bytes
]:
"""
"""
Generate barcode image as PNG bytes
Generate barcode image as PNG bytes
Args:
Args:
data: Data to encode in barcode
data: Data to encode in barcode
standard: Barcode standard (code128, code39, ean13, etc.)
standard: Barcode standard (code128, code39, ean13, etc.)
width: Image width in pixels
width: Image width in pixels
height: Image height in pixels
height: Image height in pixels
Returns:
Returns:
PNG image bytes or None if generation failed
PNG image bytes or None if generation failed
"""
"""
if
standard
==
'none'
:
if
standard
==
'none'
:
return
None
return
None
try
:
try
:
# Special case for UPC-E which is not supported by python-barcode library
# Special case for UPC-E which is not supported by python-barcode library
if
standard
==
'upce'
:
if
standard
==
'upce'
:
...
@@ -146,7 +146,7 @@ def generate_barcode_image(data: str, standard: str, width: int = 300, height: i
...
@@ -146,7 +146,7 @@ def generate_barcode_image(data: str, standard: str, width: int = 300, height: i
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
error
(
f
"Failed to get barcode class for {barcode_type}: {e}"
)
logger
.
error
(
f
"Failed to get barcode class for {barcode_type}: {e}"
)
return
None
return
None
# Create image writer with custom options
# Create image writer with custom options
writer
=
ImageWriter
()
writer
=
ImageWriter
()
writer
.
set_options
({
writer
.
set_options
({
...
@@ -159,21 +159,24 @@ def generate_barcode_image(data: str, standard: str, width: int = 300, height: i
...
@@ -159,21 +159,24 @@ def generate_barcode_image(data: str, standard: str, width: int = 300, height: i
'write_text'
:
True
,
'write_text'
:
True
,
'text'
:
data
'text'
:
data
})
})
#
Gener
ate barcode
#
Cre
ate barcode
barcode_instance
=
barcode_class
(
data
,
writer
=
writer
)
barcode_instance
=
barcode_class
(
data
,
writer
=
writer
)
# Render to bytes
# Get PIL Image using render() method
pil_image
=
barcode_instance
.
render
()
# Save to bytes
buffer
=
BytesIO
()
buffer
=
BytesIO
()
barcode_instance
.
write
(
buffer
)
pil_image
.
save
(
buffer
,
format
=
'PNG'
)
buffer
.
seek
(
0
)
buffer
.
seek
(
0
)
image_bytes
=
buffer
.
getvalue
()
image_bytes
=
buffer
.
getvalue
()
buffer
.
close
()
buffer
.
close
()
logger
.
debug
(
f
"Generated {standard} barcode for data: {data}"
)
logger
.
debug
(
f
"Generated {standard} barcode for data: {data}"
)
return
image_bytes
return
image_bytes
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
error
(
f
"Failed to generate barcode: {e}"
)
logger
.
error
(
f
"Failed to generate barcode: {e}"
)
return
None
return
None
...
@@ -216,16 +219,12 @@ def calculate_ean13_check_digit(data: str) -> str:
...
@@ -216,16 +219,12 @@ def calculate_ean13_check_digit(data: str) -> str:
raise
ValueError
(
"EAN-13 check digit calculation requires exactly 12 digits"
)
raise
ValueError
(
"EAN-13 check digit calculation requires exactly 12 digits"
)
# EAN-13 check digit calculation
# EAN-13 check digit calculation
# Step 1: Sum digits in odd positions (1st, 3rd, 5th, etc.) multiplied by 3
# Weights alternate starting with 1 for leftmost digit, 3 for next, etc.
odd_sum
=
sum
(
int
(
data
[
i
])
for
i
in
range
(
0
,
12
,
2
))
*
3
# This ensures the rightmost data digit gets weight 3
weights
=
[
1
,
3
,
1
,
3
,
1
,
3
,
1
,
3
,
1
,
3
,
1
,
3
]
# Step 2: Sum digits in even positions (2nd, 4th, 6th, etc.)
total
=
sum
(
int
(
data
[
i
])
*
weights
[
i
]
for
i
in
range
(
12
))
even_sum
=
sum
(
int
(
data
[
i
])
for
i
in
range
(
1
,
12
,
2
))
# Step 3: Total sum
total
=
odd_sum
+
even_sum
#
Step 4:
Find the smallest number that makes total divisible by 10
# Find the smallest number that makes total divisible by 10
check_digit
=
(
10
-
(
total
%
10
))
%
10
check_digit
=
(
10
-
(
total
%
10
))
%
10
return
data
+
str
(
check_digit
)
return
data
+
str
(
check_digit
)
...
...
mbetterclient/web_dashboard/routes.py
View file @
3b50b307
...
@@ -5484,16 +5484,11 @@ def generate_bet_barcode(bet_id):
...
@@ -5484,16 +5484,11 @@ def generate_bet_barcode(bet_id):
logger
.
debug
(
f
"Using generated barcode data for bet {bet_uuid}: {barcode_data}"
)
logger
.
debug
(
f
"Using generated barcode data for bet {bet_uuid}: {barcode_data}"
)
# Generate barcode image
# Generate barcode image
barcode_image
=
generate_barcode_image
(
barcode_data
,
standard
,
width
,
height
)
barcode_image_bytes
=
generate_barcode_image
(
barcode_data
,
standard
,
width
,
height
)
if
barcode_image
:
# Convert PIL image to bytes
img_buffer
=
io
.
BytesIO
()
barcode_image
.
save
(
img_buffer
,
format
=
'PNG'
)
img_buffer
.
seek
(
0
)
if
barcode_image_bytes
:
return
Response
(
return
Response
(
img_buffer
.
getvalue
()
,
barcode_image_bytes
,
mimetype
=
'image/png'
,
mimetype
=
'image/png'
,
headers
=
{
'Cache-Control'
:
'public, max-age=3600'
}
# Cache for 1 hour
headers
=
{
'Cache-Control'
:
'public, max-age=3600'
}
# Cache for 1 hour
)
)
...
...
mbetterclient/web_dashboard/templates/dashboard/admin_bet_details.html
View file @
3b50b307
This diff is collapsed.
Click to expand it.
mbetterclient/web_dashboard/templates/dashboard/admin_bets.html
View file @
3b50b307
This diff is collapsed.
Click to expand it.
mbetterclient/web_dashboard/templates/dashboard/bet_details.html
View file @
3b50b307
This diff is collapsed.
Click to expand it.
mbetterclient/web_dashboard/templates/dashboard/bets.html
View file @
3b50b307
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment