示例#1
0
    def post(self, sender):
        args = Messages_List.parser.parse_args()
        item = Messages(sender, args['receiver'], args['subject'],
                        args['message'])

        item.save_to()
        return item.json()
示例#2
0
 def delete():
     data = {}
     msgs = Messages()
     if not request.values.has_key('name'):
         msgs.add(u"no name supplied")
         data["errors"] = msgs
         return asJSON(data)
     name = request.values['name']
     if not len(msgs.getAll()) > 0:
         dns = DNSHandler()
         data = dns.delete(name)
     else:
         data["errors"] = msgs
     if data.has_key("error") or data.has_key("errors"):
         data["success"] = False
     return asJSON(data)
 def delete():
     data = {}
     msgs = Messages()
     if not request.values.has_key('name'):
         msgs.add(u"no name supplied")
         data["errors"] = msgs
         return asJSON(data)
     name = request.values['name']
     if not len(msgs.getAll()) > 0:
         dns = DNSHandler()
         data = dns.delete(name)
     else:
         data["errors"] = msgs
     if data.has_key("error") or data.has_key("errors"):
         data["success"] = False
     return asJSON(data)
示例#4
0
 def get(self):
     args = Unread_Messages.parser.parse_args()
     items = Messages.get_unread_messages(args['status'], args['sender'])
     if items:
         return {'Messages': list(map(lambda x: x.json(), items))}
     else:
         return {'All messages are read'}
示例#5
0
 def get(self):
     args = Read_Message.parser.parse_args()
     item = Messages.get_message_by_subject(args['subject'])
     if item:
         return {'Message': '{}'.format(item["Message"])}
     else:
         return {
             'Message':
             'with the subject {} was not found'.format(args['subject'])
         }
示例#6
0
 def delete(self, name):
     args = Delete_Message.parser.parse_args()
     item = Messages.get_specific_message(args['subject'], args['role'],
                                          name)
     if item:
         item.delete_()
         return {
             'Message':
             'with the subject {} has been deleted from records'.format(
                 args['subject'])
         }
     return {
         'Message':
         'with the subject {} is already not on the list'.format(
             args['subject'])
     }
示例#7
0
 def editHost():
     data = {}
     msgs = Messages()
     if not request.values.has_key('name'):
         msgs.add(u"no name supplied")
         data["errors"] = msgs
         return asJSON(data)
     if not request.values.has_key('host'):
         msgs.add(u"no host address supplied")
         data["errors"] = msgs
         return asJSON(data)
     name = request.values['name']
     host = request.values['host']
     if not name:
         msgs.add(u"no name supplied")
     if not len(msgs.getAll()) > 0:
         dns = DNSHandler()
         data = dns.editHost(name, host)
     else:
         data["errors"] = msgs
     if data.has_key("error") or data.has_key("errors"):
         data["success"] = False
     return asJSON(data)
 def editHost():
     data = {}
     msgs = Messages()
     if not request.values.has_key('name'):
         msgs.add(u"no name supplied")
         data["errors"] = msgs
         return asJSON(data)
     if not request.values.has_key('host'):
         msgs.add(u"no host address supplied")
         data["errors"] = msgs
         return asJSON(data)
     name = request.values['name']
     host = request.values['host']
     if not name:
         msgs.add(u"no name supplied")
     if not len(msgs.getAll()) > 0:
         dns = DNSHandler()
         data = dns.editHost(name, host)
     else:
         data["errors"] = msgs
     if data.has_key("error") or data.has_key("errors"):
         data["success"] = False
     return asJSON(data)
示例#9
0
 def editName():
     data = {}
     msgs = Messages()
     if not request.values.has_key('from'):
         msgs.add(u"no from name supplied")
         data["errors"] = msgs
         return asJSON(data)
     fromName = request.values['from']
     if not request.values.has_key('to'):
         msgs.add(u"no name supplied")
         data["errors"] = msgs
         return asJSON(data)
     toName = request.values['to']
     if not len(msgs.getAll()) > 0:
         dns = DNSHandler()
         data = dns.editName(fromName, toName)
     else:
         data["errors"] = msgs
     if data.has_key("error") or data.has_key("errors"):
         data["success"] = False
     return asJSON(data)
 def editName():
     data = {}
     msgs = Messages()
     if not request.values.has_key('from'):
         msgs.add(u"no from name supplied")
         data["errors"] = msgs
         return asJSON(data)
     fromName = request.values['from']
     if not request.values.has_key('to'):
         msgs.add(u"no name supplied")
         data["errors"] = msgs
         return asJSON(data)
     toName = request.values['to']
     if not len(msgs.getAll()) > 0:
         dns = DNSHandler()
         data = dns.editName(fromName, toName)
     else:
         data["errors"] = msgs
     if data.has_key("error") or data.has_key("errors"):
         data["success"] = False
     return asJSON(data)
示例#11
0
 def get(self, sender):
     items = Messages.get_messages_by_sender(sender)
     if items:
         return {'Messages': list(map(lambda x: x.json(), items))}
     return {'Messages': 'Messages were not found'}