Exemplo n.º 1
0
def group(name, id):
    group = Group.query.filter_by(id=id).first()
    if not group:
        flash("Invalid group requested.")
        if request.referrer:
            return redirect(request.referrer)
        else:
            return redirect(url_for('relationship.network_groups'))
    else:
        if current_user == group.admin:
            modal_form = GroupEditForm(
                name=group.name, description=group.description, id=group.id
            )
            modal_title = "Edit Group"
        else:
            modal_form = False
            modal_title = None
        reviews = Review.search(group_id=group.id)
        page = request.args.get('page', 1, int)
        pagination = Pagination(
            reviews, page, current_app.config.get('PER_PAGE')
        )
        pag_args = {"name": name, "id": id}
        pag_urls = pagination.get_urls('relationship.group', pag_args)
        reviews = pagination.paginatedData
        return render_template(
            "relationship/group.html", group=group, modal_form=modal_form,
            modal_title=modal_title, reviews=reviews, pag_urls=pag_urls,
            title="Group Profile"
        )
Exemplo n.º 2
0
def view_messages(folder):
    messages = current_user.get_messages(folder)
    page = request.args.get('page', 1, int)
    pagination = Pagination(messages, page, current_app.config.get('PER_PAGE'))
    pag_urls = pagination.get_urls('message.view_messages',
                                   dict(folder=folder))
    messages = pagination.paginatedData
    new_message = UserMessageForm()
    messages_dict = [{
        "id": msg.id,
        "timestamp": msg.message.timestamp,
        "read": msg.read,
        "sender_id": msg.message.sender.user_id,
        "sender_full_name": msg.message.sender.full_name,
        "sender_user_name": msg.message.sender.user.username,
        "status": msg.tag,
        "subject": msg.message.subject,
        "body": msg.message.body
    } for msg in messages]
    messages_json = json.dumps(messages_dict)
    pagination_json = json.dumps(pag_urls)
    return render_template("messages.html",
                           title="messages",
                           messages=messages,
                           pagination_json=pagination_json,
                           new_message=new_message,
                           messages_json=messages_json)
Exemplo n.º 3
0
 def test_get_urls(self):
     p = Pagination(self.testIterable, 2, current_app.config['PER_PAGE'])
     u = p.get_urls('main.index', self.testArgs)
     assert u['next'] == '/index?page=3&name=testName'
     assert u['pages'][0] == (1, '/index?page=1&name=testName')
     num_pages = len(u['pages'])
     assert u['prev'] == '/index?page=1&name=testName'
Exemplo n.º 4
0
def passwordupdate():
    pform = PasswordChangeForm()
    if pform.validate_on_submit():
        current_user.set_password(pform.new.data)
        current_user.save()
        flash("Password updated")
        return redirect(url_for('main.user', username=current_user.username))
    form = UserUpdateForm().populate_choices()
    modal_title = "Edit User Information"
    modal_title_2 = "Change Password"
    pword_open = True
    flash("Password update failed, please correct errors")
    page = request.args.get('page', 1, int)
    user = current_user
    reviews = user.reviews
    summary = user.summary()
    pag_args = {"username": user.username}
    pagination = Pagination(reviews, page, current_app.config.get('PER_PAGE'))
    pag_urls = pagination.get_urls('main.user', pag_args)
    reviews = pagination.paginatedData
    return render_template("user.html",
                           title="User Profile",
                           user=user,
                           reviews=reviews,
                           form=form,
                           modal_title=modal_title,
                           pform=pform,
                           modal_title_2=modal_title_2,
                           pword_open=pword_open,
                           pag_urls=pag_urls,
                           summary=summary)
Exemplo n.º 5
0
def provider(name, id):
    """Generate provider profile page."""
    form = ProviderFilterForm(request.args)
    filters = {"id": id, "name": name}
    try:
        provider = Provider.search(filters)[0]
    except IndexError:
        flash("Provider not found.  Please try a different search.")
        return render_template('errors/404.html'), 404
    if form.validate():
        reviewFilter = {
            "friends_filter": form.friends_filter.data,
            "groups_filter": form.groups_filter.data
        }
        page = request.args.get('page', 1, int)
        return_code = 200
    else:
        last = dict(parse.parse_qsl(parse.urlsplit(request.referrer).query))
        filter_keys = ['friends_filter', 'groups_filter']
        reviewFilter = {k: last.get(k) == 'y' for k in filter_keys}
        page = last.get('page', 1)
        return_code = 422
    if provider.reviewCount > 0:
        reviews = Review.search(provider_id=provider.id, filter=reviewFilter)
        pagination = Pagination(reviews, page,
                                current_app.config.get('PER_PAGE'))
        pag_args = {"name": name, "id": id}
        pag_urls = pagination.get_urls('main.provider', pag_args)
        reviews = pagination.paginatedData
    else:
        reviews = None
        pag_urls = None

    provider_json = simplejson.dumps(provider._asdict(), sort_keys=True)

    return render_template("provider_profile.html",
                           title="Provider Profile",
                           provider=provider,
                           pag_urls=pag_urls,
                           reviews=reviews,
                           form=form,
                           reviewFilter=reviewFilter,
                           provider_json=provider_json), return_code
Exemplo n.º 6
0
def groupSearch():
    """Searches db for groups to populate group search autocomplete"""
    form = GroupSearchForm(request.args)
    if form.validate():
        filters = {"name": form.name.data}
        groups = Group.search(filters)
        page = request.args.get('page', 1, int)
        pagination = Pagination(
            groups, page, current_app.config.get('PER_PAGE')
        )
        pag_args = {"name": form.name.data}
        pag_urls = pagination.get_urls('relationship.groupSearch', pag_args)
        groups = pagination.paginatedData
        addForm = GroupAddForm()
        code = 200
        return render_template(
            "relationship/groupSearch.html", form=form, title="Group Search",
            groups=groups, addForm=addForm, pag_urls=pag_urls
        ), code
    else:
        code = 422
        return groups_render(form, code=422)
Exemplo n.º 7
0
def user(username):
    """Generate profile page."""
    page = request.args.get('page', 1, int)
    user = User.query.filter_by(username=username).first()
    reviews = Review.search(user_id=user.id)
    summary = user.summary()
    pag_args = {"username": username}
    pagination = Pagination(reviews, page, current_app.config.get('PER_PAGE'))
    pag_urls = pagination.get_urls('main.user', pag_args)
    reviews = pagination.paginatedData

    if user == current_user:
        form = UserUpdateForm(obj=user).populate_choices()
        form.address.state.data = user.address.state.id
        pform = PasswordChangeForm()
        modal_title = "Edit User Information"
        modal_title_2 = "Change Password"
        return render_template("user.html",
                               title="User Profile",
                               user=user,
                               reviews=reviews,
                               form=form,
                               summary=summary,
                               modal_title=modal_title,
                               pform=pform,
                               modal_title_2=modal_title_2,
                               pag_urls=pag_urls)

    message = UserMessageForm(Message_User=user.full_name,
                              recipient_id=user.id)
    return render_template("user.html",
                           title="User Profile",
                           user=user,
                           reviews=reviews,
                           pag_urls=pag_urls,
                           summary=summary,
                           message=message)
Exemplo n.º 8
0
def userupdate():
    """Update user information minus password which is updated seperately."""
    form = UserUpdateForm().populate_choices()
    if form.validate_on_submit():
        current_user.address.update(line1=form.address.line1.data,
                                    line2=form.address.line2.data,
                                    city=form.address.city.data,
                                    zip=form.address.zip.data,
                                    state_id=form.address.state.data)
        address = current_user.address
        current_user.update(first_name=form.first_name.data,
                            last_name=form.last_name.data,
                            email=form.email.data,
                            username=form.username.data,
                            address=address)
        current_user.send_email_verification()
        flash("User information updated")
        return redirect(url_for('main.user', username=current_user.username))
    modal_title = "Edit User Information"
    modal_open = True
    flash("User information update failed.  Please correct errors.")
    page = request.args.get('page', 1, int)
    reviews = current_user.reviews
    summary = current_user.summary()
    pag_args = {"username": current_user.username}
    pagination = Pagination(reviews, page, current_app.config.get('PER_PAGE'))
    pag_urls = pagination.get_urls('main.user', pag_args)
    reviews = pagination.paginatedData
    return render_template("user.html",
                           form=form,
                           reviews=reviews,
                           title="User Profile",
                           modal_title=modal_title,
                           user=current_user,
                           modal_open=modal_open,
                           pag_urls=pag_urls,
                           summary=summary), 422
Exemplo n.º 9
0
def search():
    form = ProviderSearchForm(request.args)
    form.populate_choices()
    page = request.args.get('page', 1, int)
    form_dict = json.dumps(form.data)
    if form.validate() or request.args.get('page') is not None:
        try:
            searchLocation = Location(form.location.data,
                                      form.manual_location.data,
                                      (form.gpsLat.data, form.gpsLong.data))
        except AddressError:
            flash("Invalid address submitted. Please re-enter and try again.")
            if form.manual_location.data not in [None, ""]:
                msg = "Invalid Address. Please updated."
                form.manual_location.errors.append(msg)
            return render_template("index.html",
                                   form_dict=form_dict,
                                   form=form,
                                   title="Search"), 422

        searchLocation.setRangeCoordinates(form.searchRange.data)
        filters = {
            "name": form.name.data,
            "category": Category.query.get(form.category.data),
            "location": searchLocation,
            "friends": form.friends_filter.data,
            "groups": form.groups_filter.data,
            "reviewed": form.reviewed_filter.data
        }
        sortCriteria = form.sort.data
        providers = Provider.search(filters, sortCriteria)

        if providers == []:
            flash("No results found. Please try a different search.")
            providersDict = simplejson.dumps([], sort_keys=True)
            summary = None
            pag_urls = None
            locationDict = None

        else:
            summary = Review.summaryStatSearch(filters)
            if sortCriteria == "distance":
                providers = sortByDistance(searchLocation.coordinates,
                                           providers)
            pagination = Pagination(providers, page,
                                    current_app.config.get('PER_PAGE'))
            pag_urls = pagination.get_urls('main.search', request.args)
            providers = pagination.paginatedData
            providersDict = [provider._asdict() for provider in providers]
            providersDict = simplejson.dumps(providersDict, sort_keys=True)
            if session.get('location'):
                locationDict = session['location']
                locationDict = simplejson.dumps(locationDict, sort_keys=True)
            else:
                locationDict = None

        filter_fields = [
            form.reviewed_filter, form.friends_filter, form.groups_filter
        ]
        reviewFilter = {}
        for field in filter_fields:
            if field.data is True:
                reviewFilter[field.name] = 'y'
        form.initialize()

        return render_template("index.html",
                               form=form,
                               title="Search",
                               providers=providers,
                               pag_urls=pag_urls,
                               form_dict=form_dict,
                               reviewFilter=reviewFilter,
                               locationDict=locationDict,
                               providersDict=providersDict,
                               summary=summary)
    return render_template("index.html",
                           form=form,
                           form_dict=form_dict,
                           title="Search"), 422