Browse Source

исправил баг по отображению картинок в админке #5

Anton 1 year ago
parent
commit
0a3086df05
  1. 36
      adminpanelapp/models.py

36
adminpanelapp/models.py

@ -1,3 +1,4 @@
import time
from urllib.parse import quote from urllib.parse import quote
import requests import requests
@ -37,12 +38,13 @@ class Orders(models.Model):
<body> <body>
<img src="{photo_url}" width="{width}" height="{height}" class="small-photo"> <img src="{photo_url}" width="{width}" height="{height}" class="small-photo">
<img src="{photo_url}" width="{large_width}" height="{large_height}" class="large-photo"> <img src="{photo_url}" width="{large_width}" height="{large_height}" class="large-photo">
<a href="#" onclick="togglePhoto()" id="toggle-button" class="button">Увеличить фото</a> <a href="#" onclick="togglePhoto(event)" class="button">Увеличить фото</a>
<script> <script>
function togglePhoto() {{ function togglePhoto(event) {{
var smallPhoto = document.getElementsByClassName("small-photo")[0]; var toggleButton = event.target;
var largePhoto = document.getElementsByClassName("large-photo")[0]; var container = toggleButton.parentNode;
var toggleButton = document.getElementById("toggle-button"); var smallPhoto = container.querySelector(".small-photo");
var largePhoto = container.querySelector(".large-photo");
if (smallPhoto.style.display === "none") {{ if (smallPhoto.style.display === "none") {{
smallPhoto.style.display = "block"; smallPhoto.style.display = "block";
@ -86,6 +88,7 @@ class Orders(models.Model):
response = requests.get(url) response = requests.get(url)
data = response.json() data = response.json()
if data['ok']: if data['ok']:
file_path = data["result"]["file_path"] file_path = data["result"]["file_path"]
photo_url = f"https://api.telegram.org/file/bot{token}/{quote(file_path, safe='')}" photo_url = f"https://api.telegram.org/file/bot{token}/{quote(file_path, safe='')}"
@ -95,20 +98,21 @@ class Orders(models.Model):
<body> <body>
<img src="{photo_url}" width="{width}" height="{height}" class="small-photo"> <img src="{photo_url}" width="{width}" height="{height}" class="small-photo">
<img src="{photo_url}" width="{large_width}" height="{large_height}" class="large-photo"> <img src="{photo_url}" width="{large_width}" height="{large_height}" class="large-photo">
<a href="#" onclick="togglePhotoPay()" id="toggle-button" class="button">Увеличить фото</a> <a href="#" onclick="togglePhoto(event)" class="button">Увеличить фото</a>
<script> <script>
function togglePhotoPay() {{ function togglePhoto(event) {{
var smallPhotoPay = document.getElementsByClassName("small-photo")[1]; var toggleButton = event.target;
var largePhotoPay = document.getElementsByClassName("large-photo")[1]; var container = toggleButton.parentNode;
var toggleButton = document.getElementById("toggle-button"); var smallPhoto = container.querySelector(".small-photo");
var largePhoto = container.querySelector(".large-photo");
if (smallPhotoPay.style.display === "none") {{
smallPhotoPay.style.display = "block"; if (smallPhoto.style.display === "none") {{
largePhotoPay.style.display = "none"; smallPhoto.style.display = "block";
largePhoto.style.display = "none";
toggleButton.innerHTML = "Увеличить фото"; toggleButton.innerHTML = "Увеличить фото";
}} else {{ }} else {{
smallPhotoPay.style.display = "none"; smallPhoto.style.display = "none";
largePhotoPay.style.display = "block"; largePhoto.style.display = "block";
toggleButton.innerHTML = "Уменьшить фото"; toggleButton.innerHTML = "Уменьшить фото";
}} }}
}} }}

Loading…
Cancel
Save