示例#1
0
class PlayerSelection(Screen):
    """
	menu for managing which child is here
	"""
    def __init__(self, **kwargs):
        super(PlayerSelection, self).__init__(**kwargs)
        self.groupName = kwargs["name"].replace("_", "")
        self.build()

    def build(self):
        self.layout = BoxLayout(orientation="vertical")
        sc = ScrollView()
        self.scb = GridLayout(cols=2,
                              row_default_height='100dp',
                              row_force_default=True,
                              size_hint_y=None)
        self.scb.bind(minimum_height=self.scb.setter('height'))

        self.attend = {}
        self.players = []

        for player in user:
            self.addPlayer(player)

        sc.add_widget(self.scb)

        sendButton = Button(text='Sende Mail', size_hint=(1, .2))
        sendButton.bind(on_release=self.askPassword)

        backButton = Button(text='Zurück', size_hint=(1, .2))
        backButton.bind(on_release=self.back)

        self.layout.add_widget(sc)
        self.layout.add_widget(sendButton)
        self.layout.add_widget(backButton)

        self.add_widget(self.layout)

    def on_enter(self):
        super(PlayerSelection, self).on_enter(self)
        self.remove_widget(self.layout)
        self.build()

    def addPlayer(self, player):
        if player[2] == self.groupName:
            playerId = player[0] + "\t" + player[1]
            self.players.append(player)
            self.attend[playerId] = "normal"
            self.scb.add_widget(Label(text=player[0]))
            self.scb.add_widget(
                CheckBox(on_press=partial(self.togglePlayer, playerId)))

    def togglePlayer(self, playerId, value, **kwargs):
        self.attend[playerId] = value.state

    def back(self, obj):
        sm.current = "Spiel"

    def askPassword(self, obj):
        """
		asks for password for email
		"""
        self.server = SMTP('smtp.gmail.com:587')
        self.server.ehlo()
        self.server.starttls()

        c.execute("Select mail from trainer")
        self.trainerMail = c.fetchone()[0]

        self.popBox = BoxLayout(orientation="vertical")

        self.passInput = TextInput(password=True, multiline=False)
        submit = Button(text="Einloggen")
        submit.bind(on_release=self.loginToMail)

        self.popBox.add_widget(
            Label(text=
                  "Bitte geben sie ihr E-Mail Passwort für ihre Mail ({}) ein:"
                  .format(self.trainerMail)))
        self.popBox.add_widget(self.passInput)
        self.popBox.add_widget(submit)

        self.loginPopup = Popup(title='Einloggen',
                                content=self.popBox,
                                size_hint=(.8, .5))
        self.loginPopup.open()

    def loginToMail(self, obj):
        """
		logs into mail and sends
		"""
        try:
            #login
            self.server.login(self.trainerMail, self.passInput.text)
            print("Login Successful")

            self.loginPopup.dismiss()

            mailPopBox = BoxLayout(orientation="vertical")
            self.mailPop = Popup(title='Sende Mail',
                                 content=mailPopBox,
                                 size_hint=(.8, .5))

            sendToNames = [
                pId.split("\t")[0] for pId in self.attend
                if self.attend[pId] == "normal"
            ]
            sendToNames = ", ".join(sendToNames)

            submit = Button(text="Sende Mail")
            submit.bind(on_release=self.sendMails)

            cancel = Button(text="Abbrechen")
            cancel.bind(on_release=self.mailPop.dismiss)

            mailPopBox.add_widget(
                Label(text="Send Mail an die Eltern von: {}".format(
                    sendToNames)))
            mailPopBox.add_widget(submit)
            mailPopBox.add_widget(cancel)

            self.mailPop.open()

        except Exception as e:
            self.popBox.children[
                2].text += "\n(Problem bei Login, Bitte erneut versuchen)"
            self.popBox.do_layout()

    def sendMails(self, obj):
        c.execute("Select name from trainer")
        trainerName = c.fetchone()[0]
        for playerId in self.attend:
            if self.attend[playerId] == "normal":
                playerMail = playerId.split("\t")[1]
                playerName = playerId.split("\t")[0]
                subject = "Badminton-Benachrichtigung"
                text = "Dies ist eine automatische Benachrichtigung, dass ihr Kind {} heute nicht zum Badminton erschienen ist.\nLiebe Grüße, {}".format(
                    playerName, trainerName).encode("utf-8")

                msg = MIMEText(text, "plain", "utf-8")
                msg["Subject"] = subject
                msg["From"] = self.trainerMail
                msg["To"] = playerMail

                self.server.send_message(msg)
        self.mailPop.dismiss()
        self.server.quit()
        sm.current = "Menu"
示例#2
0
class UserManager(Screen):
    """
	menu for managing the users

	TODO: import csv
	TODO: telefon numbers for sms? 
	"""
    def __init__(self, **kwargs):
        super(UserManager, self).__init__(**kwargs)
        self.layout = BoxLayout(orientation="vertical")

        loadTheChildren()

        newUser = Button(text="+", size_hint=(1, .2))
        newUser.bind(on_release=self.createNewPlayer)

        backButton = Button(text='Zurück', size_hint=(1, .2))
        backButton.bind(on_release=self.toMenu)

        sc = ScrollView()
        self.users = GridLayout(cols=3,
                                row_default_height='70dp',
                                row_force_default=True,
                                size_hint_y=None)
        self.users.bind(minimum_height=self.users.setter('height'))
        for u in user:
            self.addUser(u)

        sc.add_widget(self.users)

        self.layout.add_widget(sc)
        self.layout.add_widget(newUser)
        self.layout.add_widget(backButton)

        self.add_widget(self.layout)

    def addUser(self, entrys):
        """
		Idea: Change Groups into Dropdown and add extra group management in trainer
		Todo: Delete Button behind every user
		"""
        name = entrys[0]
        mail = entrys[1]
        group = entrys[2]

        nameInput = TextInput(text=str(name), multiline=False)
        self.users.add_widget(nameInput)

        mailInput = TextInput(text=str(mail), multiline=False)
        self.users.add_widget(mailInput)

        groupInput = TextInput(text=str(group),
                               multiline=False,
                               size_hint=(.3, 1))
        self.users.add_widget(groupInput)

        #delButton = Button(text="-")
        #delButton.bind(on_release=self.deleteUser)
        #self.users.add_widget(delButton)

        allInputs.append((nameInput, mailInput, groupInput))

    def deleteUser(self, obj):
        print(obj)

    def toMenu(self, obj):
        self.saveTheChildren()
        sm.current = "Menu"

    def createNewPlayer(self, obj):
        user.append(("", "", ""))
        self.addUser(user[-1])
        self.layout.do_layout()

    def saveTheChildren(self):
        """
		Insert users to database
		Todo: Encrypt
		"""
        global user
        self.updateUser()
        # delete old entrys and update with new ones
        c.execute('DELETE FROM users')
        for u in user:
            c.execute('''INSERT INTO users VALUES(?,?,?)''',
                      (u[0], u[1], u[2]))
        conn.commit()

    def updateUser(self):
        """
		Updates our user info by evaluating the text inputs
		"""
        global user
        user = []
        for inp in allInputs:
            newInfo = [i.text for i in inp]
            if "".join(newInfo) != "":
                user.append(newInfo)
        return user
class OrderActionPopup(Popup):
    def __init__(self, products, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.title = "New Order"
        app = MDApp.get_running_app()
        self.layout = BoxLayout(size_hint_y=2)
        self.scroll = ScrollView()
        #self.scroll.do_scroll_y = True

        self.layout.orientation = "vertical"

        self.available_products = products  #app.customconfig.load_products()
        self.product_cost = 0
        self.products_selected = []
        self.markup = 0.2
        """ CUSTOMER NAME """
        customer_layout = BoxLayout()
        customer_layout.add_widget(Label(text=f"Customer:"))
        self.customer_input = MDTextField(color_mode='accent')
        customer_layout.add_widget(self.customer_input)
        self.layout.add_widget(customer_layout)
        """ CUSTOMER EMAIL """
        email_layout = BoxLayout()
        email_layout.add_widget(Label(text=f"Email:"))
        self.email_input = MDTextField(color_mode='accent')
        email_layout.add_widget(self.email_input)
        self.layout.add_widget(email_layout)
        """ PRODUCTS """
        product_title_layout = BoxLayout()
        product_title_layout.add_widget(Label(text=f"Products: "))

        self.add_prod_btn = MDRectangleFlatButton(text="Add Product")
        self.add_prod_menu = MDDropdownMenu(
            items=self.build_available_products(),
            width_mult=4,
            caller=self.add_prod_btn,
            callback=self.add_prod_callback)
        self.add_prod_btn.on_release = self.add_prod_menu.open

        product_title_layout.add_widget(self.add_prod_btn)
        self.product_list_layout = GridLayout()
        self.product_list_layout.cols = 3

        self.layout.add_widget(product_title_layout)
        self.layout.add_widget(self.product_list_layout)
        """ MATERIAL COST """
        self.Material_cost = Label(text=f"Material Cost: £0")
        self.layout.add_widget(self.Material_cost)
        """ CUSTOMER COST """
        self.customer_cost = MDTextField(color_mode='accent')
        self.customer_cost.on_text_validate = self.validate_customer_cost
        cc_layout = BoxLayout()
        cc_layout.add_widget(Label(text="Customer Cost:"))
        cc_layout.add_widget(self.customer_cost)
        self.layout.add_widget(cc_layout)
        """ MARKUP """
        default_markup = app.customconfig.get_setting("Markup")

        self.markup = MDTextField(color_mode='accent',
                                  text=str(default_markup))
        self.markup.on_text_validate = self.validate_markup
        m_layout = BoxLayout()
        m_layout.add_widget(Label(text="Markup %"))
        m_layout.add_widget(self.markup)
        self.layout.add_widget(m_layout)
        """ ORDER DATE """
        date_layout = BoxLayout()
        date_layout.add_widget(Label(text=f"Order Date: "))
        self.picker = MDDatePicker(callback=self.date_callback)
        self.picker_btn = MDRectangleFlatButton(text=str(self.picker.today),
                                                on_release=self.picker.open)
        date_layout.add_widget(self.picker_btn)
        self.layout.add_widget(date_layout)
        """ LEAD TIME """
        lead_layout = BoxLayout()
        lead_layout.add_widget(Label(text=f"Quoted Lead Time (Days): "))
        self.leadtime_btn = MDRectangleFlatButton(text="7")
        self.leadtime_menu = MDDropdownMenu(
            items=self.build_leadTimeEntrys(app),
            width_mult=4,
            caller=self.leadtime_btn,
            callback=self.leadtime_callback)
        self.leadtime_btn.on_release = self.leadtime_menu.open
        lead_layout.add_widget(self.leadtime_btn)

        self.layout.add_widget(lead_layout)
        """ ORIGIN """
        origin_layout = BoxLayout()
        origin_layout.add_widget(Label(text=f"Origin: "))
        self.origin_btn = MDRectangleFlatButton(text="Facebook")
        self.origin_menu = MDDropdownMenu(items=self.build_originEntrys(app),
                                          width_mult=4,
                                          caller=self.origin_btn,
                                          callback=self.origin_callback)
        self.origin_btn.on_release = self.origin_menu.open
        origin_layout.add_widget(self.origin_btn)

        self.layout.add_widget(origin_layout)
        """ PAYMENT """
        payment_layout = BoxLayout()
        payment_layout.add_widget(Label(text=f"Payment: "))
        self.payment_btn = MDRectangleFlatButton(text="Unpaid")
        self.payment_menu = MDDropdownMenu(items=self.build_paymentEntrys(app),
                                           width_mult=4,
                                           caller=self.payment_btn,
                                           callback=self.payment_callback)
        self.payment_btn.on_release = self.payment_menu.open
        payment_layout.add_widget(self.payment_btn)

        self.layout.add_widget(payment_layout)
        """ STATUS """
        status_layout = BoxLayout()
        status_layout.add_widget(Label(text=f"Status: "))
        self.status_btn = MDRectangleFlatButton(text="Order Placed")
        self.status_menu = MDDropdownMenu(items=self.build_statusEntrys(app),
                                          width_mult=4,
                                          caller=self.status_btn,
                                          callback=self.status_callback)
        self.status_btn.on_release = self.status_menu.open
        status_layout.add_widget(self.status_btn)

        self.layout.add_widget(status_layout)
        """ DELIVERY """
        delivery_layout = BoxLayout()
        delivery_layout.add_widget(Label(text="Delivery Method: "))
        self.delivery_btn = MDRectangleFlatButton(text="Collection")
        self.delivery_menu = MDDropdownMenu(
            items=self.build_deliveryEntrys(app),
            width_mult=4,
            caller=self.delivery_btn,
            callback=self.delivery_callback)
        self.delivery_btn.on_release = self.delivery_menu.open
        delivery_layout.add_widget(self.delivery_btn)

        self.layout.add_widget(delivery_layout)
        """ SAVE | DISCARD """
        buttonlayout = BoxLayout()
        buttonlayout.orientation = "horizontal"
        buttonlayout.add_widget(
            MDRectangleFlatButton(text="Discard", on_release=self.dismiss))
        buttonlayout.add_widget(
            MDRectangleFlatButton(text="Save Order", on_release=self.save))

        self.update_costing()
        self.layout.add_widget(buttonlayout)
        self.scroll.add_widget(self.layout)
        self.content = self.scroll

    def cancelOrder(self, td):
        print("Cancel Order")

    def validate_markup(self):
        try:
            if self.markup.text == "":
                self.markup.text = "0"
            self.update_costing()
        except ValueError:
            self.markup.text = "0"
            self.validate_markup()

    def validate_customer_cost(self):
        try:
            if self.customer_cost == "":
                self.customer_cost.text = "0"
            p_cost = self.Material_cost.text.replace("Material Cost: £", "")
            if float(p_cost) == 0:
                self.markup.text = "0"
                return
            self.markup.text = str(
                round(((float(self.customer_cost.text) - float(p_cost)) /
                       float(p_cost)) * 100, 2))
        except ValueError:
            self.customer_cost.text = "0"
            self.validate_customer_cost()

    def save(self, td):
        print("Save New order")

    def build_available_products(self):
        tmp = []
        for i in self.available_products:
            tmp.append({"text": i.name})
        return tmp

    def add_prod_callback(self, prod):
        for i in self.available_products:
            if i.name == prod.text:
                self.products_selected.append(i)
        self.product_list_layout.clear_widgets()

        for i in self.products_selected:
            self.product_list_layout.add_widget(MDRoundFlatButton(text=i.name))

        self.update_costing()
        self.layout.do_layout()

        self.add_prod_menu.dismiss()

    def update_costing(self):
        cost = 0
        for i in self.products_selected:
            cost += i.cost
        cost = round(cost, 2)
        self.Material_cost.text = f"Material Cost: £{cost}"
        if cost == 0:
            self.customer_cost.text = "0"
            return
        self.customer_cost.text = str(
            round(cost + (cost * (float(self.markup.text) / 100)), 2))

    def date_callback(self, date):
        self.picker_btn.text = str(date)

    def build_leadTimeEntrys(self, app):
        leadtime_range = app.customconfig.get_setting("Leadtime_max")
        tmp = []
        for i in range(int(leadtime_range)):
            tmp.append({"text": str(i)})
        return tmp

    def leadtime_callback(self, btn):
        self.leadtime_btn.text = btn.text
        self.leadtime_menu.dismiss()

    def build_originEntrys(self, app):
        origins = app.customconfig.get_setting("Origins")
        tmp = []
        for i in origins:
            tmp.append({"text": i})
        return tmp

    def origin_callback(self, btn):
        self.origin_btn.text = btn.text
        self.origin_menu.dismiss()

    def build_paymentEntrys(self, app):
        origins = app.customconfig.get_setting("Payments")
        tmp = []
        for i in origins:
            tmp.append({"text": i})
        return tmp

    def payment_callback(self, btn):
        self.payment_btn.text = btn.text
        self.payment_menu.dismiss()

    def build_statusEntrys(self, app):
        origins = app.customconfig.get_setting("Status")
        tmp = []
        for i in origins:
            tmp.append({"text": i})
        return tmp

    def status_callback(self, btn):
        self.status_btn.text = btn.text
        self.status_menu.dismiss()

    def build_deliveryEntrys(self, app):
        origins = app.customconfig.get_setting("Delivery")
        tmp = []
        for i in origins:
            tmp.append({"text": i})
        return tmp

    def delivery_callback(self, btn):
        self.delivery_btn.text = btn.text
        self.delivery_menu.dismiss()