def group_edit_view(request): """returns current group information for editing and then collects all information that has been added by the user whether new or existing and edits the existing entries. """ username = request.authenticated_userid group = Group.lookup_by_attribute(name=request.matchdict['group_name'])[0] criteria = Criteria.lookup_by_attribute(group=group)[0] if request.method == 'POST': criteria = Criteria.edit(location=request.params.getall('location'), taste=request.params.getall('taste'), diet=request.params.getall('diet'), cost=request.params.getall('cost'), age=request.params.getall('age'), id=criteria.id) group = Group.edit(name=request.params.get('name'), description=request.params.get('description'), id=group.id) return HTTPFound(request.route_url('group_detail', group_name=group.name)) profile = {} profile['criteria'] = criteria profile['group'] = group profile['username'] = username return profile
def profile_edit_view(request): """returns current user information. On POST collects all information fromt the page and edits the user and criteria accordingly. """ username = request.authenticated_userid user = User.lookup_by_attribute(username=username)[0] criteria = Criteria.lookup_by_attribute(user=user)[0] if request.method == 'POST': User.edit(id=user.id, username=username, firstname=request.params.get('first_name'), lastname=request.params.get('last_name'), restaurants=request.params.get('favorite_restaurants'), food=request.params.get('favorite_food') ) Criteria.edit(id=criteria.id, location=request.params.getall('location'), taste=request.params.getall('taste'), diet=request.params.getall('diet'), cost=request.params.getall('cost'), age=request.params.getall('age') ) headers = remember(request, username) return HTTPFound(request.route_url( 'profile_detail', username=username ), headers=headers) profile = {} profile['criteria'] = criteria profile['username'] = username profile['user'] = user return profile
def group_create_view(request): """Collects all information from the page and instanciates a new group and its corresponding criteria. """ username = request.authenticated_userid admin = User.lookup_by_attribute(username=username)[0] if request.method == 'POST': group = Group.add(name=request.params.get('name'), description=request.params.get('description'), admin=admin, users=[admin], forum=OrderedDict()) Criteria.add(location=request.params.getall('location'), taste=request.params.getall('taste'), diet=request.params.getall('diet'), cost=request.params.getall('cost'), age=request.params.getall('age'), group=group) return HTTPFound(request.route_url('group_detail', group_name=group.name)) profile = {} profile['criteria'] = Criteria() profile['username'] = username return profile
def profile_detail_view(request): """will allow the user who owns the profile or any user who is in a group with that user to see that users current informmation and criteria. """ if not (request.has_permission('owner') or request.has_permission('connect')): return HTTPForbidden() user = User.lookup_by_attribute(username=request.matchdict['username'])[0] profile = {} profile['username'] = request.authenticated_userid, profile['user'] = user profile['criteria'] = Criteria.lookup_by_attribute(user=user)[0] return profile
def user_create_view(request): username = request.authenticated_userid if request.method == 'POST': try: manager = BCRYPTPasswordManager() username = request.params.get('username') password = request.params.get('password') hashed = manager.encode(password) email = request.params.get('email') user = User.add( username=username, password=hashed, email=email, ) Criteria.add(user=user) headers = remember(request, username) return HTTPFound(request.route_url('send_email'), headers=headers) except: return {} return {'username': username}
def group_detail_view(request): """returns current group information. If recievng input form a form will add that user as a group member if they aren't already. Will look to see whether a new discussion is being created and if so, add it to the group forum. If a new post on an existing discussion is created that post will be added to the appropriate discussion. Discussions are returned in reverse order. """ username = request.authenticated_userid group = Group.lookup_by_attribute(name=request.matchdict['group_name'])[0] criteria = Criteria.lookup_by_attribute(group=group)[0] if request.method == 'POST': user = User.lookup_by_attribute(username=username)[0] user.groups.append(group) time = datetime.datetime.utcnow() if request.params.get('title'): title = request.params.get('title') group.forum[title] = [(request.params.get('post'), username, time)] group.edit(id=group.id, forum=group.forum) else: title = request.params.items()[0][0] post = request.params.items()[0][1] group.forum[title].append((post, username, time)) group.edit(id=group.id, forum=group.forum) return HTTPFound(request.route_url( 'group_detail', group_name=request.matchdict['group_name'], )) profile = {} forum = OrderedDict() for _ in range(len(group.forum)): to_add = group.forum.popitem() forum[to_add[0]] = to_add[1] profile['forum'] = forum profile['criteria'] = criteria profile['group'] = group profile['username'] = username return profile