Ejemplo n.º 1
0
 def save(self):
     # But we don't want junk messages getting saved. Let's report an error
     # if the message is not valid.
     if self.is_valid():
         HackGMSDatabase.save_message_record(self)
     else:
         raise ValueError("Tried to save an invalid message!")
Ejemplo n.º 2
0
 def save(self):
     # But we don't want junk messages getting saved. Let's report an error
     # if the message is not valid.
     if self.is_valid():
         HackGMSDatabase.save_message_record(self)
     else:
         raise ValueError("Tried to save an invalid message!")
Ejemplo n.º 3
0
def deleteMessage(message_id):
    message_to_delete = Message.get_message_by_id(message_id)
    if message_to_delete is not None:
        HackGMSDatabase.delete_message_record(message_to_delete)
        response = make_response("Message %s was deleted." % message_id, 200)
    else:
        response = make_response("Message %s does not exist." % message_id, 404)
    return response 
Ejemplo n.º 4
0
def deleteMessage(message_id):
    message_to_delete = Message.get_message_by_id(message_id)
    if message_to_delete is not None:
        HackGMSDatabase.delete_message_record(message_to_delete)
        response = make_response("Message %s was deleted." % message_id, 200)
    else:
        response = make_response("Message %s does not exist." % message_id,
                                 404)
    return response
Ejemplo n.º 5
0
def createNewMessage():
    text = request.json.get("text")
    author = request.json.get("author")
    date = datetime.utcnow()
    new_message = Message(text=text, author=author, date=date)
    if new_message.is_valid():
        HackGMSDatabase.create_message_record(new_message)
        response = make_response(json.dumps(new_message.ready_for_json()), 200)
    else:
        error_list = '; '.join(new_message.errors)
        response = make_response("There were errors creating your message: %s" % error_list, 400)
    return response
Ejemplo n.º 6
0
def createNewMessage():
    text = request.json.get("text")
    author = request.json.get("author")
    date = datetime.utcnow()
    new_message = Message(text=text, author=author, date=date)
    if new_message.is_valid():
        HackGMSDatabase.create_message_record(new_message)
        response = make_response(json.dumps(new_message.ready_for_json()), 200)
    else:
        error_list = '; '.join(new_message.errors)
        response = make_response(
            "There were errors creating your message: %s" % error_list, 400)
    return response
Ejemplo n.º 7
0
 def get_message_by_id(cls, message_id):
     record = HackGMSDatabase.get_message_record(message_id)
     if record is not None:
         message = Message(*record)
         return message
     else:
         return None
Ejemplo n.º 8
0
 def get_message_by_id(cls, message_id):
     record = HackGMSDatabase.get_message_record(message_id)
     if record is not None:
         message = Message(*record)
         return message
     else:
         return None
Ejemplo n.º 9
0
    def get_all_messages(cls):

        # Ask the database for all the stored records of messages 
        # (in date order, please!)
        records_list = HackGMSDatabase.get_message_records()
        # Let's make a list to keep all the finished Messages
        messages_list = []
        # One by one, turn each record into a Message and add it to the list.
        for each_record in records_list:
            new_message = Message(*each_record)
            messages_list.append(new_message)
        # OK, all done. Let's return the list of messages.
        return messages_list
Ejemplo n.º 10
0
    def get_all_messages(cls):

        # Ask the database for all the stored records of messages
        # (in date order, please!)
        records_list = HackGMSDatabase.get_message_records()
        # Let's make a list to keep all the finished Messages
        messages_list = []
        # One by one, turn each record into a Message and add it to the list.
        for each_record in records_list:
            new_message = Message(*each_record)
            messages_list.append(new_message)
        # OK, all done. Let's return the list of messages.
        return messages_list
Ejemplo n.º 11
0
def make_sure_the_database_is_ready():
    if HackGMSDatabase.schema_is_present():
        app.logger.info(" * All required tables were found in the database.")
    else:
        app.logger.warn(" * Initializing the database.")
        HackGMSDatabase.initialize()
Ejemplo n.º 12
0
def make_sure_the_database_is_ready():
    if HackGMSDatabase.schema_is_present():
        app.logger.info(" * All required tables were found in the database.")
    else:
        app.logger.warn(" * Initializing the database.")
        HackGMSDatabase.initialize()