Beispiel #1
0
def contracts_show_contract(contract_name):
    """
    Shows a summary of the contract requirements.
    If the user has not signed a contract it also
    displays a signup button
    """

    can_edit = None
    query = UserRoleModel.all()
    query.filter('user ='******'webmaster':
            can_edit = True
            break

    query = models.SignedContractModel.all()
    query.filter('user ='******'name =', urllib.unquote_plus(contract_name))

    try:
        contract = query.fetch(1)[0]
    except IndexError:
        return render_template('404.html'), 404

    contract.url_name = contract_name
        
    query = models.TimeReqModel.all()
    query.filter('contract_ =', contract.key())

    time_reqs = query.fetch(query.count())

    for time_req in time_reqs:
        time_req.str_time = str(time_req.time)
        time_req.str_date = str(time_req.dueDate)
        time_req.url_name = urllib.quote_plus(time_req.name)

    query = models.DuesReqModel.all()
    query.filter('contract_ =', contract.key())

    dues_reqs = query.fetch(query.count())

    for dues_req in dues_reqs:
        dues_req.str_date = str(dues_req.dueDate)
        dues_req.url_name = urllib.quote_plus(dues_req.name)

    return render_template('contracts/show.html',
                           can_edit=can_edit,
                           can_sign=can_sign,
                           contract=contract,
                           time_reqs=time_reqs,
                           dues_reqs=dues_reqs)
def contracts_show_contract(contract_name):
    """
    Shows a summary of the contract requirements.
    If the user has not signed a contract it also
    displays a signup button
    """

    can_edit = None
    query = UserRoleModel.all()
    query.filter('user ='******'webmaster':
            can_edit = True
            break

    query = models.SignedContractModel.all()
    query.filter('user ='******'name =', urllib.unquote_plus(contract_name))

    try:
        contract = query.fetch(1)[0]
    except IndexError:
        return render_template('404.html'), 404

    contract.url_name = contract_name

    query = models.TimeReqModel.all()
    query.filter('contract_ =', contract.key())

    time_reqs = query.fetch(query.count())

    for time_req in time_reqs:
        time_req.str_time = str(time_req.time)
        time_req.str_date = str(time_req.dueDate)
        time_req.url_name = urllib.quote_plus(time_req.name)

    query = models.DuesReqModel.all()
    query.filter('contract_ =', contract.key())

    dues_reqs = query.fetch(query.count())

    for dues_req in dues_reqs:
        dues_req.str_date = str(dues_req.dueDate)
        dues_req.url_name = urllib.quote_plus(dues_req.name)

    return render_template('contracts/show.html',
                           can_edit=can_edit,
                           can_sign=can_sign,
                           contract=contract,
                           time_reqs=time_reqs,
                           dues_reqs=dues_reqs)
Beispiel #3
0
def display_blog():
    """
    View to display existing blog posts
    """
    new_post = None
    if current_user.is_authenticated():
        query = UserRoleModel.all()
        query.filter('user ='******'webmaster':
                new_post = forms.NewPostForm()
                break


    query = models.PostModel.all()
    query.order('-timestamp')

    posts = query.fetch(10)

    for post in posts:
        post.url_timestamp = urllib.quote_plus(str(post.timestamp))
        post.url_title = urllib.quote_plus(post.title)

    post_form = forms.NewPostForm()

    if request.method == 'POST' and post_form.validate():
        post = models.PostModel(title=post_form.title.data,
                                timestamp=dt.datetime.now(),
                                text=post_form.text.data,
                                author=current_user.key())
        post.put()

        post.url_timestamp = urllib.quote_plus(str(post.timestamp))
        post.url_title = urllib.quote_plus(post.title)
        
        posts.insert(0, post)
        if len(posts) > 10:
            del posts[-1]

        post_form = forms.NewPostForm(None)

    post_form = forms.NewPostForm(None)
        
        
    return render_template('blogs/display_posts.html',
                           new_post=new_post,
                           posts=posts)
def display_blog():
    """
    View to display existing blog posts
    """
    new_post = None
    if current_user.is_authenticated():
        query = UserRoleModel.all()
        query.filter('user ='******'webmaster':
                new_post = forms.NewPostForm()
                break

    query = models.PostModel.all()
    query.order('-timestamp')

    posts = query.fetch(10)

    for post in posts:
        post.url_timestamp = urllib.quote_plus(str(post.timestamp))
        post.url_title = urllib.quote_plus(post.title)

    post_form = forms.NewPostForm()

    if request.method == 'POST' and post_form.validate():
        post = models.PostModel(title=post_form.title.data,
                                timestamp=dt.datetime.now(),
                                text=post_form.text.data,
                                author=current_user.key())
        post.put()

        post.url_timestamp = urllib.quote_plus(str(post.timestamp))
        post.url_title = urllib.quote_plus(post.title)

        posts.insert(0, post)
        if len(posts) > 10:
            del posts[-1]

        post_form = forms.NewPostForm(None)

    post_form = forms.NewPostForm(None)

    return render_template('blogs/display_posts.html',
                           new_post=new_post,
                           posts=posts)
Beispiel #5
0
def contracts_sign(contract_name):
    """
    Allows a user that has not already signed a contract
    to sign a contract
    """

    query = models.SignedContractModel.all()
    query.filter('user ='******'You cannot sign more than one contract', 'error')
        return redirect(url_for('contracts_list_contracts'))

    query = models.ContractModel.all()
    query.filter('name =', urllib.unquote_plus(contract_name))

    try:
        contract = query.fetch(1)[0]
    except:
        return render_template('404.html'), 404

    signed = models.SignedContractModel(user=current_user.key(),
                                        contract_ = contract.key())

    signed.put()

    # create the empty progress models for each requirement on this contract
    query = models.TimeReqModel.all()
    query.filter('contract_ =', contract)

    time_reqs = query.fetch(query.count())
    for time_req in time_reqs:
        time_req_prog = models.TimeReqProgressModel(user=current_user.key(),
                                                    req=time_req)
        time_req_prog.put()

    query = models.DuesReqModel.all()
    query.filter('contract_ =', contract)
        
    dues_reqs = query.fetch(query.count())
    for dues_req in dues_reqs:
        dues_req_prog = models.DuesReqProgressModel(user=current_user.key(),
                                                    req=dues_req)
        dues_req_prog.put()

    flash('You have successfully signed a contract', 'success')
    return redirect(url_for('contracts_progress'))
def check_permissions(cwruid):
    """
    Returns a permissions tuple.

    The first element in the tuple is whether the current
    account is the account being accessed.

    The second element in the tuple is whether the current
    user is a webmaster
    """

    # see if the user is the current user
    same_user = False
    if current_user.cwruid == cwruid:
        same_user = True

    # see if the user is an admin
    admin_user = False

    query = UserRoleModel.all()
    query.filter('user ='******'webmaster':
            admin_user = True
            break

    return (same_user, admin_user)
def list_users_by_family(family_name):
    """
    This view displays a list of users for the family
    specified in family_name
    """

    can_edit = None
    query = UserRoleModel.all()
    query.filter('user ='******'webmaster':
            can_edit = True
            break

    query = models.FamilyModel.all()
    query.filter('name =', urllib.unquote_plus(family_name).lower())
    try:
        family = query.fetch(1)[0]
    except IndexError:
        return "no such family"
        return render_template('404.html'), 404

    users = find_users(family=('=', family.key()))

    return render_template('members/list.html',
                           can_edit=can_edit,
                           family=family,
                           users=users)
def contracts_list_contracts():
    """
    Lists all of the available contracts
    and provides links to their summary pages
    """

    can_edit = None
    query = UserRoleModel.all()
    query.filter('user ='******'webmaster':
            can_edit = True
            break

    query = models.ContractModel.all()

    contracts = query.fetch(query.count())

    for contract in contracts:
        contract.url_name = urllib.quote_plus(contract.name)

    return render_template('contracts/list.html',
                           can_edit=can_edit,
                           contracts=contracts)
def photos_show_album(album_id):
    """
    View to display all of an album's
    photos
    """
    query = UserRoleModel.all()
    query.filter("user ="******"webmaster":
            can_edit = True
            break

    query = fb_models.AlbumModel.all()
    query.filter("me =", album_id)

    try:
        album = query.fetch(1)[0]
    except IndexError:
        return render_template("404.html"), 404

    query = fb_models.PhotoModel.all()
    query.filter("approved =", True)
    query.filter("album_id =", album_id)

    photos = query.fetch(query.count())

    return render_template("photos/show_album.html", can_edit=can_edit, album=album, photos=photos)
Beispiel #10
0
def list_users_by_family(family_name):
    """
    This view displays a list of users for the family
    specified in family_name
    """


    
    can_edit = None
    query = UserRoleModel.all()
    query.filter('user ='******'webmaster':
            can_edit = True
            break

    query = models.FamilyModel.all()
    query.filter('name =', urllib.unquote_plus(family_name).lower())
    try:
        family = query.fetch(1)[0]
    except IndexError:
        return "no such family"
        return render_template('404.html'), 404

    users = find_users(family=('=', family.key()))

    return render_template('members/list.html',
                           can_edit=can_edit,
                           family=family,
                           users=users)
Beispiel #11
0
def photos_show_album(album_id):
    """
    View to display all of an album's
    photos
    """
    query = UserRoleModel.all()
    query.filter('user ='******'webmaster':
            can_edit = True
            break

    query = fb_models.AlbumModel.all()
    query.filter('me =', album_id)

    try:
        album = query.fetch(1)[0]
    except IndexError:
        return render_template('404.html'), 404

    query = fb_models.PhotoModel.all()
    query.filter('approved =', True)
    query.filter('album_id =', album_id)

    photos = query.fetch(query.count())

    return render_template('photos/show_album.html',
                           can_edit=can_edit,
                           album=album,
                           photos=photos)
Beispiel #12
0
def contracts_list_contracts():
    """
    Lists all of the available contracts
    and provides links to their summary pages
    """

    can_edit = None
    query = UserRoleModel.all()
    query.filter('user ='******'webmaster':
            can_edit = True
            break
        

    query = models.ContractModel.all()
    
    contracts = query.fetch(query.count())

    for contract in contracts:
        contract.url_name = urllib.quote_plus(contract.name)
    
    return render_template('contracts/list.html',
                           can_edit=can_edit,
                           contracts=contracts)
Beispiel #13
0
def service_event_signup(event_name, event_time):
    """
    This view will sign a user up for an event
    """

    event = get_service_event(event_name, event_time)
    if event is None:
        return render_template('404.html'), 404
    event = prepare_service_event(event)

    signups = get_signups(event)

    if (event.maxBro is not None
            and len(signups) < event.maxBro) or event.maxBro is None:
        signup = models.ServiceSignUpModel(user=current_user.key(),
                                           event=event.key())
        signup.put()

        flash('Successfully signup up for event', 'success')
    else:
        flash('Error signing up for event. Event is already full', 'error')
    return redirect(
        url_for('service_show_event',
                event_name=event.url_name,
                event_time=event.url_time))
Beispiel #14
0
def check_permissions(cwruid):
    """
    Returns a permissions tuple.

    The first element in the tuple is whether the current
    account is the account being accessed.

    The second element in the tuple is whether the current
    user is a webmaster
    """

    # see if the user is the current user
    same_user = False
    if current_user.cwruid == cwruid:
        same_user = True

    # see if the user is an admin
    admin_user = False

    query = UserRoleModel.all()
    query.filter('user ='******'webmaster':
            admin_user = True
            break

    return (same_user, admin_user)
Beispiel #15
0
def list_users():
    """
    View for listing all users
    and listing users based on a
    search.

    If membership role or webmaster role is present
    then the user will also see edit links for the user
    """

    can_edit = None

    query = UserRoleModel.all()
    query.filter('user ='******'webmaster':
            can_edit = True
            break
    
    users = find_users()
    return render_template('members/list.html',
                           can_edit=can_edit,
                           users=users)
Beispiel #16
0
def contracts_sign(contract_name):
    """
    Allows a user that has not already signed a contract
    to sign a contract
    """

    query = models.SignedContractModel.all()
    query.filter('user ='******'You cannot sign more than one contract', 'error')
        return redirect(url_for('contracts_list_contracts'))

    query = models.ContractModel.all()
    query.filter('name =', urllib.unquote_plus(contract_name))

    try:
        contract = query.fetch(1)[0]
    except:
        return render_template('404.html'), 404

    signed = models.SignedContractModel(user=current_user.key(),
                                        contract_=contract.key())

    signed.put()

    # create the empty progress models for each requirement on this contract
    query = models.TimeReqModel.all()
    query.filter('contract_ =', contract)

    time_reqs = query.fetch(query.count())
    for time_req in time_reqs:
        time_req_prog = models.TimeReqProgressModel(user=current_user.key(),
                                                    req=time_req)
        time_req_prog.put()

    query = models.DuesReqModel.all()
    query.filter('contract_ =', contract)

    dues_reqs = query.fetch(query.count())
    for dues_req in dues_reqs:
        dues_req_prog = models.DuesReqProgressModel(user=current_user.key(),
                                                    req=dues_req)
        dues_req_prog.put()

    flash('You have successfully signed a contract', 'success')
    return redirect(url_for('contracts_progress'))
Beispiel #17
0
def edit_blog_post(timestamp, title):
    """
    View to edit an exsiting blog specified
    by the timestamp and title
    """
    # get the blog posts
    query = models.PostModel.all()
    str_timestamp = urllib.unquote_plus(timestamp)
    timestamp = dt.datetime.strptime(str_timestamp, '%Y-%m-%d %H:%M:%S.%f')
    query.filter('timestamp =', timestamp)
    query.filter('title =', urllib.unquote_plus(title))

    try:
        post = query.fetch(1)[0]
    except IndexError:
        return render_template('404.html'), 404

    post.url_timestamp = urllib.quote_plus(str(post.timestamp))
    post.url_title = urllib.quote_plus(post.title)

    post_form = forms.NewPostForm()
    if request.method == "POST" and post_form.validate():
        query = models.CommentModel.all()
        query.filter('post =', post.key())

        comments = query.fetch(query.count())

        new_post = models.PostModel(title=post_form.title.data,
                                    timestamp=dt.datetime.now(),
                                    text=post_form.text.data,
                                    author=current_user.key())

        new_post.put()

        for comment in comments:
            comment.post = new_post.key()
            comment.put()

        post.delete()

        new_post.url_timestamp = urllib.quote_plus(str(new_post.timestamp))
        new_post.url_title = urllib.quote_plus(new_post.title)

        return redirect(
            url_for('view_blog_post',
                    timestamp=new_post.url_timestamp,
                    title=new_post.url_title))

    edit_post_form = forms.NewPostForm(None)
    edit_post_form.title.data = post.title
    edit_post_form.text.data = post.text

    url_timestamp = urllib.quote_plus(str(post.timestamp))
    url_title = urllib.quote_plus(post.title)

    return render_template('blogs/edit_post.html',
                           form=edit_post_form,
                           url_timestamp=url_timestamp,
                           url_title=url_title)
Beispiel #18
0
def edit_blog_post(timestamp, title):
    """
    View to edit an exsiting blog specified
    by the timestamp and title
    """
    # get the blog posts
    query = models.PostModel.all()
    str_timestamp = urllib.unquote_plus(timestamp)
    timestamp = dt.datetime.strptime(str_timestamp, '%Y-%m-%d %H:%M:%S.%f')
    query.filter('timestamp =', timestamp)
    query.filter('title =', urllib.unquote_plus(title))
    
    try:
        post = query.fetch(1)[0]
    except IndexError:
        return render_template('404.html'), 404

    post.url_timestamp = urllib.quote_plus(str(post.timestamp))
    post.url_title = urllib.quote_plus(post.title)
        
    post_form = forms.NewPostForm()
    if request.method == "POST" and post_form.validate():
        query = models.CommentModel.all()
        query.filter('post =', post.key())

        comments = query.fetch(query.count())
        
        new_post = models.PostModel(title=post_form.title.data,
                                    timestamp=dt.datetime.now(),
                                    text=post_form.text.data,
                                    author=current_user.key())

        new_post.put()

        for comment in comments:
            comment.post = new_post.key()
            comment.put()

        post.delete()

        new_post.url_timestamp = urllib.quote_plus(str(new_post.timestamp))
        new_post.url_title = urllib.quote_plus(new_post.title)

        return redirect(url_for('view_blog_post',
                                timestamp=new_post.url_timestamp,
                                title=new_post.url_title))
        
    edit_post_form = forms.NewPostForm(None)
    edit_post_form.title.data = post.title
    edit_post_form.text.data = post.text

    url_timestamp = urllib.quote_plus(str(post.timestamp))
    url_title = urllib.quote_plus(post.title)
    
    return render_template('blogs/edit_post.html',
                           form=edit_post_form,
                           url_timestamp=url_timestamp,
                           url_title=url_title)
Beispiel #19
0
def contracts_progress():
    """
    Shows the contract progress for the current user
    """

    query = models.SignedContractModel.all()
    query.filter('user ='******'You have not yet signed a contract', 'error')
        return redirect(url_for('contracts_list_contracts'))

    query = models.TimeReqProgressModel.all()
    query.filter('user ='******'user ='******'contracts/progress.html',
                           user=current_user,
                           contract=signed_contract.contract_,
                           time_req_progs=time_req_progresses,
                           dues_req_progs=dues_req_progresses)
Beispiel #20
0
def can_edit(names):
    # see if the user is an admin
    admin_user = False

    query = UserRoleModel.all()
    query.filter('user =', current_user.key())
    uroles = query.fetch(query.count())
    for urole in uroles:
        if urole.role.name in names:
            admin_user = True

    return admin_user
def can_edit(names):
    # see if the user is an admin
    admin_user = False

    query = UserRoleModel.all()
    query.filter('user =', current_user.key())
    uroles = query.fetch(query.count())
    for urole in uroles:
        if urole.role.name in names:
            admin_user = True

    return admin_user
Beispiel #22
0
def contracts_progress():
    """
    Shows the contract progress for the current user
    """

    query = models.SignedContractModel.all()
    query.filter('user ='******'You have not yet signed a contract', 'error')
        return redirect(url_for('contracts_list_contracts'))

    query = models.TimeReqProgressModel.all()
    query.filter('user ='******'user ='******'contracts/progress.html',
                           user=current_user,
                           contract=signed_contract.contract_,
                           time_req_progs=time_req_progresses,
                           dues_req_progs=dues_req_progresses)
def is_signed_up(event):
    """
    This method determines if the current
    user is signed up for the specified event.

    It returns the ServiceSignUpModel associated
    with the user, event pair if the user is signed up
    otherwise it returns None.
    """

    query = models.ServiceSignUpModel.all()
    query.filter('user ='******'event =', event.key())

    try:
        return query.fetch(1)[0]
    except IndexError:
        return None
Beispiel #24
0
def photos_album_list():
    """
    View for displaying a list of all albums
    """

    query = UserRoleModel.all()
    query.filter("user ="******"webmaster":
            can_edit = True
            break

    query = fb_models.AlbumModel.all()
    query.filter("display =", True)

    albums = query.fetch(query.count())

    return render_template("photos/list_albums.html", can_edit=can_edit, albums=albums)
Beispiel #25
0
def service_event_signup(event_name, event_time):
    """
    This view will sign a user up for an event
    """

    event = get_service_event(event_name, event_time)
    if event is None:
        return render_template('404.html'), 404
    event = prepare_service_event(event)

    signups = get_signups(event)

    if (event.maxBro is not None and len(signups) < event.maxBro) or event.maxBro is None:
        signup = models.ServiceSignUpModel(user=current_user.key(),
                                           event=event.key())
        signup.put()

        flash('Successfully signup up for event', 'success')
    else:
        flash('Error signing up for event. Event is already full', 'error')
    return redirect(url_for('service_show_event',
                            event_name=event.url_name,
                            event_time=event.url_time))
Beispiel #26
0
def list_users():
    """
    View for listing all users
    and listing users based on a
    search.

    If membership role or webmaster role is present
    then the user will also see edit links for the user
    """

    can_edit = None

    query = UserRoleModel.all()
    query.filter('user ='******'webmaster':
            can_edit = True
            break

    users = find_users()
    return render_template('members/list.html', can_edit=can_edit, users=users)
Beispiel #27
0
def photos_album_list():
    """
    View for displaying a list of all albums
    """

    query = UserRoleModel.all()
    query.filter('user ='******'webmaster':
            can_edit = True
            break

    query = fb_models.AlbumModel.all()
    query.filter('display =', True)

    albums = query.fetch(query.count())

    return render_template('photos/list_albums.html',
                           can_edit=can_edit,
                           albums=albums)
Beispiel #28
0
def view_blog_post(timestamp, title):
    """
    View to display blog post and associated comments
    """

    edit_post = None
    # determine if the user has the proper role to edit
    if current_user.is_authenticated():
        query = UserRoleModel.all()
        query.filter('user ='******'webmaster':
                edit_post = True
                break

    # get the blog posts
    query = models.PostModel.all()
    str_timestamp = urllib.unquote_plus(timestamp)
    timestamp = dt.datetime.strptime(str_timestamp, '%Y-%m-%d %H:%M:%S.%f')
    query.filter('timestamp =', timestamp)
    query.filter('title =', urllib.unquote_plus(title))
    
    try:
        post = query.fetch(1)[0]
    except IndexError:
        return render_template('404.html'), 404

    # add the urlencoded version of timestamp and 
    post.url_timestamp = urllib.quote_plus(str(post.timestamp))
    post.url_title = urllib.quote_plus(post.title)
        
    # get the comments
    query = models.CommentModel.all()
    query.filter('post =', post.key())
    query.order('timestamp')

    comments = query.fetch(query.count())

    # go through and add forms with delete button to each comment if the user
    # has edit privileges
    if edit_post is not None:
        for comment in comments:
            comment.delete = forms.DeleteCommentForm(None)
            comment.delete.key.data = comment.key()
            comment.url_timestamp = urllib.quote_plus(str(comment.timestamp))

    form = forms.NewComment(request.form)
    if request.method=="POST" and form.validate():
        comment = models.CommentModel(post=post.key(),
                                      timestamp=dt.datetime.now(),
                                      text=form.text.data,
                                      author=current_user.key())
        comment.put()
        comment.delete = forms.DeleteCommentForm(None)
        comment.delete.key.data = comment.key()
        comment.url_timestamp = urllib.quote_plus(str(comment.timestamp))

        comments.append(comment)
        
    return render_template('blogs/display_post.html',
                           edit_post=edit_post,
                           current_user=current_user,
                           post=post,
                           comments=comments,
                           new_comment=forms.NewComment(None))
Beispiel #29
0
def view_blog_post(timestamp, title):
    """
    View to display blog post and associated comments
    """

    edit_post = None
    # determine if the user has the proper role to edit
    if current_user.is_authenticated():
        query = UserRoleModel.all()
        query.filter('user ='******'webmaster':
                edit_post = True
                break

    # get the blog posts
    query = models.PostModel.all()
    str_timestamp = urllib.unquote_plus(timestamp)
    timestamp = dt.datetime.strptime(str_timestamp, '%Y-%m-%d %H:%M:%S.%f')
    query.filter('timestamp =', timestamp)
    query.filter('title =', urllib.unquote_plus(title))

    try:
        post = query.fetch(1)[0]
    except IndexError:
        return render_template('404.html'), 404

    # add the urlencoded version of timestamp and
    post.url_timestamp = urllib.quote_plus(str(post.timestamp))
    post.url_title = urllib.quote_plus(post.title)

    # get the comments
    query = models.CommentModel.all()
    query.filter('post =', post.key())
    query.order('timestamp')

    comments = query.fetch(query.count())

    # go through and add forms with delete button to each comment if the user
    # has edit privileges
    if edit_post is not None:
        for comment in comments:
            comment.delete = forms.DeleteCommentForm(None)
            comment.delete.key.data = comment.key()
            comment.url_timestamp = urllib.quote_plus(str(comment.timestamp))

    form = forms.NewComment(request.form)
    if request.method == "POST" and form.validate():
        comment = models.CommentModel(post=post.key(),
                                      timestamp=dt.datetime.now(),
                                      text=form.text.data,
                                      author=current_user.key())
        comment.put()
        comment.delete = forms.DeleteCommentForm(None)
        comment.delete.key.data = comment.key()
        comment.url_timestamp = urllib.quote_plus(str(comment.timestamp))

        comments.append(comment)

    return render_template('blogs/display_post.html',
                           edit_post=edit_post,
                           current_user=current_user,
                           post=post,
                           comments=comments,
                           new_comment=forms.NewComment(None))