Пример #1
0
 def delete_files_for_user(cls, user):
     mongodbmanager.connect()
     files = cls.find_files_for_user(user)
     if files is not None:
         count = files.count()
         files.delete()
         return count
Пример #2
0
 def create_file(cls, name, hash, user):
     mongodbmanager.connect()
     file = cls.find_file_by_hash_and_sessionid(hash, user.session_id)
     if file is None:
         # Create new file
         newFile = File(name = name, hash = hash, session_id = user.session_id)
         newFile.save()
     else:
         # Update file name
         cls.update_file(file, name)
Пример #3
0
    def find_files_by_query(cls, query):
        mongodbmanager.connect()
        files =  File.objects(name__icontains = query)

        #do manual distinct
        returning_files = []
        returning_files_hashes = []
        for f in files:
            if f.hash not in returning_files_hashes:
                returning_files.append(f)
                returning_files_hashes.append(f.hash)

        return returning_files
Пример #4
0
 def delete_user(cls, user):
     mongodbmanager.connect()
     user.delete()
Пример #5
0
    def create_user(cls, ip, port):
        mongodbmanager.connect()

        new_user = User(ip=str(ip), port=port, session_id=hashing.generate_session_id())
        new_user.save()
        return new_user
Пример #6
0
 def find_user_by_ip_and_port(cls, ip, port):
     mongodbmanager.connect()
     return User.objects(ip = ip, port = port).first()
Пример #7
0
 def find_user_by_ip(cls, ip):
     mongodbmanager.connect()
     return User.objects(ip = ip).first()
Пример #8
0
 def delete_file(cls, file):
     mongodbmanager.connect()
     file.delete()
Пример #9
0
 def update_file(cls, file, new_name):
     mongodbmanager.connect()
     file.name = new_name
     file.save()
Пример #10
0
 def find_files_for_user(cls, user):
     mongodbmanager.connect()
     return File.objects(session_id = user.session_id)
Пример #11
0
 def count_files_by_hash(cls, hash):
     mongodbmanager.connect()
     return File.objects(hash = hash).count()
Пример #12
0
 def find_files_by_hash(cls, hash):
     mongodbmanager.connect()
     return File.objects(hash = hash).all()
Пример #13
0
 def find_file_by_hash_and_sessionid(cls, hash, session_id):
     mongodbmanager.connect()
     return File.objects(hash = hash, session_id = session_id).first()
Пример #14
0
 def increase_download_count_for_file(cls, file):
     mongodbmanager.connect()
     file.download_count += 1
     file.save()
Пример #15
0
 def delete_all(cls):
     mongodbmanager.connect()
     User.drop_collection()
Пример #16
0
 def find_user_by_session_id(cls, session_id):
     mongodbmanager.connect()
     return User.objects(session_id=session_id).first()
Пример #17
0
 def find_file(cls, name, hash, user):
     mongodbmanager.connect()
     return  File.objects(name = name, hash = hash, session_id = user.session_id).first()