0

I have a barcode reader that reads the code of the citizenship card and verifies, on a server with OctoberCMS, if the user is registered. If you are registered, it returns the information of the user that is hosted in the database. If it is not, it will create a record in the database with the information provided by the citizenship card and will return the ID of the new record. So far everything is going well.

The problem is that I am new to GUI programming and I need to create an interface for this code. I have advanced work using PyQt.

For now, I have created a simple interface that captures additional information that must be added to the user when it is created or verified in OctoberCMS. My question is: What is the best way to send the additional information using the API that I made in OctoberCMS ?. I would be grateful if you could provide me with a sample code, something general, since I don't understand PyQt's classes and modules very well.

This is the code I have made in python.

class MyApp(QtWidgets.QMainWindow, Ui_MainWindow):

    def __init__(self):
        #Iniciar el objeto QMainWindow
        QtWidgets.QMainWindow.__init__(self)
        Ui_MainWindow.__init__(self)
        self.setupUi(self)
        self.showMaximized()
        self.email.textChanged.connect(self.validar_email)
        self.telefono.textChanged.connect(self.validar_telefono)
        self.pushButton.clicked.connect(self.validar_formulario)

    def validar_email(self):
        email = self.email.text()
        validar = re.match('^[a-zA-Z0-9\._-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,4}$', email, re.I)
        if email == "":
            self.email.setStyleSheet("border: 1px solid yellow;")
            return False
        elif not validar:
            self.email.setStyleSheet("border: 1px solid red;")
            return False
        else:
            self.email.setStyleSheet("border: 1px solid green;")
            return True

    def validar_telefono(self):
        telefono = self.telefono.text()
        validar = re.match('^(\d{10})$', telefono, re.I)
        if telefono == "":
            self.telefono.setStyleSheet("border: 1px solid yellow;")
            return False
        elif not validar:
            self.telefono.setStyleSheet("border: 1px solid red;")
            return False
        else:
            self.telefono.setStyleSheet("border: 1px solid green;")
            return True

    def mostrar(self):
        self.label_7.setText(str(pregunta1) + "_" + str(pregunta2) + "_" + str(pregunta3) + "_" + str(dias))

    def validar_formulario(self):
        if self.validar_telefono() and self.validar_email():
            self.mostrar()
            QMessageBox.information(self, "Formulario correcto", "Validación correcta", QMessageBox.Discard)
        else:
            QMessageBox.warning(self, "Formulario incorrecto", "Validación incorrecta", QMessageBox.Discard)

I need to send this information through the Api like this: http://localhost/api/myoctobermodule, using from-data.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • 1
    You could provide the code of your application that was written with OctoberCMS and so we could take it as a basis to show you how to send the information from Qt. – eyllanesc May 31 '20 at 21:29
  • Basically I can't provide parts of the code, excuse me. But what I can tell you is that I just need to "point" to the API address. I explain: api address = "http://nameserver.com/api/myapi" ,. I am using form-data. key = name /// value = somename key = otherkey //// value = othervalue. What I need to know is how the data is sent in PyQT – Jean Pierre Rojas May 31 '20 at 21:44
  • please provide a [mre] – eyllanesc May 31 '20 at 21:45
  • Check it now please. – Jean Pierre Rojas May 31 '20 at 22:18
  • 1
    1) Show the code as text, not images. 2) It is not necessary for the MRE to involve your project, it is better that you create a new project from scratch oriented to the form and then provide that code. Please read [ask] and review the [tour] – eyllanesc May 31 '20 at 22:22
  • Please check it again. – Jean Pierre Rojas May 31 '20 at 22:35
  • It seems that you have not understood me, the PyQt is trivial (a form with some validators), what I have asked you is a simple and functional example of how to implement the form on the server side. The link you provide is irrelevant. – eyllanesc May 31 '20 at 22:40
  • On the server I simply receive all the data, save it in different variables and send it to their respective models so that it is saved in the database. With this I have no problem, it is working well for me. What I need to know is how to do what you call "trivial", because I don't know how to submit the form information in PyQt in form-data. – Jean Pierre Rojas May 31 '20 at 22:45
  • mmm, it seems that you do not understand me, the communication (the sending of information) depends on both elements: the client and the server. So the code that I ask you is not because I think you have problems on the server but to use it as the basis in my possible answer, I have not used OctoberCMS so I cannot implement your server, if I had access to a server then I would analyze the necessary requirements for Qt to send the information Can you provide a set of steps that allows me to implement your server and thus be able to test my possible solution? – eyllanesc May 31 '20 at 22:50
  • self-hosted CMS platform based on the Laravel PHP Framework. I am using server with Linux OS, Apache 2.4.43, Php 7.2.30, MySQL 10.3.22-MariaDB-cll-live. Does this help you? – Jean Pierre Rojas May 31 '20 at 23:02
  • it is not useful, you are giving me the requirements of the technologies, which is not what I have asked you. I am going to try to publish a code, if it works great and if I do not follow my way. It is annoying to ask (almost beg) many times the same. – eyllanesc May 31 '20 at 23:05
  • I sincerely apologize, I cannot understand what exactly you need to be able to help me. I do not have much experience in this of servers. – Jean Pierre Rojas May 31 '20 at 23:07
  • Searching among my answers I found a question on how to send a form (text and files) to Django, and I think the same should be used in your case considering that your CMS does not have any special attribute. – eyllanesc May 31 '20 at 23:10
  • It has illustrated me a little, but I still have questions. Is there any way I can contact you? I would like you to give me advice. I could clearly donate something to you = D – Jean Pierre Rojas May 31 '20 at 23:25
  • The donation is voluntary so neither you nor I will have any obligation, you can contact me (in my github profile is my email: https://github.com/eyllanesc/) but I will consider it as a job. – eyllanesc May 31 '20 at 23:28
  • The wrote u an email. – Jean Pierre Rojas May 31 '20 at 23:40

0 Answers0