Skip to content

Commit

Permalink
Added EOY Menu and archiving of return files when emailing
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsher committed Mar 16, 2023
1 parent b9b9519 commit fc9c361
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 12 deletions.
45 changes: 44 additions & 1 deletion src/devicekiosk.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import zipfile
import traceback
import subprocess
import uuid

from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine
Expand Down Expand Up @@ -54,6 +55,7 @@ class UI(QObject):
showErrorPageSignal = Signal(None)
showFinishSignal = Signal(None)
showEOYReturnSignal = Signal(None)
showEOYStartSignal = Signal(None)

firstName = ""
lastName = ""
Expand Down Expand Up @@ -220,6 +222,11 @@ def submitEOYReturn(self, returnInfo):
self.addToReturnFile(returnSerial, chargerReturned)
self.showEOYReturnSignal.emit()

@Slot('QString')
def submitEOYFinish(self, returnEmail):
self.emailEOYReturnFiles(returnEmail)
self.archiveReturns()
self.showEOYStartSignal.emit()

def postToZenDesk(self):
self.errorMessage = ""
Expand Down Expand Up @@ -273,6 +280,34 @@ def sendEmail(self):
self.errorMessage = ex
s.close()

def emailEOYReturnFiles(self, returnAddress):
msg = EmailMessage()
msg['Subject'] = 'EOY Return Files'
body = "EOY Return Files"
msg.set_content(body)
attachmentFolder = os.path.dirname(os.path.abspath(__file__))
# files =
for file in os.listdir(attachmentFolder):
if file.endswith(".csv"):
with open(os.path.join(attachmentFolder, file), 'rb') as content_file:
print(file)
content = content_file.read()
msg.add_attachment(content, maintype='application', subtype='txt', filename=str(file))
# email.add_attachment(content, maintype='application', subtype='pdf', filename='example.pdf')
msg['From'] = self.config["smtp_user"]
msg['To'] = "asher@tolland.k12.ct.us, " + returnAddress
# Send the message via Gmail SMTP server
s = smtplib.SMTP("smtp.gmail.com", 587)
s.ehlo()
s.starttls()
s.login(self.config["smtp_user"], self.config["smtp_password"])
try:
s.send_message(msg)
except smtplib.SMTPException as ex:
self.errorMessage = ex
print("Email error " + ex)
s.close()

def addToReturnFile(self, serial, returnedCharger):
print("Adding " + serial + " to return file, with charger: " + str(returnedCharger))
filename = "eoy-returns-" + str(datetime.date.today()) + ".csv"
Expand All @@ -287,7 +322,15 @@ def addToReturnFile(self, serial, returnedCharger):
with open(returnsFile, 'a') as f:
f.writelines(serial + "," + str(returnedCharger) + "\n")
f.close()


def archiveReturns(self):
workingDir = os.path.dirname(os.path.abspath(__file__))
archiveDir = os.path.join(workingDir, "return-archive", str(uuid.uuid4()))
if not os.path.exists(archiveDir):
os.makedirs(archiveDir)
for file in os.listdir(workingDir):
if file.endswith(".csv"):
shutil.move(os.path.join(workingDir, file), archiveDir)

if __name__ == "__main__":
QGuiApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) #enable highdpi scaling
Expand Down
103 changes: 103 additions & 0 deletions src/qml/EOYFinish.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import QtQuick
import QtQuick.Window
import QtQuick.Controls
import QtQuick.Layouts

Item {

function verifyForm() {
if (inputEmail.text.toString().length > 0) {
btnSubmit.enabled = true
}
else {
btnSubmit.enabled = false
}
}

function setFocus() {
inputEmail.focus = true
inputEmail.forceActiveFocus()
}

property var chargerReturned: true



ColumnLayout {
anchors.fill: parent
// spacing: 2

Text {
id: txtHeader
Layout.fillWidth: true
Layout.fillHeight: true

text: "Enter an email address to receive the return files.\nEmail will also be sent to Candace de Loureiro.\nFiles will be backed up this computer in the event something goes wrong."
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap
font.pointSize: 30

}

// AnimatedImage {
// id: image
// Layout.alignment: Qt.AlignHCenter
// source: "../images/dropoff.gif"
// fillMode: Image.Image.PreserveAspectCrop
// }

TextField {
id: inputEmail
placeholderText: qsTr("Email Address")
font.pointSize: 20
Layout.fillWidth: true
Layout.fillHeight: true
horizontalAlignment: TextInput.AlignHCenter
focus: true
onTextChanged: {
verifyForm()
}

Component.onCompleted: {
this.focus = true
this.forceActiveFocus()
}
}

Button {
id: btnSubmit
text: "Submit Returns"
enabled: false
font.pointSize: 50
Layout.fillWidth: true
Layout.fillHeight: true

onClicked: {
ui.submitEOYFinish(inputEmail.text)
}
}

Button {
id: btnMenu
text: "Return to EOY Menu"
enabled: true
font.pointSize: 20
Layout.fillWidth: true
Layout.fillHeight: true

onClicked: {
contentFrame.push(Qt.createComponent("EOYStart.qml"))
}
}

}
// Setting focus any other way doesn't seem to work.
// Kind of kludge, but works
Timer {
interval: 100
running: true
repeat: false
onTriggered: setFocus()
}
}
23 changes: 14 additions & 9 deletions src/qml/EOYReturn.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ Item {
btnChargerNoText.color = "white"
btnChargerNoRect.color = "red"
}

function listProperty(item)
{
for (var p in item)
console.log(p + ": " + item[p]);
}

ColumnLayout {
anchors.fill: parent
Expand Down Expand Up @@ -165,9 +159,7 @@ Item {
}
}
}
}


}

Button {
id: btnSubmit
Expand All @@ -182,6 +174,19 @@ Item {
ui.submitEOYReturn(returnInfo)
}
}

Button {
id: btnMenu
text: "Return to EOY Menu"
enabled: true
font.pointSize: 20
Layout.fillWidth: true
Layout.fillHeight: true

onClicked: {
contentFrame.push(Qt.createComponent("EOYStart.qml"))
}
}

}
// Setting focus any other way doesn't seem to work.
Expand Down
59 changes: 59 additions & 0 deletions src/qml/EOYStart.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import QtQuick
import QtQuick.Window
import QtQuick.Controls
import QtQuick.Layouts

Item {
ColumnLayout {
anchors.fill: parent
// spacing: 2

Text {
id: txtIntro
Layout.fillWidth: true
Layout.fillHeight: true

text: "EOY Return"
// anchors.fill: self
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WordWrap
font.pointSize: 30
// fontSizeMode: Text.Fit
// minimumPixelSize: 30
// font.pixelSize: 1000

// anchors.centerIn: self
}

// Image {
// id: image
// width: 100
// height: 100
// source: "../images/logo.png"
// Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
// fillMode: Image.PreserveAspectFit
// }

Button {
id: btnDropOff
text: "Begin Returns"
font.pointSize: 50
Layout.fillWidth: true
Layout.fillHeight: true
onClicked: {
contentFrame.push(Qt.createComponent("EOYReturn.qml"))
}
}
Button {
id: btnPickUp
text: "Submit Saved Returns"
font.pointSize: 50
Layout.fillWidth: true
Layout.fillHeight: true
onClicked: {
contentFrame.push(Qt.createComponent("EOYFinish.qml"))
}
}
}
}
9 changes: 7 additions & 2 deletions src/qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ ApplicationWindow {
function onShowEOYReturnSignal() {
// contentFrame.clear()
contentFrame.push(Qt.createComponent("EOYReturn.qml"))
}
}

function onShowEOYStartSignal() {
// contentFrame.clear()
contentFrame.push(Qt.createComponent("EOYStart.qml"))
}
}

// Automatically go to a non-standard kiosk mode start page
Expand All @@ -90,7 +95,7 @@ ApplicationWindow {
break;
case 2:
// EOY Return Only Mode
contentFrame.push(Qt.createComponent("EOYReturn.qml"))
contentFrame.push(Qt.createComponent("EOYStart.qml"))
default:
break;
}
Expand Down

0 comments on commit fc9c361

Please sign in to comment.