コード例 #1
0
 def put(self):
     emp_number = get_raw_jwt()['identity']
     parser = reqparse.RequestParser()
     parser.add_argument('file_id',
                         help='This field cannot be blank',
                         required=True)
     parser.add_argument('comment',
                         help='This field cannot be blank',
                         required=True)
     data = parser.parse_args()
     attachment = models.Attachment(emp_number, self.screen)
     try:
         if attachment.put_comment(data) == 0:
             return {
                 "message":
                 "Comment not updated, no change found on submitted data or no file_id found"
             }
         else:
             result = {
                 "file_id": data['file_id'],
                 "comment": data['comment'],
                 "message": "Comment succesfully updated"
             }
             return result
     except Exception as e:
         print(e)
         return {'message': 'Something went wrong'}, 500
コード例 #2
0
ファイル: attachment.py プロジェクト: atseanpaul/modern-paste
def create_new_attachment(paste_id, file_name, file_size, mime_type,
                          file_data):
    """
    Create a new database entry for an attachment with the given file_name, associated with a particular paste ID.

    :param paste_id: Paste ID to associate with this attachment
    :param file_name: Raw name of the file
    :param file_size: Size of the file in bytes
    :param mime_type: MIME type of the file
    :param file_data: Binary, base64-encoded file data
    :return: An instance of models.Attachment describing this attachment entry
    :raises PasteDoesNotExistException: If the associated paste does not exist
    """
    # Add an entry into the database describing this file
    new_attachment = models.Attachment(
        paste_id=paste_id,
        file_name=secure_filename(file_name),
        file_size=file_size,
        mime_type=mime_type,
    )

    _store_attachment_file(paste_id, file_data, new_attachment)

    session.add(new_attachment)
    session.commit()

    return new_attachment
コード例 #3
0
ファイル: app.py プロジェクト: ip0000h/taskman
 def post(self, task_id):
     args = self.reqparse.parse_args()
     new_attachment = models.Attachment(
         task_id,
         current_user.id,
         args['comment']
     )
     models.db.session.add(new_attachment)
     models.db.session.commit()
     return self.schema.dump(new_attachment).data
コード例 #4
0
 def get(self):
     emp_number = get_raw_jwt()['identity']
     attachment = models.Attachment(emp_number, self.screen)
     parser = reqparse.RequestParser()
     parser.add_argument('file_id',
                         help='This field cannot be blank',
                         required=True)
     data = parser.parse_args()
     try:
         if data["file_id"] == "all":
             result = []
             for attachment in attachment.get_meta_all():
                 result.append({
                     "file_id": str(attachment[1]),
                     "comment": attachment[2],
                     "file_name": attachment[3],
                     "size": str(attachment[4]),
                     "type": attachment[5],
                     "date_added": attachment[9]
                 })
             return {
                 "data": result,
                 "message": "Files succesfully retrieved"
             }
         else:
             result = attachment.get(data["file_id"])
             if result is None:
                 return {"message": "File not found"}, 400
             else:
                 return {
                     "data": {
                         "file_id": result[1],
                         "file": b64encode(result[5]).decode(),
                         "comment": result[2],
                         "file_name": result[3],
                         "size": result[4],
                         "type": result[6],
                         "date_added": result[10]
                     },
                     "message": "File succesfully retrieved"
                 }
     except Exception as e:
         print(e)
         return {'message': 'Something went wrong'}, 500
コード例 #5
0
 def delete(self):
     emp_number = get_raw_jwt()['identity']
     parser = reqparse.RequestParser()
     parser.add_argument('file_id',
                         help='This field cannot be blank',
                         required=True)
     data = parser.parse_args()
     attachment = models.Attachment(emp_number, self.screen)
     try:
         if attachment.delete(data['file_id']) == 0:
             return {"message": "No file_id found"}, 400
         else:
             result = {
                 "data": {
                     "file_id": data['file_id']
                 },
                 "message": "File succesfully deleted"
             }
             return result
     except Exception as e:
         print(e)
         return {'message': 'Something went wrong'}, 500
コード例 #6
0
 def post(self):
     emp_number = get_raw_jwt()['identity']
     parser = reqparse.RequestParser()
     parser.add_argument('select_file',
                         help='This field cannot be blank',
                         required=True)
     parser.add_argument('file_name',
                         help='This field cannot be blank',
                         required=True)
     parser.add_argument('comment',
                         help='This field cannot be blank',
                         required=True)
     data = parser.parse_args()
     try:
         attachment = models.Attachment(emp_number, self.screen)
         return {
             "data": attachment.post(data),
             "message": "File succesfully created"
         }
     except Exception as e:
         print(e)
         return {'message': 'Something went wrong'}, 500