Skip to content

Commit c5d2d3e

Browse files
committed
changed login page
1 parent 4109d86 commit c5d2d3e

File tree

3 files changed

+30
-36
lines changed

3 files changed

+30
-36
lines changed

panel/panel/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from django.conf.urls.static import static
55

66
urlpatterns = [
7-
path("admin/", admin.site.urls),
8-
path("", include("post_manager.urls")),
7+
path("", admin.site.urls),
8+
path("postmanager/", include("post_manager.urls")),
99
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
1010
# Serve media files when DEBUG is True
1111
if settings.DEBUG:

panel/post_manager/admin.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33
from .models import Post
44
from .views import send_to_telegram # Import the send_to_telegram function
55
import json
6-
from panel.settings import LOGGING
76
import os
87
from pathlib import Path
98
import logging
109

11-
# Get an instance of the logger
12-
logger = logging.getLogger(__name__)
13-
1410
BASE_DIR = Path(__file__).resolve().parent.parent
1511

1612
# Use a relative path for the config.json file
@@ -31,7 +27,7 @@
3127
TOPIC_CHOICES = [(k, k) for k in TOPICS.keys()] # Use topic names for choices
3228

3329
# Debugging: Print loaded topics to console
34-
logger.info("Loaded TOPICS from config.json:", TOPICS)
30+
print("Loaded TOPICS from config.json:", TOPICS)
3531

3632

3733
@admin.action(description="Mark selected posts as pinned")
@@ -63,7 +59,7 @@ def send_posts_to_telegram(modeladmin, request, queryset):
6359
) # Get message_thread_id
6460

6561
# Debugging: Print the values that are being sent to Telegram
66-
logger.info(
62+
print(
6763
f"Sending to chat_id: {chat_id}, message_thread_id: {message_thread_id}"
6864
)
6965

@@ -76,7 +72,7 @@ def send_posts_to_telegram(modeladmin, request, queryset):
7672
message_thread_id=message_thread_id,
7773
)
7874
else:
79-
logger.error(f"Error: Topic not found for post: {post.content}")
75+
print(f"Error: Topic not found for post: {post.content}")
8076

8177
modeladmin.message_user(
8278
request, "Selected posts were sent to Telegram successfully!"
@@ -136,7 +132,7 @@ def save_model(self, request, obj, form, change):
136132
message_thread_id = topic_info.get("message_thread_id")
137133

138134
# Debugging: Print to confirm which topic is selected
139-
logger.info(
135+
print(
140136
f"Sending to chat_id: {chat_id}, message_thread_id: {message_thread_id}"
141137
)
142138

panel/post_manager/views.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import requests
1010
import os
1111
import sqlite3
12-
import logging
1312

1413
# Build paths inside the project like this: BASE_DIR / 'subdir'.
1514
BASE_DIR = Path(__file__).resolve().parent.parent
@@ -23,9 +22,6 @@
2322

2423
DATABASE_FILE = os.path.join(DATABASE_DIR, "group_data.db")
2524

26-
# Get an instance of the logger
27-
logger = logging.getLogger(__name__)
28-
2925

3026
# Load group chat ID from the database
3127
def load_group_chat_id():
@@ -104,9 +100,9 @@ def edit_post(request, post_id):
104100
f"Neuer Post: {post.content}"
105101
)
106102

107-
# Debugging: logger.info available threads
108-
logger.info("Available THREADS in TOPICS:", TOPICS) # Debugging
109-
logger.info("Post Topic ID:", post.topic_id) # Debugging
103+
# Debugging: print available threads
104+
print("Available THREADS in TOPICS:", TOPICS) # Debugging
105+
print("Post Topic ID:", post.topic_id) # Debugging
110106

111107
# Retrieve the thread information by matching the topic_id
112108
thread_info = next(
@@ -130,7 +126,7 @@ def edit_post(request, post_id):
130126
image_path=image_path,
131127
)
132128
else:
133-
logger.info("Thread information not found in TOPICS based on topic_id.")
129+
print("Thread information not found in TOPICS based on topic_id.")
134130

135131
messages.success(request, "Post updated and sent to Telegram!")
136132
return redirect("index")
@@ -148,6 +144,10 @@ def delete_post(request, post_id):
148144
post = get_object_or_404(Post, id=post_id)
149145
post.delete() # Delete the post from the database
150146
messages.success(request, "Post deleted successfully!")
147+
148+
# Log successful deletion
149+
print(f"Post with ID {post_id} has been deleted.")
150+
151151
return redirect(
152152
"index"
153153
) # Redirect back to the post listing or wherever appropriate
@@ -165,12 +165,10 @@ def create_post(request):
165165
) # Check for 'True' to confirm pin status
166166

167167
# Debugging statement
168-
logger.info("Create Post - Content:", content)
169-
logger.info("Create Post - Image:", image)
170-
logger.info(
171-
"Create Post - Pinned Status:", pinned
172-
) # Debugging the pinned status
173-
logger.info("Create Post - Selected Thread:", selected_thread)
168+
print("Create Post - Content:", content)
169+
print("Create Post - Image:", image)
170+
print("Create Post - Pinned Status:", pinned) # Debugging the pinned status
171+
print("Create Post - Selected Thread:", selected_thread)
174172

175173
# Get the thread information from the configuration
176174
thread_info = TOPICS.get(selected_thread)
@@ -228,7 +226,7 @@ def send_to_telegram(
228226

229227
if response_photo.status_code == 200:
230228
message_id = result_photo["result"]["message_id"]
231-
logger.info("Photo sent successfully, message ID:", message_id)
229+
print("Photo sent successfully, message ID:", message_id)
232230

233231
# Pin the message only if pinned is True
234232
if pinned:
@@ -242,23 +240,23 @@ def send_to_telegram(
242240
pin_result = pin_response.json()
243241

244242
# Debugging output for pinning response
245-
logger.info(
243+
print(
246244
f"Attempting to pin message ID {message_id} in chat {chat_id}."
247245
)
248-
logger.info("Pin Data:", data_pin)
249-
logger.info(
246+
print("Pin Data:", data_pin)
247+
print(
250248
"Pin Response:", pin_result
251249
) # Log the pinning response # Log the pinning response
252250

253251
if pin_response.status_code != 200:
254-
logger.info(
252+
print(
255253
f"Error pinning message (status code {pin_response.status_code}):",
256254
pin_result,
257255
)
258256
else:
259-
logger.info("Message pinned successfully.")
257+
print("Message pinned successfully.")
260258
else:
261-
logger.info("Error sending photo:", result_photo)
259+
print("Error sending photo:", result_photo)
262260

263261
else:
264262
# Send the message
@@ -274,7 +272,7 @@ def send_to_telegram(
274272

275273
if response_send.status_code == 200:
276274
message_id = result_send["result"]["message_id"]
277-
logger.info("Message sent successfully, message ID:", message_id)
275+
print("Message sent successfully, message ID:", message_id)
278276

279277
# Pin the message only if pinned is True
280278
if pinned:
@@ -290,16 +288,16 @@ def send_to_telegram(
290288
pin_result = pin_response.json()
291289

292290
# Debugging output for pinning response
293-
logger.info("Pin Response:", pin_result) # Log the pinning response
291+
print("Pin Response:", pin_result) # Log the pinning response
294292

295293
if pin_response.status_code != 200:
296-
logger.info(
294+
print(
297295
f"Error pinning message (status code {pin_response.status_code}):",
298296
pin_result,
299297
)
300298
else:
301-
logger.info("Message pinned successfully.")
299+
print("Message pinned successfully.")
302300
else:
303-
logger.info(
301+
print(
304302
"Error sending message:", result_send
305303
) # Print error if sending message failed

0 commit comments

Comments
 (0)