Esempio n. 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()
Esempio n. 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)
Esempio n. 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'}
Esempio n. 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'])
         }
Esempio n. 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'])
     }
Esempio n. 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)
Esempio n. 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)
Esempio n. 10
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)
Esempio n. 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'}