Пример #1
0
def index():

    jwt_user = get_jwt_identity()
    user = User.get_or_none(User.name == jwt_user)

    if not user:
        return error_401("Unauthorized action")

    user_bookmarks = Lesson.select().join(
        Bookmark,
        on=(Bookmark.lesson == Lesson.id)).where(Bookmark.owner == user.id)

    data = [{
        'id': lesson.id,
        'title': lesson.title,
        'description': lesson.description,
        'rating': lesson.rating,
        'teach': lesson.teach,
        'owner_id': lesson.owner_id,
        'owner_name': lesson.owner.name,
        'skill_id': lesson.skill_id,
        'skill_name': lesson.skill.name,
        'image_url': lesson.image_url
    } for lesson in user_bookmarks]

    return success_201("Returned list of the current user's bookmarks", data)
Пример #2
0
def index_with_filter():
    # Retrieve arguments
    teach = request.args.get('teach')
    if (teach == "true"):
        teach_option = True
    elif (teach == "false"):
        teach_option = False
    else:
        return error_401("Invalid teach input")

    # Retrieve lessons from database
    lessons = [ 
        {
            'id': lesson.id,
            'title': lesson.title,
            'description': lesson.description,
            'rating': lesson.rating,
            'owner_id': lesson.owner_id,
            'owner_name': lesson.owner.name,
            'teach': lesson.teach,
            'skill_id': lesson.skill_id,
            'skill_name': lesson.skill.name,
            'image_url': lesson.image_url
        } for lesson in Lesson.select().where(Lesson.teach == teach_option)
    ]
    return success_200(lessons)
Пример #3
0
def index():
    # Retrieve lessons from database
    lessons = [ 
        {
            'id': lesson.id,
            'title': lesson.title,
            'description': lesson.description,
            'rating': lesson.rating,
            'owner_id': lesson.owner_id,
            'owner_name': lesson.owner.name,
            'teach': lesson.teach,
            'skill_id': lesson.skill_id,
            'skill_name': lesson.skill.name,
            'image_url': lesson.image_url
        } for lesson in Lesson.select()
    ]
    return success_200(lessons)
Пример #4
0
def search_lessons():

    search_value = request.args['search_value']

    teach_arg = request.args['teach']
    if str(teach_arg) == 'true':
        teach=True
    else:
        teach=False

    list_of_skills = []
    final_lessons_list = []
    
    split_search_value = search_value.lower().split(" ") #This is a list []

    for word in split_search_value: #loop through the split search string
        for lesson in Lesson.select().where(Lesson.teach == teach): #loop through all rows in Lesson
            if (word in lesson.title.lower()) or (word in lesson.skill.name.lower()) or (word in lesson.description.lower()): #if a word from the split search string is part of the lesson title, append it to a list
                final_lessons_list.append(lesson)

                    
    if len(final_lessons_list) > 0:
        
        data = [
            {
            'id': lesson.id,
            'title': lesson.title,
            'description': lesson.description,
            'rating': lesson.rating,
            'teach': lesson.teach,
            'owner_id': lesson.owner_id,
            'owner_name': lesson.owner.name,
            'skill_id': lesson.skill_id,
            'skill_name': lesson.skill.name,
            'image_url': lesson.image_url
            } for lesson in final_lessons_list
        ]

        return success_201('success testing', data)
    else:
        return success_201('No lessons matched the search query', [])