Skip to content

Commit 4d8202d

Browse files
committed
Initialize or reset proxy each time before request is sent.
Initialize or reset proxy each time before request is sent. Create LambdaService object when button is pressed. Removed redundant code.
1 parent 63a3b36 commit 4d8202d

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

arho_feature_template/core/lambda_service.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@ def __init__(self):
1717
# Init network manager
1818
self.network_manager = QNetworkAccessManager()
1919

20-
# Get settings
20+
def send_request(self, action: str, plan_id: str):
21+
"""Sends a request to the lambda function."""
22+
2123
proxy_host, proxy_port, self.lambda_url = get_settings()
2224

25+
# Initialize or reset proxy each time a request is sent. Incase settings have changed.
2326
if proxy_host and proxy_port:
2427
# Set up SOCKS5 Proxy if values are provided
2528
proxy = QNetworkProxy()
2629
proxy.setType(QNetworkProxy.Socks5Proxy)
2730
proxy.setHostName(proxy_host)
2831
proxy.setPort(int(proxy_port))
2932
self.network_manager.setProxy(proxy)
33+
else:
34+
self.network_manager.setProxy(QNetworkProxy())
3035

31-
def send_request(self, action: str, plan_id: str):
32-
"""Sends a request to the lambda function."""
3336
payload = {"action": action, "plan_uuid": plan_id}
3437
payload_bytes = QByteArray(json.dumps(payload).encode("utf-8"))
3538

@@ -53,7 +56,6 @@ def _process_reply(self, reply: QNetworkReply):
5356

5457
try:
5558
response_data = reply.readAll().data().decode("utf-8")
56-
5759
response_json = json.loads(response_data)
5860

5961
# Determine if the proxy is set up.
@@ -71,7 +73,7 @@ def _process_reply(self, reply: QNetworkReply):
7173
if not isinstance(plan_json, dict):
7274
plan_json = {}
7375

74-
outline_json = None
76+
outline_json = {}
7577
if plan_json:
7678
geographical_area = plan_json.get("geographicalArea")
7779
if geographical_area:
@@ -83,9 +85,6 @@ def _process_reply(self, reply: QNetworkReply):
8385
"geometry": geographical_area.get("geometry"),
8486
}
8587

86-
if outline_json is None:
87-
outline_json = {} # Fallback to empty dictionary if no outline JSON is created
88-
8988
# Emit the signal with the two JSONs
9089
self.jsons_received.emit(plan_json, outline_json)
9190

arho_feature_template/core/plan_manager.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
class PlanManager:
1818
def __init__(self):
19-
self.lambda_service = LambdaService()
20-
self.lambda_service.jsons_received.connect(self.save_plan_jsons)
2119
self.json_plan_path = None
2220
self.json_plan_outline_path = None
2321
self.kaava_layer = get_layer_by_name("Kaava")
@@ -121,6 +119,8 @@ def get_plan_json(self):
121119
QMessageBox.critical(None, "Virhe", "Ei aktiivista kaavaa.")
122120
return
123121

122+
self.lambda_service = LambdaService()
123+
self.lambda_service.jsons_received.connect(self.save_plan_jsons)
124124
self.lambda_service.send_request("get_plans", plan_id)
125125

126126
def save_plan_jsons(self, plan_json, outline_json):

0 commit comments

Comments
 (0)