fixed crud list

fixed payments
upload -a
This commit is contained in:
2025-07-23 11:08:25 +03:00
parent a4a91e0053
commit 4603953458
53 changed files with 1512 additions and 1078 deletions
+20
View File
@@ -0,0 +1,20 @@
from django import template
from django.template.defaultfilters import date
from common.utils.utils import check_container_number_validity
register = template.Library()
@register.filter
def bg_date(value):
if value:
return date(value, "y.m.d h:m")
return ""
@register.simple_tag
def container_validity_class(container_number):
if not check_container_number_validity(container_number):
return 'invalid-container'
return ''
+40
View File
@@ -0,0 +1,40 @@
import os
import uuid
from datetime import datetime
from django.conf import settings
from rest_framework import status
from rest_framework.response import Response
import owncloud
from owncloud import (HTTPResponseError)
class Owncloud:
@staticmethod
def upload_damage_photo(filename, depot_id):
_, ext = os.path.splitext(filename)
oc = owncloud.Client(settings.OWNCLOUD_URL)
oc.login(settings.OWNCLOUD_USER, settings.OWNCLOUD_PASSWORD)
path = f"{settings.OWNCLOUD_DAMAGES_FOLDER}{str(depot_id)}"
try:
oc.file_info(path)
except HTTPResponseError:
_ = oc.mkdir(path)
owncloud_filename = f"{datetime.today().strftime('%Y%m%d')}_{uuid.uuid4()}{ext}"
owncloud_fullpath = path + "/" + owncloud_filename
oc.put_file(owncloud_fullpath, filename)
file_info = oc.share_file_with_link(owncloud_fullpath)
return file_info.get_link()
@staticmethod
def get_damages(depot_id):
oc = owncloud.Client(settings.OWNCLOUD_URL)
oc.login(settings.OWNCLOUD_USER, settings.OWNCLOUD_PASSWORD)
files = oc.list(f"{settings.OWNCLOUD_DAMAGES_FOLDER}{str(depot_id)}")
damages = []
for file_info in files:
if file_info.is_dir():
continue # Пропускаме поддиректории
# Създаване на публичен линк за всеки файл
link_info = oc.share_file_with_link(file_info.path)
damages.append(link_info.get_link())
return Response(damages, status=status.HTTP_200_OK)
+47 -1
View File
@@ -1,5 +1,12 @@
import re
from django.template.loader import render_to_string
from django.utils.html import strip_tags
from containers.models import Container
from preinfo.models import Preinfo
from django.conf import settings
from django.core.mail import send_mail, EmailMessage
def filter_queryset_by_user(queryset, user):
@@ -40,4 +47,43 @@ def get_container_by_number(number):
try:
return Container.objects.get(number=number, expedited=False)
except Container.DoesNotExist:
return None
return None
CALC_STRING = "0123456789A.BCDEFGHIJK.LMNOPQRSTU.VWXYZ"
def check_container_number_validity(container_number):
if not re.search(r"[A-Z]{4}[0-9]{7}", container_number):
return False
subtotal = 0
delta = 1
for i in range(0, 10):
subtotal = subtotal + CALC_STRING.find(container_number[i]) * delta
delta = delta * 2
subtotal = (subtotal % 11) % 10
if not subtotal == CALC_STRING.find(container_number[10]):
return False
return True
ADMIN_USER_EMAIL= settings.ADMIN_USER_EMAIL
EMAIL_HOST_USER = settings.EMAIL_HOST_USER
def send_test_email(user_email, urls):
subject='Welcome to Our Platform'
html_message = render_to_string('email.html', {
'site_name': 'Our Platform',
'user_email': user_email,
'link1': urls['pay_epay'],
'link2': urls['pay_credit_card'],
})
plain_message = strip_tags(html_message)
email = EmailMessage(
subject=subject,
body=html_message,
from_email=EMAIL_HOST_USER,
to=[user_email],
)
email.content_subtype = 'html' # This tells Django to send HTML email
email.send()
+8 -5
View File
@@ -1,14 +1,17 @@
from django.shortcuts import render
from django.views.generic import TemplateView
from containers.models import Container
class BarrierDashboardView(TemplateView):
template_name = 'barrier/barrier-dashboard.html'
extra_context = {
'title': 'Client Dashboard',
'description': 'This is the client dashboard page.',
}
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
recent_containers = Container.objects.select_related('line', 'booking').order_by('-expedited_on', '-received_on')[:10]
context['recent_containers'] = recent_containers
return context
def get(self, request, *args, **kwargs):
return render(request, self.template_name, self.extra_context)
return render(request, self.template_name, self.get_context_data())