예제 #1
0
def test_show_action():
    other_user = User.get_or_insert_by_username(username='******', password='******', email='*****@*****.**', lastname='Marcora', forename='Edoardo')
    other_folder = Folder.get_or_insert_by_user_and_title(other_user, 'Foo')
    res = app.get('/folders/3', status=404) # no folder
    res = app.get('/folders/2', status=404) # other folder
    res = app.get('/folders/1')
    assert res.json == folder_hash
예제 #2
0
def duplicated(path):
    qry = Folder.query(Folder.path == path)
    result = qry.fetch()
    if len(result) > 0:
        return True
    else:
        return False
예제 #3
0
    def post(self):
        email = self.request.get("userEmail")
        upass = self.request.get("userPassword")
        upass_c = self.request.get("confirmPassword")

        if upass != upass_c:
            template_values = {
                'title': 'DropBox Application | Sign Up',
                'errmsg': 'Password dismatch',
                'email': email,
            }
            # self.redirect('/signup')
            path = os.path.join(os.path.dirname(__file__),
                                "templates/signup.html")
            self.response.write(template.render(path, template_values))
        else:
            if self.checkUser(email) > 0:
                template_values = {
                    'title': 'DropBox Application | Sign Up',
                    'errmsg': 'User duplicated',
                    'email': email,
                }
                # self.redirect('/signup')
                path = os.path.join(os.path.dirname(__file__),
                                    "templates/signup.html")
                self.response.write(template.render(path, template_values))
            else:
                user = User()
                user.password = upass
                user.email = email

                user_key = user.put()

                # Put session variable user as user's key
                self.session['root'] = str(user_key.id())

        folder = Folder()

        folder.user_id = str(user_key.id())
        folder.path = str(user_key.id())
        folder_key = folder.put()

        # Redirect to home
        self.redirect('/')
예제 #4
0
def create_folder(path, userkey):
    folder = Folder()
    folder.user_id = userkey
    folder.path = path
    now = datetime.now()
    folder.cdate = now.strftime("%m/%d/%Y %H:%M:%S")
    folder.size = ""
    folder_key = folder.put()
예제 #5
0
 def folders(self):
   from models.folder import Folder
   folders = Folder.get(self.folder_list)
   if None in folders:
       compact = []
       for folder in folders:
           if folder is not None:
               compact.append(folder)
       folders = compact
       self.folder_list = [folder.key() for folder in folders]
       self.put()
   return folders
예제 #6
0
    def load(memory: RuntimeMemory = RuntimeMemory()) -> FileSystem:
        fs: FileSystem
        try:
            with open('fs.dat', 'rb') as f:
                fs = pickle.load(f)
        except IOError:
            print('WARN: fs.dat not found')
            fs = FileSystem(Folder('root', None))
            fs.save()

        MemoryService.init(memory)
        return fs
예제 #7
0
def listFolders(path, userkey):
    folders = []
    if (path != userkey):  # if root
        folders.append({'name': '..', 'cdate': ''})

    # Get list of folders from datastore
    qry = Folder.query(Folder.user_id == userkey)
    results = qry.fetch()
    for result in results:
        rpath = result.path
        start = rpath.find(path)
        if start != -1:
            sub = rpath[start + len(path) + 1:]
            if sub != '':
                if sub.find('/') == -1:
                    folders.append({'name': sub, 'cdate': result.cdate})

    return folders
예제 #8
0
    def get(self):
        root = self.session.get('root')
        path = self.request.get('path')

        full_path = root + '/' + path

        # Delete folder from datastore. Query condition means it contain sub directory.
        qry = Folder.query(Folder.path >= full_path)
        results = qry.fetch()

        # Query result is not correct, because of condition for querying. So fix them.
        for result in results:
            result_path = result.path
            if result_path.find(path) is not -1:
                result.key.delete()

        # After deleting, make directory for redirecting.
        if path.find('/') is not -1:
            red_path = path[:path.rindex('/')]
        else:
            red_path = ''

        self.redirect('/?path=' + red_path)
def setup():
    user = User.get_by_username('marcora')
    folder = Folder.get_or_insert_by_user_and_title(user, 'Foo')
    res = app.post('/login', {'username':'******', 'password':'******'})
예제 #10
0
 def Folder(self):
     return Folder(self)
예제 #11
0
from models.folder import Folder
from models.user import User
# from data.user_data import list_users

from models.user import User

list_users = [
    User(username='******', password='******', email='*****@*****.**'),
    User(username='******', password='******', email='*****@*****.**'),
    User(username='******', password='******', email='*****@*****.**'),
    User(username='******', password='******', email='*****@*****.**')
]

list_folders = [
    Folder(name="SEI 53", users=list_users),
    Folder(name="News articles", users=list_users),
    Folder(name="Long reads", users=list_users)
]
예제 #12
0
 def create_directory(self, path: str) -> None:
     log.debug(f'create_directory: path = {path}')
     name = path.rsplit('/', maxsplit=1)[-1]
     parent = self._get_parent(path)
     parent.nodes[name] = Folder(name, parent)
     self.save()