@@ -24,10 +24,17 @@ def __init__(self, file_path, main_window):
2424 self .remove_button = QPushButton ("Remove" )
2525 self .remove_button .clicked .connect (self .remove_self )
2626
27- layout = QHBoxLayout ()
28- layout .addWidget (self .file_label )
29- layout .addWidget (self .title_entry )
30- layout .addWidget (self .remove_button )
27+ file_layout = QHBoxLayout ()
28+ file_layout .addWidget (self .file_label )
29+ file_layout .addWidget (self .remove_button )
30+
31+ entry_layout = QHBoxLayout ()
32+ entry_layout .addWidget (QLabel ("Title:" ))
33+ entry_layout .addWidget (self .title_entry )
34+
35+ layout = QVBoxLayout ()
36+ layout .addLayout (file_layout )
37+ layout .addLayout (entry_layout )
3138
3239 self .setLayout (layout )
3340
@@ -43,14 +50,22 @@ def __init__(self):
4350
4451 self .file_entries = []
4552
46- self .setWindowTitle ("File Upload " )
53+ self .setWindowTitle ("Radmash Uploader " )
4754 self .resize (400 , 300 )
4855
4956 central_widget = QWidget (self )
5057 self .setCentralWidget (central_widget )
5158
5259 main_layout = QVBoxLayout (central_widget )
5360
61+ server_url_layout = QHBoxLayout ()
62+ self .server_url_label = QLabel ("Server URL (don't change unless necessary):" )
63+ self .server_url_entry = QLineEdit ()
64+ default_server_url = os .getenv ('SERVER_URL' )
65+ self .server_url_entry .setText (default_server_url )
66+ server_url_layout .addWidget (self .server_url_label )
67+ server_url_layout .addWidget (self .server_url_entry )
68+
5469 self .select_button = QPushButton ("Select Files" )
5570 self .select_button .clicked .connect (self .select_files )
5671
@@ -59,14 +74,15 @@ def __init__(self):
5974 self .submit_button = QPushButton ("Submit" )
6075 self .submit_button .clicked .connect (self .upload_files )
6176
77+ main_layout .addLayout (server_url_layout )
6278 main_layout .addWidget (self .select_button )
6379 main_layout .addLayout (self .files_layout )
6480 main_layout .addWidget (self .submit_button )
6581
6682 def select_files (self ):
6783 file_dialog = QFileDialog ()
6884 file_dialog .setFileMode (QFileDialog .ExistingFiles )
69- file_dialog .setNameFilter ("PDF Files (*.pdf)" )
85+ file_dialog .setNameFilter ("Divrei Torah (*.pdf)" )
7086 if file_dialog .exec_ ():
7187 file_paths = file_dialog .selectedFiles ()
7288 for file_path in file_paths :
@@ -81,20 +97,35 @@ def remove_file_entry(self, file_entry):
8197 self .file_entries .remove (file_entry )
8298
8399 def upload_files (self ):
100+ server_url = self .server_url_entry .text () # Get the server URL from the input field
101+ if not server_url :
102+ QMessageBox .warning (self , "Warning" , "Please enter a server URL" )
103+ return
104+
84105 file_entries_data = []
85106 files = []
107+ empty_fields = False # Flag to track if any input field is empty
108+
86109 for file_entry in self .file_entries :
87110 file_path = file_entry .file_path
88111 file_name = file_path .split ("/" )[- 1 ]
89112 title = file_entry .title_entry .text ()
113+
114+ if not title : # Check if the title field is empty
115+ empty_fields = True
116+ QMessageBox .warning (self , "Warning" , "Please enter a title for all files" )
117+ break
118+
90119 file_entries_data .append ((file_path , file_name , title ))
91120 with open (file_path , 'rb' ) as file :
92121 file_content = file .read ()
93122 files .append (('file' , (file_name , file_content , 'application/pdf' )))
94123
124+ if empty_fields :
125+ return
126+
95127 data = {f'title_{ i + 1 } ' : title for i , (_ , _ , title ) in enumerate (file_entries_data )}
96128
97- server_url = os .getenv ('SERVER_URL' )
98129 response = requests .post (server_url + '/upload' , files = files , data = data )
99130
100131 if response .status_code == 200 :
0 commit comments