コード例 #1
0
ファイル: group.py プロジェクト: snir-sh/Grosharies
 def deleteUserFromGroup(self, group_id, user_name):
     if user_name:
         User.deleteUserFromGroup(group_id, user_name)
         lists = GroupLists.getAllLists(group_id)
         if lists:
             for list in lists:
                 List.deleteUserFromList(user_name, list)
コード例 #2
0
ファイル: test_board.py プロジェクト: GuangzheGao/sorbitol
    def test_add_and_get_lists(self):
        bid0 = Board.add("board0", "A")
        board0 = Board.get(bid0)
        bid1 = Board.add("board1", "A")

        lid0 = List.add("list0", bid0)
        lid1 = List.add("list1", bid1)
        assert lid0 in [_list.id for _list in board0.get_lists()]
        assert lid1 not in [_list.id for _list in board0.get_lists()]
コード例 #3
0
ファイル: group.py プロジェクト: snir-sh/Grosharies
 def deleteGroup(self, group_id):
     query = Group.query(Group.GroupID == group_id).get()
     if query:
         key = query.key.id()
         query.key.delete()
         User.deleteGroup(key)
         lists = GroupLists.getAllLists(key)
         if lists:
             for list in lists:
                 List.deleteList(list.ListID, key)
コード例 #4
0
ファイル: group.py プロジェクト: snir-sh/Grosharies
 def createList(self, list_name, list_admin, group_id):
     groupLists = GroupLists.getAllLists(group_id)
     if groupLists is None:
         List.createList(list_name, list_admin, group_id)
         return True
     else:
         for group in groupLists:
             if (group.GroupID == group_id):
                 return False
         List.createList(list_name, list_admin, group_id)
         return True
コード例 #5
0
ファイル: test_list.py プロジェクト: GuangzheGao/sorbitol
    def test_get_cards(self):
        bid0 = Board.add("board1", "A")
        lid0 = List.add("List0", bid0) 
        list0 = List.get(lid0)
        lid1 = List.add("List1", bid0) 
        list1 = List.get(lid1)

        uid0 = User.add("test1", "password", "*****@*****.**")
        
        caid0 = Card.add("card1", lid0, uid0)
        caid1 = Card.add("card2", lid1, uid0)

        assert caid0 in [card.id for card in list0.get_cards()]
        assert caid1 not in [card.id for card in list0.get_cards()]
コード例 #6
0
ファイル: test_card.py プロジェクト: GuangzheGao/sorbitol
 def test_get_user_ids(self):
     uid0 = User.add("test1", "password", "*****@*****.**")
     bid0 = Board.add("board1", "A")
     lid0 = List.add("To Do", bid0)
     card_id = Card.add("card0", lid0, uid0)
     card = Card.get(card_id)
     assert str(uid0) in [user_id for user_id in card.get_user_ids()]
コード例 #7
0
ファイル: handlers.py プロジェクト: ncss/projects-2016-1
def dashboard_handler(response):
    uid = util.get_current_user_id(response)
    user_mists = List.find_by_userid(uid)
    recent = sorted(user_mists, key = lambda list: list.id)
    recent.reverse()
    user_id = util.get_current_user_id(response)
    response.write(templater.render("templates/dashboard.html", mists=recent, page_title = "Dashboard", site_title = "M'lists", user_id=user_id, image_fetcher=IMDB.fetch_image))
コード例 #8
0
ファイル: views.py プロジェクト: GuangzheGao/sorbitol
def api_list(board_id = None):
    if request.method == 'GET':
        board_id = request.args.get('board_id')
        lists = List.get_all(board_id)
        if lists != None:
            return jsonify(json_list=[i.serialize() for i in lists])
        else:
            return jsonify({'code': 404, 'message': 'List ID not valid.'})
    else:
        try:
            board_id = long(request.form['board_id'])
            title = request.form['title']
        except KeyError:
            return jsonify({'code': 400, 'message': 'Bad Request'})
        else:
            return jsonify({"list_id": List.add(title, board_id)})
コード例 #9
0
ファイル: handlers.py プロジェクト: ncss/projects-2016-1
def edit_post_handler(response, list_id):
    # Put this early otherwise all the items are removed!
    if response.get_field("title", "") == "":
        response.redirect("/list/{}/edit?fail=list_title_empty".format(list_id))
        return

    a_list = List.find(list_id)

    user_id = util.get_current_user_id(response)
    if not a_list.author == user_id:
        raise Exception

    a_list.name = response.get_field("title", "")
    a_list.save()

    # delete the old list items before adding the new ones
    for old_item in ListContent.find_by_list_id(list_id):
        ListContent.delete(list_id, old_item.item_order)

    list_items = response.get_arguments("list_item")
    list_items = filter(None, list_items)
    for i, item in enumerate(list_items):
        list_content = ListContent.create(a_list.id, i, item)

    response.redirect('/dashboard')
コード例 #10
0
ファイル: test_card.py プロジェクト: GuangzheGao/sorbitol
 def test_get_cards_by_list_id(self):
     uid0 = User.add("test1", "password", "*****@*****.**")
     bid0 = Board.add("board1", "A")
     lid0 = List.add("To Do", bid0)
     card_id = Card.add("card0", lid0, uid0)
     card = Card.get(card_id)
     assert card_id in [card.id for card in Card.get_cards_by_list_id(lid0)]
コード例 #11
0
ファイル: handlers.py プロジェクト: ncss/projects-2016-1
def edit_handler(response, list_id):
    user_id = util.get_current_user_id(response)
    list = List.find(list_id)

    if not list.author == user_id:
        raise Exception

    response.write(templater.render("templates/edit.html", mist = list, page_title = "Edit", site_title = "M'lists", fail=response.get_field('fail', '')))
コード例 #12
0
ファイル: handlers.py プロジェクト: ncss/projects-2016-1
def view_handler(response, list_id):
    list = List.find(list_id)
    try:
        user_id = util.get_current_user_id(response)
    except Exception as e:
        user_id = None

    response.write(templater.render("templates/view_list.html", mist = list, page_title = list.name, site_title = "M'lists", user_id=user_id, image_fetcher=IMDB.fetch_image))
コード例 #13
0
ファイル: test_card.py プロジェクト: GuangzheGao/sorbitol
 def test_set_and_get_card(self):
     uid0 = User.add("test1", "password", "*****@*****.**")
     bid0 = Board.add("board1", "A")
     lid0 = List.add("To Do", bid0)
     card_id = Card.add("card0", lid0, uid0)
     card = Card.get(card_id)
     assert card.title == 'card0'
     assert card.list_id == lid0
コード例 #14
0
ファイル: test_card.py プロジェクト: GuangzheGao/sorbitol
 def test_get_and_test_description(self):
     uid0 = User.add("test1", "password", "*****@*****.**")
     bid0 = Board.add("board1", "A")
     lid0 = List.add("To Do", bid0)
     card_id = Card.add("card0", lid0, uid0)
     card = Card.get(card_id)
     card.set_description('desc')
     assert 'desc' in card.get_description()
コード例 #15
0
ファイル: productsList.py プロジェクト: snir-sh/Grosharies
    def get(self):
        template_params = {}
        user = None
        if self.request.cookies.get('session'):
            user = User.checkToken(self.request.cookies.get('session'))
        if not user:
            self.redirect('/')
            return
        #show the all the products of the list

        list_id = int(self.request.cookies.get('list_id_cookie'))
        if list_id:
            pid = self.request.get('pid')
            if pid:
                List.deleteProductFromList(list_id, int(pid))
                p_name = self.request.get('p_name')
                p_quantity = self.request.get('p_quantity')
                p_units = self.request.get('p_units')
                if p_name and p_quantity and p_units:
                    if Product.checkIfProductExists(p_name, list_id):
                        self.response.write(json.dumps({'status': 'exists'}))
                        return
                    Product.addProduct(p_name, p_quantity, p_units, list_id)
                    time.sleep(0.5)
            new_Product_name = self.request.get('new_Product_name')
            new_Product_quantity = self.request.get('new_Product_quantity')
            new_Product_units = self.request.get('new_Product_units')
            if new_Product_name and new_Product_quantity and new_Product_units:
                if Product.checkIfProductExists(new_Product_name, list_id):
                    self.response.write(json.dumps({'status': 'exists'}))
                    return
                Product.addProduct(new_Product_name, new_Product_quantity,
                                   new_Product_units, list_id)
                time.sleep(0.5)
            listProducts = List.getAllProductsOfTheList(list_id)
            list_name = List.getListByID(list_id).ListName
            user_permit = List.getUserPermit(list_id, user.email)
            data = []
            if list_name:
                data.append(list_name)
                data.append(listProducts)
                data.append(user_permit)
                self.response.write(json.dumps(data))
        else:
            self.response.write(json.dumps({'status': 'error'}))
コード例 #16
0
    def get(self):
        template_params = {}
        user = None
        if self.request.cookies.get('session'):
            user = User.checkToken(self.request.cookies.get('session'))
        if not user:
            self.redirect('/')
            return

        group_id = None
        gid = self.request.get('gid')
        if gid:
            group_id = int(gid)
            self.response.set_cookie('group_id_cookie', str(group_id))
        else:
            group_id = int(self.request.cookies.get('group_id_cookie'))

        #create new list
        new_list_name = self.request.get('new_list_name')
        if new_list_name:
            if List.checkIfTheNameExists(new_list_name, group_id):
                self.response.write(
                    json.dumps({
                        "status": "exist",
                        "name": new_list_name
                    }))
                return
            else:
                list_usersToAdd = json.loads(
                    self.request.get('list_usersToAdd'))
                newList = List.createList(new_list_name, user.email, group_id)
                if newList:
                    if list_usersToAdd:
                        for listUser in list_usersToAdd:
                            List.addUserToList(new_list_name, user.email,
                                               listUser[0], listUser[1],
                                               newList.ListID)
                time.sleep(0.3)
                allData = []
                listNames = List.getAllListsName(group_id)
                if listNames:
                    allData.append(listNames)
                    allData.append(newList.ListID)
                    self.response.write(json.dumps(allData))
コード例 #17
0
ファイル: productsList.py プロジェクト: snir-sh/Grosharies
    def get(self):
        if self.request.cookies.get('session'):
            user = User.checkToken(self.request.cookies.get('session'))
        if not user:
            self.redirect('/')
            return
        list_id = int(self.request.cookies.get('list_id_cookie'))
        group_id = int(self.request.cookies.get('group_id_cookie'))
        if list_id:
            users = List.getAllListUsersWithoutLogUser(list_id, user.email)
            list_name = List.getListNameByID(list_id)
            if users and list_name:
                List.deleteAllProducts(list_id)
                data = []
                data.append(users)
                data.append(list_name)
                self.response.write(json.dumps(data))

                return
コード例 #18
0
ファイル: test_comment.py プロジェクト: GuangzheGao/sorbitol
 def test_add_and_get(self):
     uid0 = User.add("test1", "password", "*****@*****.**")
     bid0 = Board.add("board1", "A")
     lid0 = List.add("To Do", bid0)
     caid0 = Card.add("card1", lid0, uid0)
     coid0 = Comment.add(caid0, uid0, "comment1")
     comment0 = Comment.get(coid0)
     assert caid0 == comment0.card_id
     assert uid0 == comment0.user_id
     assert "comment1" == comment0.content
コード例 #19
0
ファイル: views.py プロジェクト: shannon7777/flask-todolist
def homepage():
    # lists = List.select().order_by(List.id.asc())
    # todos = Todo.select().order_by(Todo.id.asc())
    # make into array then can loop through it and will be JSON serializeable
    all_lists = [l.list_name for l in List.select().order_by(List.id.asc())]
    all_todos = [t.content for t in Todo.select().order_by(Todo.id.asc())]

    result = jsonify({'all_lists': all_lists, 'all_todos': all_todos})

    return result
コード例 #20
0
ファイル: test_card.py プロジェクト: GuangzheGao/sorbitol
 def incr_decr_get_comment(self):
     uid0 = User.add("test1", "password", "*****@*****.**")
     bid0 = Board.add("board1", "A")
     lid0 = List.add("To Do", bid0)
     card_id = Card.add("card0", lid0, uid0)
     card = Card.get(card_id)
     Card.incr_comment(card_id)
     assert 1 == card.get_comment_count()
     Card.desc_comment(card_id)
     assert 0 == card.get_comment_count()
コード例 #21
0
ファイル: handlers.py プロジェクト: ncss/projects-2016-1
def feed_handler(response):
    mists = List.find_all()

    popular = sorted(mists, key = lambda list: list.get_likes())
    popular.reverse()

    recent = sorted(mists, key = lambda list: list.id)
    recent.reverse()

    user_id = util.get_current_user_id(response)
    response.write(templater.render("templates/feed.html", mists=recent, popular=popular, page_title = "Feed", site_title = "M'lists", user_id=user_id))
コード例 #22
0
ファイル: views.py プロジェクト: GuangzheGao/sorbitol
def api_get_card(card_id = None):
    if card_id == None:
        return jsonify({'code': 400, 'message': 'Bad Request'})
    else:
        card = Card.get(long(card_id))
        if card == None:
            return jsonify({'code': 404, 'message': 'Page Not Found'})
        _list = List.get(card.list_id)
        return render_template('card.html',
                                card=card,
                                list=_list,
                                edit_card_desc_form=EditCardDescForm(),
                                add_comment_form=AddCommentForm());
コード例 #23
0
ファイル: views.py プロジェクト: shannon7777/flask-todolist
def create_list():
    data = request.get_json()
    list_name = data['list_name']
    new_list = List(list_name=list_name)

    if new_list.save():
        flash(f'Successfully created a new list,{ list_name }!', 'success')
    else:
        flash('Did not create a new list', 'danger')

    result = jsonify({'list_name': list_name})

    return result
コード例 #24
0
ファイル: handlers.py プロジェクト: ncss/projects-2016-1
def delete_handler(response, list_id):
    a_list = List.find(list_id)

    user_id = util.get_current_user_id(response)
    if not a_list.author == user_id:
        raise Exception

    # delete the old list items before adding the new ones
    for old_item in ListContent.find_by_list_id(list_id):
        ListContent.delete(list_id, old_item.item_order)

    a_list.delete()
    response.redirect('/dashboard')
コード例 #25
0
ファイル: test_list.py プロジェクト: GuangzheGao/sorbitol
 def test_get_lists_by_board_id(self):
     bid0 = Board.add("board1", "A")
     bid1 = Board.add("board2", "A")
     lid0 = List.add("List0", bid0)
     list0 = List.get(lid0)
     lid1 = List.add("List1", bid1)
     list1 = List.get(lid1)
     assert lid0 in [_list.id for _list in List.get_lists_by_board_id(bid0)]
     assert lid1 not in [_list.id for _list in List.get_lists_by_board_id(bid0)]
コード例 #26
0
    def get(self):
        template_params = {}
        user = None
        if self.request.cookies.get('session'):
            user = User.checkToken(self.request.cookies.get('session'))
        if not user:
            self.redirect('/')
            return
        template_params['userEmail'] = user.email
        #get group_id from cookies
        group_id = int(self.request.cookies.get('group_id_cookie'))

        #get group names
        groupsNames = Group.getAllGroupsNames(user.email)
        if groupsNames:
            template_params['userGroups'] = groupsNames

        #show the all the products of the list
        list_id = int(self.request.get('lid'))
        if list_id:
            self.response.set_cookie('list_id_cookie', str(list_id))
            listProducts = List.getAllProductsOfTheList(list_id)
            template_params['listProducts'] = listProducts
            list = List.getListByID(list_id)
            list_name = list.ListName
            template_params['list_name'] = list_name
            if (list.ListAdmin == user.email):
                template_params['isListAdmin'] = user.email

        #get the lists names from the group
        groupsLists = List.getAllListsNameOfTheUser(group_id, user.email)
        if groupsLists:
            template_params['groupsLists'] = groupsLists

        html = template.render("web/templates/list.html", template_params)
        self.response.write(html)
コード例 #27
0
ファイル: test_user.py プロジェクト: GuangzheGao/sorbitol
    def test_add_and_get_cards(self):
        uid0 = User.add("test_user1", "password", "*****@*****.**")
        user0 = User.get(uid0)
        uid1 = User.add("test_user2", "password", "*****@*****.**")
        user1 = User.get(uid1)
        bid0 = Board.add("board1", "A")
        lid0 = List.add("List0", bid0)

        caid0 = Card.add("card1", lid0, uid0)
        caid1 = Card.add("card2", lid0, uid1)
        card0 = Card.get(caid0)


        print caid0, user0.get_card_ids()
        assert str(caid0) in user0.get_card_ids()
        assert str(caid1) not in user0.get_card_ids()
コード例 #28
0
ファイル: board.py プロジェクト: paylogic/trello_workon
    def __init__(self, board_id, trello_settings):
        self.board_id = board_id
        self.trello_settings = trello_settings

        try:
            self.name = requests.get(
                TRELLO_BOARD_REQUEST.format(
                    board_id=self.board_id,
                    app_id=self.trello_settings['app_id'],
                    token=self.trello_settings['token'],
                )).json()['name']
        except ValueError:
            raise TrelloTokenError

        self.load_list_names()
        self.doing = List(self, DOING_LIST_ID)
コード例 #29
0
ファイル: test_comment.py プロジェクト: GuangzheGao/sorbitol
    def test_get_comments_by_card_id(self):
        uid0 = User.add("test1", "password", "*****@*****.**")
        bid0 = Board.add("board1", "A")
        lid0 = List.add("To Do", bid0)

        caid0 = Card.add("card1", lid0, uid0)
        caid1 = Card.add("card2", lid0, uid0)

        coid0 = Comment.add(caid0, uid0, "comment1")
        coid1 = Comment.add(caid1, uid0, "comment2")

        comment0 = Comment.get(coid0)
        comment1 = Comment.get(coid1)

        assert coid0 in [comment.id for comment in Comment.get_comments_by_card_id(caid0)]
        assert coid1 not in [comment.id for comment in Comment.get_comments_by_card_id(caid0)]
コード例 #30
0
ファイル: views.py プロジェクト: GuangzheGao/sorbitol
def api_board(board_id=None):
    print "=======", request.form
    try:
        title = request.form['title']
    except:
        return jsonify({'code':400, 'message':'Invalid Request'})

    board_id = Board.add(title,'A')
    board = Board.get(board_id)
    board.add_user(current_user)
    current_user.add_board(board)
    List.add("To Do", board_id)
    List.add("Doing", board_id)
    List.add("Done", board_id)
    return jsonify({'board_id':board_id})
コード例 #31
0
 def post(self):
     #data = request.get_json()
     post_user = List().save()
     output = post_user
     return generate_json_response(result=output)
コード例 #32
0
 def get(self, list_id):
     output = List.objects(listId=list_id)
     return generate_json_response(result=output)
コード例 #33
0
ファイル: test_data.py プロジェクト: GuangzheGao/sorbitol
board0.add_user(user1)
board0.add_user(user2)

board1.add_user(user0)
board1.add_user(user1)

user0.add_board(board0)
user0.add_board(board1)
user1.add_board(board0)
user1.add_board(board1)
user2.add_board(board0)

user0.set_avatar('http://127.0.0.1:5000/_uploads/images/avatar_1.png')
user1.set_avatar('http://127.0.0.1:5000/_uploads/images/avatar_2.png')

lid0 = List.add("To Do", bid0)
lid1 = List.add("Doing", bid0)
lid2 = List.add("Done", bid0)

caid0 = Card.add("card1", lid0, uid0)
caid1 = Card.add("card2", lid0, uid0)
caid2 = Card.add("card3", lid1, uid0)

card0 = Card.get(caid0)
card0.add_user(user1)
card0.add_user(user2)

coid0 = Comment.add(caid0, uid0, "comment1")
coid1 = Comment.add(caid0, uid1, "comment2")
coid2 = Comment.add(caid0, uid2, "comment3")
コード例 #34
0
def add_new_list(client_list, user):
    list = List(client_list["name"], user.id, user.name, client_list.get("image"))
    db.get_session().add(list)
    db.get_session().commit()
    return list
コード例 #35
0
ファイル: listPage.py プロジェクト: snir-sh/Grosharies
    def get(self):
        template_params = {}
        user = None
        if self.request.cookies.get('session'):
            user = User.checkToken(self.request.cookies.get('session'))
        if not user:
            self.redirect('/')
            return
        group = None

        template_params['userEmail'] = user.email
        group_id = None
        gid = self.request.get('gid')
        if gid:
            group_id = int(gid)
            self.response.set_cookie('group_id_cookie', str(group_id))
        else:
            group_id = int(self.request.cookies.get('group_id_cookie'))

        listNames = List.getAllListsNameOfTheUser(group_id, user.email)
        if listNames:
            template_params['groupLists'] = listNames

        group = Group.getGroupNameByID(group_id)
        if group:
            template_params['groupName'] = group.GroupName
            template_params['groupAdmin'] = group.GroupAdmin
            if (group.GroupAdmin == user.email):
                template_params['isAdmin'] = user.email
            else:
                template_params['isNotAdmin'] = user.email

        # Retrieving all the users of a group without the admin
        group = Group.getGroupNameByID(group_id)
        users = None
        if group:
            users = Group.getAllUsersFromGroupByIDWithoutListAdmin(
                group_id, group.GroupAdmin)
        groupMembers = []
        if users:
            for gUser in users:
                groupMembers.append(gUser)
            template_params['groupUsers'] = groupMembers

        # Retrieving all the groups names for showing on left side.
        groupsNames = Group.getAllGroupsNames(user.email)
        if groupsNames:
            template_params['userGroups'] = groupsNames
        template_params['group_id'] = group_id

        #delete user from a group
        deleteUser = self.request.get('deleteUser')
        if deleteUser:
            Group.deleteUserFromGroup(group_id, str(deleteUser))
            time.sleep(0.5)
            # Retrieving all the users of a group without the admin
            group = Group.getGroupNameByID(group_id)
            if group:
                users = Group.getAllUsersFromGroupByIDWithoutListAdmin(
                    group_id, group.GroupAdmin)
                groupMembers = []
                if users:
                    for gUser in users:
                        groupMembers.append(gUser)
                    self.response.write(json.dumps(groupMembers))
                    return

        # changing a group name
        newGroupName = self.request.get('newGroupName')
        if newGroupName:
            Group.changeGroupName(group_id, newGroupName)

        # check if asked to delete group
        confirmDeletion = self.request.get('confirmDeletion')
        if confirmDeletion:
            Group.deleteGroup(group_id)
            self.response.delete_cookie('group_id')
            time.sleep(0.3)
            self.response.write('statusDeleted')

        html = template.render("web/templates/listPage.html", template_params)
        self.response.write(html)
コード例 #36
0
ファイル: test_list.py プロジェクト: GuangzheGao/sorbitol
 def test_set_and_get_list(self):
     bid0 = Board.add("board1", "A")
     lid0 = List.add("List0", bid0)
     list0 = List.get(lid0)
     assert list0.title == "List0", True
     assert list0.board_id == lid0
コード例 #37
0
ファイル: group.py プロジェクト: snir-sh/Grosharies
 def deleteList(self, list_id, group_id):
     if (List.checkExistenceByID(list_id) is not None):
         List.deleteList(list_id, group_id)
         return True
     return False
コード例 #38
0
 def post(self, list_id):
     output = {'listId': List.objects(listId=list_id).delete()}
     return generate_json_response(result=output)
コード例 #39
0
ファイル: listDetails.py プロジェクト: snir-sh/Grosharies
    def get(self):
        template_params = {}
        user = None
        if self.request.cookies.get('session'):
            user = User.checkToken(self.request.cookies.get('session'))
        if not user:
            self.redirect('/')
            return
        group = None

        template_params['userEmail'] = user.email
        group_id = None
        group_id = int(self.request.cookies.get('group_id_cookie'))

        groupsLists = List.getAllListsNameOfTheUser(group_id, user.email)
        if groupsLists:
            template_params['groupLists'] = groupsLists

        list_id = int(self.request.cookies.get('list_id_cookie'))
        if list_id:
            list = List.getListByID(list_id)
            if list:
                users = List.getAllListUsersByID(list_id)
                template_params['listUsers'] = users
                template_params['listName'] = list.ListName
                template_params['listAdmin'] = list.ListAdmin
                if (list.ListAdmin == user.email):
                    template_params['isListAdmin'] = user.email
                else:
                    template_params['isNotListAdmin'] = user.email

        # Retrieving all the groups names for showing on left side.
        groupsNames = Group.getAllGroupsNames(user.email)
        if groupsNames:
            template_params['userGroups'] = groupsNames
        template_params['group_id'] = group_id

        #delete user from a list
        deleteUser = self.request.get('deleteUser')
        if deleteUser:
            List.deleteUserFromList(deleteUser, list_id)

        #add user to a list
        addUser = self.request.get('addUser')
        permit = self.request.get('permit')
        if addUser:
            userToAdd = List.checkIfUserInList(addUser)
            if userToAdd == True:
                self.response.write('userExist')
                return
            else:
                #need to implement
                self.response.write('userNotExist')

        # changing a list name
        newListName = self.request.get('newListName')
        if newListName:
            List.changeListName(list_id, newListName)

        # check if asked to delete group
        confirmDeletion = self.request.get('confirmDeletion')
        if confirmDeletion:
            List.deleteList(list_id, group_id)
            self.response.delete_cookie('list_id')
            time.sleep(0.3)
            self.response.write('statusDeleted')

        html = template.render("web/templates/listDetails.html",
                               template_params)
        self.response.write(html)
コード例 #40
0
ファイル: board.py プロジェクト: GuangzheGao/sorbitol
 def get_lists(self):
     '''return a list of user objs'''
     return List.get_lists_by_board_id(self.id)
コード例 #41
0
    def get(self):
        template_params = {}
        user = None
        if self.request.cookies.get('session'):
            user = User.checkToken(self.request.cookies.get('session'))
        if not user:
            self.redirect('/')
            return

        group_id = None
        gid = self.request.get('gid')
        if gid:
            group_id = int(gid)
        else:
            group_id = int(self.request.cookies.get('group_id_cookie'))

        #Fill User Input
        fill = self.request.get('fillUsers')
        if fill:
            users = Group.getAllUsersFromGroupByID(group_id)
            self.response.write(json.dumps(users))

        # changing a list name
        list_id = int(self.request.cookies.get('list_id_cookie'))
        if list_id:
            newListName = self.request.get('newListName')
            if newListName:
                if List.checkIfTheNameExists(newListName, group_id):
                    self.response.write(
                        json.dumps({
                            "status": "exist",
                            "name": newListName
                        }))
                    return
                data = []
                List.changeListName(list_id, newListName)
                listNames = List.getAllListsName(group_id)
                data.append(listNames)
                data.append(newListName)
                self.response.write(json.dumps(data))
                return

        #delete user from a list
        removeUser = self.request.get('removeUser')
        if removeUser:
            List.deleteUserFromList(removeUser, list_id)
            time.sleep(0.3)
            users = List.getAllListUsersByID(list_id)
            if users:
                self.response.write(json.dumps(users))
            else:
                self.response.write(json.dumps({"status": "empty"}))
            return

        #add user to a list
        addUser = self.request.get('addUser')
        permit = self.request.get('permit')
        if addUser:
            userToAdd = List.checkIfUserInList(list_id, addUser)
            if userToAdd == True:
                self.response.write(
                    json.dumps({
                        "status": "exist",
                        "name": addUser
                    }))
                return
            checkIfUser = User.checkIfUserExists(addUser)
            if checkIfUser:
                list = List.getListByID(list_id)
                list_name = list.ListName
                List.addUserToList(list_name, user.email, addUser, permit,
                                   list_id)
                time.sleep(0.3)
                users = List.getAllListUsersByID(list_id)
                self.response.write(json.dumps(users))
                return
            else:
                self.response.write(
                    json.dumps({
                        "status": "notUser",
                        "name": addUser
                    }))
                return

        # leaving a list
        leaveList = self.request.get('leaveList')
        if leaveList:
            List.deleteUserFromList(user.email, list_id)
            self.response.write(json.dumps({"status": "ok"}))
            time.sleep(0.3)
コード例 #42
0
def listRequests():
    list_id = request.args.get('list_id', None)
    user_id = request.args.get('user_id', None)
    auth_token = token_getter()

    if request.method == 'GET':
        # checks to see if the client is logged-in, by seeing if an auth_token exists, if not then `auth_token = -1`
        if type(auth_token) is not int:
            auth_token = -1

        # 1|0| Case 1: Where only the list_id is provided
        if list_id:
            try:
                get_list = List.query.filter_by(id=list_id).first()
                list_privacy = get_list.private
                list_user_id = get_list.user_id
                if list_privacy == False or int(list_user_id) == int(auth_token):
                    return jsonify(get_list.serialize)
                else:
                    return jsonify({"error": "list is set to private"}), 403
            except Exception as e:
                return jsonify({'error': "{}".format(e.__cause__)}), 400

        # 0|1 Case 2: when only user_id is provided
        if user_id:
            try:
                if int(user_id) == int(auth_token):
                    lists = List.query.filter_by(user_id=user_id)
                    return jsonify([list.serialize for list in lists]), 200
                else:
                    lists = List.query.filter_by(
                        user_id=user_id, private=False)
                    return jsonify([list.serialize for list in lists]), 200
            except Exception as e:
                return jsonify({'error': "{}".format(e.__cause__)}), 400

        # 0|0 Case 3: when none is provided, we look at the auth_token and retrieve the lists
        if auth_token != -1:
            try:
                lists = List.query.filter_by(user_id=auth_token)
                return jsonify([list.serialize for list in lists]), 200
            except Exception as e:
                return jsonify({'error': "{}".format(e.__cause__)}), 400

    if request.method == 'POST':
        # client must be logged-in in order to create a list, client is only restricted to create list for their own account
        if type(auth_token) is not int:
            return jsonify({'error': "you must log in to create a list"}), 400

        else:
            body = json.loads(request.get_data())
            list_user_id = int(auth_token)
            list_name = body['name']

            # checks to see if list already exists
            if not List.query.filter_by(user_id=list_user_id, name=list_name).first():
                # checks to see if cloudinary works
                new_img_url = replace_cloudinary_image(body['img_url'])
                try:
                    list = List(list_user_id, list_name, new_img_url)
                    db.session.add(list)
                    db.session.commit()
                except Exception as e:
                    return jsonify({'error': "{}".format(e.__cause__)}), 400
                return jsonify({'response': 'list successfully added'}), 200
            else:
                return jsonify({'error': 'list already exists'}), 400

    if request.method == 'PUT':
        # client must be logged-in in order to edit a list, client is only restricted to editting their own lists
        if type(auth_token) is not int:
            return jsonify({'error': "you must log in to edit the list"}), 400

        else:
            list = List.query.get(int(list_id))
            if list.user_id == int(auth_token):
                try:
                    req = request.get_json()
                    list.name = req.get("name", list.name)
                    list.private = req.get("private", list.private)
                    if "img_url" in req:
                        list.img_url = replace_cloudinary_image(req["img_url"])
                    db.session.commit()
                    return jsonify({"response": "List '{}' was updated".format(list_id)}), 200

                except Exception as e:
                    return jsonify({'error': "{}".format(e.__cause__)}), 400
            else:
                return jsonify({'error': "unauthorized access"}), 401

    if request.method == 'DELETE':
        # client must be logged-in in order to delete a list, client is only restricted to deleting their own lists
        if type(auth_token) is not int:
            return jsonify({'error': "you must logged-in, to delete the list"}), 400

        else:
            list = List.query.get(int(list_id))
            if list.user_id == int(auth_token):
                try:
                    list_to_product = ListToProduct.query.filter_by(
                        list_id=int(list_id)).delete()
                    db.session.delete(list)
                    db.session.commit()
                    return jsonify({'response': "List '{}' was successfully deleted from the database".format(list)}), 200

                except Exception as e:
                    return jsonify({'error': "{}".format(e.__cause__)}), 400
            else:
                return jsonify({'error': "unauthorized access"}), 401