Example #1
0
def delete(user_id):
    """
    Treats the POST request to delete a user.
    """
    user = User.get(User, user_id)
    user.delete()
    return redirect('/blogly/list')
Example #2
0
def main_home():
    """
    Render the User List template for both '/' and '/list' paths.
    """

    users = User.all(User)
    return render_template('user_list.html',
                           page_title=g.USERS.LIST_PG,
                           users=users)
Example #3
0
def save(user_id):
    """
    Treats the POST request to update a user.
    """
    dict_form = dict(request.form)
    dict_form['id'] = user_id
    user = User.get(User, user_id)
    user.update(dict_form)
    return redirect(f'{g.USERS.PATH}/{user_id}')
Example #4
0
def new():
    """
    Treats the POST request to add the a new post.

    'From' Context
    --------------
        Add User Form -> Save

    """
    dict_form = dict(request.form)
    user_id = User.add(User, dict_form)
    return redirect(f'{g.USERS.PATH}/{user_id}')
Example #5
0
def details(user_id):
    """
    Renders the form that shows the user details.

    'From' Contexts
    ---------------
        Users -> <Name on the List>
        User Add Form -> Save or Cancel
        User Edit Form -> Save or Cancel
    """
    user = User.get(User, user_id)
    return render_template('user_view.html',
                           page_title=g.USERS.VIEW_PG,
                           user=user,
                           posts=user.posts)
Example #6
0
def edit_form(user_id):
    """Renders Edit User form. Sends some special variables to the front-end:

    - method: the method to be sent by the form on click on the 'Save' button.
    - crud: the operation to configure the form.

    'From' Contexts
    ---------------
        User View -> Edit
    """
    user = User.get(User, user_id)
    return render_template('user_form.html',
                           method='POST',
                           crud='update',
                           page_title=g.USERS.EDIT_PG,
                           user=user)
Example #7
0
def add_form():
    """
    Renders the Add User form. Sends some special variables to the front-end:
    - method: the method to be sent by the form on click on the 'Save' button.
    - crud: the operation to configure the form.

    'From' Context
    --------------
        Users -> Add User

    """
    user = User({})
    return render_template('user_form.html',
                           method='POST',
                           crud='create',
                           page_title=g.USERS.ADD_PG,
                           user=user)
Example #8
0
def create_form_view(user_id):
    """
    Renders the Add Post form. Sends some special variables to the front-end:

    - method: the method to be sent by the form on click on the 'Save' button.
    - crud: the operation to configure the form.

    """
    post = Post({})
    post.user_id = user_id
    user = User.get(User, user_id)
    tags = Tag.all(Tag)
    return render_template(
        'post_form.html',
        method='POST',
        crud='create',
        page_title=f'{g.POSTS.ADD_PG} for {user.full_name()}',
        post=post,
        all_tags=tags)
Example #9
0
    def insert_data():
        from blogly.users.user_model import User

        budda = User({
            'first_name': 'Siddhārtha',
            'last_name': 'Gautama',
            'image_url': None
        })
        jesus = User({'first_name': 'Jesus', 'last_name': 'Christ'})
        krishna = User({
            'first_name': 'Krishna',
            'last_name': 'Vasudeva',
            'image_url': None
        })
        lahiru = User({
            'first_name':
            'Lahiru',
            'last_name':
            'Gamathige',
            'image_url':
            'https://res-4.cloudinary.com/crunchbase-production/image/upload/c_lpad,h_256,w_256,f_auto,q_auto:eco/v1446050463/wle8mms7cc0leozu27fy.jpg'
        })

        db.session.add_all([budda, jesus, krishna, lahiru])
        db.session.commit()

        from blogly.posts.post_model import Post

        post_2_1 = Post({
            'title': 'הדיבר העשירי',
            'content': 'עכשיו אני אומר לך לאהוב אחד את השני, כמו שאהבתי ',
            'user_id': 2
        })
        post_3_1 = Post({
            'title': 'विश्वासों',
            'content':
            'एक आदमी अपनी मान्यताओं से बनता है। जैसा वह मानता है। तो वह बन जाता है।',
            'user_id': 3
        })
        post_4_1 = Post({
            'title': 'මැක්සිමා ප්‍ර is ාව',
            'content': 'මම යමක් කියන්නම් නමුත් ඔබට එය තේරෙන්නේ නැත.',
            'user_id': 4
        })

        post_4_2 = Post({
            'title': 'For My Students',
            'content': 'I wish my hair was growing as much as your knowledge.',
            'user_id': 4
        })

        db.session.add_all([post_2_1, post_3_1, post_4_1, post_4_2])
        db.session.commit()

        from blogly.tags.tag_model import Tag

        tag1 = Tag({'name': 'Religion'})
        tag2 = Tag({'name': 'Art'})
        tag3 = Tag({'name': 'Kitties'})

        db.session.add_all([tag1, tag2, tag3])
        db.session.commit()

        from blogly.tags.tag_post_model import TagPost

        tag_post_1_1 = TagPost({'post_id': 1, 'tag_id': 1})
        # tag_post_1_2 = TagPost({'post_id': 1, 'tag_id': 2})
        tag_post_1_3 = TagPost({'post_id': 1, 'tag_id': 3})

        db.session.add_all([tag_post_1_1, tag_post_1_3])
        db.session.commit()