Skip to content

Commit

Permalink
Merge pull request #313 from opengisch/login_improvements
Browse files Browse the repository at this point in the history
Login and project update improvements and fixes
  • Loading branch information
suricactus authored Sep 14, 2021
2 parents 8852d2e + 3ac59c0 commit e937193
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 24 deletions.
26 changes: 25 additions & 1 deletion qfieldsync/core/cloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def update_project(
) -> QNetworkReply:
"""Update an existing QFieldCloud project"""

return self.cloud_put(
return self.cloud_patch(
["projects", project_id],
{
"name": name,
Expand Down Expand Up @@ -453,6 +453,30 @@ def cloud_put(

return reply

def cloud_patch(
self, uri: Union[str, List[str]], payload: Dict = None
) -> QNetworkReply:
url = self._prepare_uri(uri)

self._clear_cloud_cookies(url)

request = QNetworkRequest(url)
request.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True)
request.setHeader(QNetworkRequest.ContentTypeHeader, "application/json")

if self._token:
request.setRawHeader(
b"Authorization", "Token {}".format(self._token).encode("utf-8")
)

payload_bytes = b"" if payload is None else json.dumps(payload).encode("utf-8")

reply = self._nam.sendCustomRequest(request, b"PATCH", payload_bytes)
reply.sslErrors.connect(lambda sslErrors: reply.ignoreSslErrors(sslErrors))
reply.setParent(self)

return reply

def cloud_delete(self, uri: Union[str, List[str]]) -> QNetworkReply:
url = self._prepare_uri(uri)

Expand Down
4 changes: 1 addition & 3 deletions qfieldsync/gui/cloud_create_project_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"""

import os
import re
from pathlib import Path
from typing import Optional

Expand Down Expand Up @@ -185,8 +184,7 @@ def cloudify_project(self):
self.create_cloud_project()

def get_cloud_project_name(self) -> str:
pattern = re.compile(r"[\W_]+")
return pattern.sub("", self.projectNameLineEdit.text())
return self.projectNameLineEdit.text()

def create_empty_cloud_project(self):
self.convertProgressBar.setVisible(False)
Expand Down
15 changes: 12 additions & 3 deletions qfieldsync/gui/cloud_login_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(
self.on_login_button_clicked
)
self.buttonBox.button(QDialogButtonBox.Cancel).clicked.connect(
lambda: self.close()
self.on_cancel_button_clicked
)

self.serverUrlLabel.setVisible(False)
Expand Down Expand Up @@ -107,11 +107,17 @@ def __init__(
)
self.qfieldCloudIcon.setMinimumSize(175, 180)
self.qfieldCloudIcon.mouseDoubleClickEvent = (
lambda event: self.toggleServerUrlVisibility()
lambda event: self.toggle_server_url_visibility()
)
self.rejected.connect(self.on_rejected)
self.hide()

def toggleServerUrlVisibility(self):
def on_rejected(self) -> None:
if self.parent():
self.parent().setEnabled(True)
self.setEnabled(True)

def toggle_server_url_visibility(self) -> None:
self.serverUrlLabel.setVisible(not self.serverUrlLabel.isVisible())
self.serverUrlCmb.setVisible(not self.serverUrlCmb.isVisible())

Expand Down Expand Up @@ -174,3 +180,6 @@ def on_login_finished(self) -> None:
self.passwordLineEdit.setEnabled(False)
self.rememberMeCheckBox.setEnabled(False)
self.done(QDialog.Accepted)

def on_cancel_button_clicked(self):
self.reject()
41 changes: 25 additions & 16 deletions qfieldsync/gui/cloud_projects_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,19 @@ def __init__(

self.update_welcome_label()

if not self.network_manager.has_token():
if self.network_manager.has_token():
self.show_projects()
self.show()
self.createButton.setEnabled(True)
else:
CloudLoginDialog.show_auth_dialog(
self.network_manager,
lambda: self.on_auth_accepted(),
lambda: self.close(),
parent=self,
)
else:
self.show_projects()
self.hide()
self.createButton.setEnabled(False)

self.use_current_project_directory_action = QAction(
QIcon(), self.tr("Use Current Project Directory")
Expand Down Expand Up @@ -509,18 +513,7 @@ def on_button_box_clicked(self) -> None:

def on_local_dir_line_edit_text_changed(self) -> None:
local_dir = self.localDirLineEdit.text()
feedback, feedback_msg = local_dir_feedback(local_dir)
self.localDirFeedbackLabel.setText(feedback_msg)

if feedback == LocalDirFeedback.Error:
self.localDirFeedbackLabel.setStyleSheet("color: red;")
self.submitButton.setEnabled(False)
elif feedback == LocalDirFeedback.Warning:
self.localDirFeedbackLabel.setStyleSheet("color: orange;")
self.submitButton.setEnabled(True)
else:
self.localDirFeedbackLabel.setStyleSheet("color: green;")
self.submitButton.setEnabled(True)
self.update_local_dir_feedback(local_dir)

def on_local_dir_line_edit_editing_finished(self) -> None:
local_dir = self.localDirLineEdit.text()
Expand Down Expand Up @@ -802,7 +795,7 @@ def show_project_form(self) -> None:
)
self.projectIsPrivateCheckBox.setChecked(self.current_cloud_project.is_private)
self.projectOwnerLineEdit.setText(self.current_cloud_project.owner)
self.localDirLineEdit.setText(self.current_cloud_project.local_dir)
self.localDirLineEdit.setText(self.current_cloud_project.local_dir or "")
self.projectUrlLabelValue.setText(
'<a href="{url}">{url}</a>'.format(
url=(self.network_manager.url + self.current_cloud_project.url)
Expand All @@ -824,6 +817,8 @@ def show_project_form(self) -> None:
).toString()
)

self.update_local_dir_feedback(self.localDirLineEdit.text())

if self.current_cloud_project.user_role not in ("admin", "manager"):
self.projectNameLineEdit.setEnabled(False)
self.projectDescriptionTextEdit.setEnabled(False)
Expand Down Expand Up @@ -1029,6 +1024,20 @@ def show_sync_popup(self) -> None:
self.transfer_dialog.accepted.connect(self.on_transfer_dialog_accepted)
self.transfer_dialog.open()

def update_local_dir_feedback(self, local_dir: str) -> None:
feedback, feedback_msg = local_dir_feedback(local_dir)
self.localDirFeedbackLabel.setText(feedback_msg)

if feedback == LocalDirFeedback.Error:
self.localDirFeedbackLabel.setStyleSheet("color: red;")
self.submitButton.setEnabled(False)
elif feedback == LocalDirFeedback.Warning:
self.localDirFeedbackLabel.setStyleSheet("color: orange;")
self.submitButton.setEnabled(True)
else:
self.localDirFeedbackLabel.setStyleSheet("color: green;")
self.submitButton.setEnabled(True)

def on_transfer_dialog_rejected(self) -> None:
if self.project_transfer:
self.project_transfer.abort_requests()
Expand Down
2 changes: 1 addition & 1 deletion qfieldsync/libqfieldsync
Submodule libqfieldsync updated 1 files
+6 −2 layer.py

0 comments on commit e937193

Please sign in to comment.