예제 #1
0
    def post(self):
        data = self.parser.parse_args()

        if data["form_type"] == "add":

            # since put it will update regardless
            # TODO delete
            if PeopleModel.find_person(data['user']):
                return {'message': "This user already exists"}, 400

            person = PeopleModel(data["user"])
            try:
                person.save_to_db()
            except Exception as e:
                return {
                    "message": "An error occurred while saving the item.",
                    "error": "{}".format(e)
                }, 500

            return redirect(url_for("home"))

        elif data["form_type"] == "del":
            person = PeopleModel.find_person(data['user'])
            if person:
                try:
                    person.delete_from_db()
                except Exception as e:
                    return {
                        "message": "An error occurred while deleting",
                        "error": "{}".format(e)
                    }, 500
            else:
                return {'message': "Doesn't exist."}, 400

            return redirect(url_for("home"))
예제 #2
0
    def __init__(self, drawing, recipient, sender):
        # check for people
        if not PeopleModel.find_person(recipient):
            raise Exception("Recipient does not exist")
        if not PeopleModel.find_person(sender):
            raise Exception("Sender does not exist")

        hashed_string = self.hash_drawing(drawing)
        # make sure no duplicate
        # if not DrawingModel.find_by_hash(hashed_string):
        self.drawing = drawing
        self.date_time = datetime.now(tz=pytz.utc)
        self.hash_value = hashed_string
        self.recipient = recipient
        self.sender = sender
예제 #3
0
 def __init__(self, recipient, message):
     if PeopleModel.find_person(recipient):
         self.recipient = recipient
         self.message = message
         self.date_time = datetime.now(tz=pytz.utc)
     else:
         raise Exception("Person does not exist")