Example #1
0
File: views.py Project: Njike/unap
    def create_model(self, form):
        """
           Create model from the form.

           Returns the model instance if operation succeeded.

           Must be implemented in the child class.

           :param form:
               Form instance
        """

        if form.data and form.validate:
            model = self.model()
            path = imageHandler(form.image.data)
            model.name = form.name.data
            model.country = form.country.data
            model.description = form.description.data
            model.category = form.category.data
            model.image_url = path
            model.winner = form.winner.data

            self.session.add(model)
            self.session.commit()

            return model
Example #2
0
File: views.py Project: Njike/unap
    def update_model(self, form, model):
        """
            Update model from the form.

            Returns `True` if operation succeeded.

            Must be implemented in the child class.

            :param form:
                Form instance
            :param model:
                Model instance
        """
        # print("model =============== ", form.amount)
        if form.data and form.validate:
            model.name = form.name.data
            model.country = form.country.data
            model.description = form.description.data
            model.category = form.category.data

            if form.image.data:
                path = imageHandler(form.image.data)
                model.image_url = path

            model.winner = form.winner.data

            self.session.commit()

            return True
Example #3
0
    def create_model(self, form):
        """
            Create model from the form.

            Returns the model instance if operation succeeded.

            Must be implemented in the child class.

            :param form:
                Form instance
        """

        if form.data:
            model = self.model()
            model.name = form.name.data.capitalize()
            model.code = form.code.data.upper()
            model.address = form.address.data
            model.image_url = imageHandler(form.image.data)
            self.session.add(model)
            self.session.commit()
            return self.model
Example #4
0
    def update_model(self, form, model):
        """
            Update model from the form.

            Returns `True` if operation succeeded.

            Must be implemented in the child class.

            :param form:
                Form instance
            :param model:
                Model instance
        """

        if form.data and form.validate:
            model.name = form.name.data.capitalize()
            model.code = form.code.data.upper()
            model.address = form.address.data
            model.image_url = imageHandler(form.image.data)
            self.session.commit()
            return True
        return False