Rammohan0504 commited on
Commit
45e6457
·
verified ·
1 Parent(s): 505497c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -18
app.py CHANGED
@@ -146,6 +146,7 @@ def upload_file_to_salesforce(file_path, filename, sf_connection, file_type):
146
  except Exception as e:
147
  return None, None, f"Error uploading {filename} to Salesforce: {str(e)}"
148
 
 
149
  # Function to generate the daily progress report (DPR), save as PDF, and upload to Salesforce
150
  def generate_dpr(files):
151
  dpr_text = []
@@ -166,14 +167,12 @@ def generate_dpr(files):
166
 
167
  # Generate DPR section for this image with dynamic caption
168
  dpr_section = f"\nImage: {file.name}\nDescription: {caption}\n"
169
- # Remove the description from the dpr_text section
170
- # No need to add it again as the image and caption will be inserted in the PDF
171
  dpr_text.append(dpr_section)
172
 
173
  # Save image path for embedding in the report
174
  image_paths.append(file.name)
175
 
176
- # Combine DPR text (no redundant description here)
177
  dpr_output = "\n".join(dpr_text)
178
 
179
  # Generate PDF filename with timestamp
@@ -182,7 +181,6 @@ def generate_dpr(files):
182
  # Save DPR text to PDF
183
  pdf_result, pdf_filepath = save_dpr_to_pdf(dpr_output, image_paths, captions, pdf_filename)
184
 
185
- # Salesforce upload
186
  salesforce_result = ""
187
  pdf_content_document_id = None
188
  pdf_url = None
@@ -219,29 +217,23 @@ def generate_dpr(files):
219
  })
220
  salesforce_result += f"Updated PDF URL for record ID {dpr_record_id}\n"
221
 
222
- # Upload images to Salesforce and create Site_Images__c records
223
  for file in files:
224
  image_filename = os.path.basename(file.name)
225
- image_content_document_id, image_upload_result = upload_file_to_salesforce(
226
  file.name, image_filename, sf, "image"
227
  )
 
228
  if image_content_document_id:
229
  image_content_document_ids.append(image_content_document_id)
230
 
231
- # Create Site_Images__c record and link to DPR
232
- site_image_record = sf.Site_Images__c.create({
233
- 'Image__c': image_content_document_id,
234
- 'Related_Report__c': dpr_record_id # Link image to DPR record
235
  })
236
- salesforce_result += image_upload_result + "\n"
237
 
238
- # Link image to DPR record
239
- if image_content_document_id:
240
- sf.ContentDocumentLink.create({
241
- 'ContentDocumentId': image_content_document_id,
242
- 'LinkedEntityId': dpr_record_id,
243
- 'ShareType': 'V'
244
- })
245
 
246
  except Exception as e:
247
  salesforce_result += f"Error interacting with Salesforce: {str(e)}\n"
 
146
  except Exception as e:
147
  return None, None, f"Error uploading {filename} to Salesforce: {str(e)}"
148
 
149
+ # Function to generate the daily progress report (DPR), save as PDF, and upload to Salesforce
150
  # Function to generate the daily progress report (DPR), save as PDF, and upload to Salesforce
151
  def generate_dpr(files):
152
  dpr_text = []
 
167
 
168
  # Generate DPR section for this image with dynamic caption
169
  dpr_section = f"\nImage: {file.name}\nDescription: {caption}\n"
 
 
170
  dpr_text.append(dpr_section)
171
 
172
  # Save image path for embedding in the report
173
  image_paths.append(file.name)
174
 
175
+ # Combine DPR text
176
  dpr_output = "\n".join(dpr_text)
177
 
178
  # Generate PDF filename with timestamp
 
181
  # Save DPR text to PDF
182
  pdf_result, pdf_filepath = save_dpr_to_pdf(dpr_output, image_paths, captions, pdf_filename)
183
 
 
184
  salesforce_result = ""
185
  pdf_content_document_id = None
186
  pdf_url = None
 
217
  })
218
  salesforce_result += f"Updated PDF URL for record ID {dpr_record_id}\n"
219
 
220
+ # Upload images to Salesforce and link them to DPR record
221
  for file in files:
222
  image_filename = os.path.basename(file.name)
223
+ image_content_document_id, image_url, image_upload_result = upload_file_to_salesforce(
224
  file.name, image_filename, sf, "image"
225
  )
226
+
227
  if image_content_document_id:
228
  image_content_document_ids.append(image_content_document_id)
229
 
230
+ # Now, link the image to the DPR record in the correct field (e.g., Site Images)
231
+ # Assuming you have a field like `Site_Images__c` in the DPR record that accepts ContentDocumentId
232
+ sf.Daily_Progress_Reports__c.update(dpr_record_id, {
233
+ 'Site_Images__c': image_content_document_id # Store ContentDocumentId in Site_Images__c field
234
  })
 
235
 
236
+ salesforce_result += image_upload_result + "\n"
 
 
 
 
 
 
237
 
238
  except Exception as e:
239
  salesforce_result += f"Error interacting with Salesforce: {str(e)}\n"