fixed crud list
fixed payments upload -a
This commit is contained in:
@@ -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
@@ -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()
|
||||
Reference in New Issue
Block a user