def block(to_username): ref = request.referrer logged_user = User.getByName(session.get('username')) to_user = User.getByName(to_username) if to_user: rel_status = Relationship.get_relationship_status(logged_user.id, to_user.id) if rel_status == "FRIENDS_PENDING" \ or rel_status == "FRIENDS_APPROVED" \ or rel_status == "REVERSE_FRIENDS_PENDING": rel = Relationship.get_relationship(logged_user.id, to_user.id) rel.delete_record() reverse_rel = Relationship.get_relationship(to_user.id, logged_user.id) reverse_rel.delete_record() Relationship( from_user=logged_user.id, to_user=to_user.id, rel_type=RELATIONSHIP_TYPE.get(BLOCKED), status=STATUS_TYPE.get(APPROVED) ).save_database() if ref: return redirect(ref) else: return redirect(url_for('user_blueprint.profile', username=to_user.username)) else: abort(404)
def add_friend(to_username): ref = request.referrer logged_user = User.objects.filter(username=session.get('username')).first() to_user = User.objects.filter(username=to_username).first() if to_user: to_username = to_user.username rel = Relationship.get_relationship(logged_user, to_user) if rel == "FRIENDS_PENDING": return rel elif rel == "BLOCKED": return rel elif rel == "FRIENDS_APPROVED": return rel elif rel == "REVERSE_FRIENDS_PENDING": #Friend has approved Relationship(from_user=logged_user, to_user=to_user, rel_type=Relationship.FRIENDS, status=Relationship.APPROVED).save() reverse_rel = Relationship.objects.get(from_user=to_user, to_user=logged_user) reverse_rel.status = Relationship.APPROVED reverse_rel.save() #return "FRIENDS_APPROVED" elif rel == None and rel != "REVERSE_BLOCKED": #notFriend, notBlocked Relationship(from_user=logged_user, to_user=to_user, rel_type=Relationship.FRIENDS, status=Relationship.PENDING).save() return "FRIENDSHIP_REQUESTED" return redirect(url_for('user_app.profile', username=to_username)) else: abort(404)
def add_friend(to_username): logged_user = User.objects.filter(username=session.get('username')).first() to_user = User.objects.filter(username=to_username).first() if to_user: rel = Relationship.get_relationship(logged_user, to_user) to_username = to_user.username if rel == "REVERSE_FRIENDS_PENDING": Relationship( from_user=logged_user, to_user=to_user, rel_type=Relationship.FRIENDS, status=Relationship.APPROVED ).save() reverse_rel = Relationship.objects.get( from_user=to_user, to_user=logged_user ) reverse_rel.status=Relationship.APPROVED reverse_rel.save() elif rel == None and rel != "REVERSE_BLOCKED": Relationship( from_user=logged_user, to_user=to_user, rel_type=Relationship.FRIENDS, status=Relationship.PENDING ).save() return redirect(url_for('user_app.profile', username=to_username)) else: abort(404)
def block(to_username): ref = request.referrer logged_user = User.objects.filter(username=session.get('username')).first() to_user = User.objects.filter(username=to_username).first() if to_user: rel = Relationship.get_relationship(logged_user, to_user) to_username = to_user.username if rel == "FRIENDS_PENDING" or rel == "FRIENDS_APPROVED" or rel == "REVERSE_FRIENDS_PENDING": rel = Relationship.objects.filter(from_user=logged_user, to_user=to_user).delete() reverse_rel = Relationship.objects.filter( from_user=to_user, to_user=logged_user).delete() Relationship(from_user=logged_user, to_user=to_user, rel_type=Relationship.BLOCKED, status=Relationship.APPROVED).save() if ref: return redirect(ref) else: return redirect( url_for('user_app.profile', username=to_user.username)) else: abort(404)
def follow(request,object_id): '''用户(身份病人)follow''' result = {} dentistuser = User.objects.get(id=object_id) DentistProfileObj = DentistProfile.objects.get(user=dentistuser) PatientProfileObj = PatientProfile.objects.get(user=request.user) try: Relationship.objects.get(patient = PatientProfileObj,dentist = DentistProfileObj) result = { "msg":"Failure", "status":0, } except: RelationshipNew = Relationship(patient = PatientProfileObj,dentist = DentistProfileObj,status = 0) RelationshipNew.save() result = { "msg":"Success", "status":1, } return result
def _dissolve_connection_between_users(username): logged_user, to_user = _get_requesting_user_and_logged_in_user_obj( "" or username.lower()) if to_user and _is_there_relationship_between_users(logged_user, to_user): Relationship.delete_connection_between_users(logged_user, to_user)
def profile(username, friends_page_number=1): logged_user = None rel = None friends_page = False friends_per_page = 3 profile_messages = [] user = User.getByName(username) if user: if session['username']: logged_user = User.getByName(session['username']) rel = Relationship.get_relationship_status(logged_user.id, user.id) # get user friends friends_list = Relationship.get_friends( user=logged_user.id, rel_type=RELATIONSHIP_TYPE.get(FRIENDS), status=STATUS_TYPE.get(APPROVED) ) friends_total = len(friends_list) if 'friends' in request.url: friends_page = True # pagination limit = friends_per_page * friends_page_number offset = limit - friends_per_page if friends_total >= limit: friends = friends_list[offset:limit] else: friends = friends_list[offset:friends_total] else: if friends_total >= 5: friends = friends_list[:5] else: friends = friends_list form = FeedPostForm() if logged_user and (rel == "SAME" or rel == "FRIENDS_APPROVED"): profile_messages = Message.getMessages(logged_user.id) return render_template('user/profile.html', user=user, logged_user=logged_user, rel=rel, friends=friends, friends_total=friends_total, friends_page=friends_page, form=form, profile_messages=profile_messages ) else: abort(404)
def unblock(username): logged_user, to_user = _get_requesting_user_and_logged_in_user_obj( username) if to_user: rel = Relationship.get_relationship(logged_user, to_user) if rel == constants.BLOCKED: Relationship.delete_connection_between_users(logged_user, to_user) return _redirect_to_referred_url_if_safe(username) abort(404)
def add_friend(to_username): ref = request.referrer logged_user = User.getByName(session.get('username')) to_user = User.getByName(to_username) if to_user: rel_status = Relationship.get_relationship_status(logged_user.id, to_user.id) if rel_status == "REVERSE_FRIENDS_PENDING": Relationship( from_user=logged_user.id, to_user=to_user.id, rel_type=RELATIONSHIP_TYPE.get(FRIENDS), status=STATUS_TYPE.get(APPROVED) ).save_database() reverse_rel = Relationship.get_relationship(to_user.id, logged_user.id) reverse_rel.status = STATUS_TYPE.get(APPROVED) reverse_rel.update_record() elif rel_status is None: # and rel_status != "REVERSE_BLOCKED" Relationship( from_user=logged_user.id, to_user=to_user.id, rel_type=RELATIONSHIP_TYPE.get(FRIENDS), status=STATUS_TYPE.get(PENDING) ).save_database() # email the user body_html = render_template( 'mail/relationship/added_friend.html', from_user=logged_user, to_user=to_user, ) body_text = render_template( 'mail/relationship/added_friend.txt', from_user=logged_user, to_user=to_user, ) email(to_user.email, ("%s has requested to be friends") % logged_user.first_name, body_html, body_text) if ref: return redirect(ref) else: return redirect(url_for('user_blueprint.profile', username=to_user.username)) else: abort(404)
def block(username): logged_user, to_user = _get_requesting_user_and_logged_in_user_obj( username) if to_user and logged_user: Relationship.delete_connection_between_users(to_user, logged_user) Relationship(from_user=logged_user, to_user=to_user, relationship_type=Relationship.BLOCKED, status=Relationship.APPROVED).save() return _redirect_to_referred_url_if_safe(username) abort(404)
def add_friend(to_username): ref = request.referrer logged_user = User.objects.filter(username=session.get('username')).first() to_user = User.objects.filter(username=to_username).first() if to_user: rel = Relationship.get_relationship(logged_user, to_user) to_username = to_user.username if rel == "REVERSE_FRIENDS_PENDING": Relationship( from_user=logged_user, to_user=to_user, rel_type=Relationship.FRIENDS, status=Relationship.APPROVED ).save() reverse_rel = Relationship.objects.get( from_user=to_user, to_user=logged_user) reverse_rel.status = Relationship.APPROVED reverse_rel.save() elif rel == None and rel != "REVERSE_BLOCKED": Relationship( from_user=logged_user, to_user=to_user, rel_type=Relationship.FRIENDS, status=Relationship.PENDING ).save() # email the user body_html = render_template( 'mail/relationship/added_friend.html', from_user=logged_user, to_user=to_user, ) body_text = render_template( 'mail/relationship/added_friend.txt', from_user=logged_user, to_user=to_user, ) email(to_user.email, ("%s has requested to be friends") % logged_user.first_name, body_html, body_text) if ref: return redirect(ref) else: return redirect(url_for('user_app.profile', username=to_user.username)) else: abort(404)
def _get_relationship_between_logged_user_and_viewing_user_profile(user): username = Session.get_session_by_name("username") if username: logged_user = User.objects.filter(username=username).first() return Relationship.get_relationship(logged_user, user)
def block(to_username): ref = request.referrer logged_user = User.objects.filter(username=session.get('username')).first() to_user = User.objects.filter(username=to_username).first() if to_user: rel = Relationship.get_relationship(logged_user, to_user) to_username = to_user.username if rel == "FRIENDS_PENDING" or rel == "FRIENDS_APPROVED" or rel == "REVERSE_FRIENDS_PENDING": rel = Relationship.objects.filter( from_user=logged_user, to_user=to_user).delete() reverse_rel = Relationship.objects.filter( from_user=to_user, to_user=logged_user).delete() Relationship( from_user=logged_user, to_user=to_user, rel_type=Relationship.BLOCKED, status=Relationship.APPROVED ).save() if ref: return redirect(ref) else: return redirect(url_for('user_app.profile', username=to_user.username)) else: abort(404)
def add_friend(to_username): ref = request.referrer logged_user = User.objects.filter(username=session.get("username")).first() to_user = User.objects.filter(username=to_username).first() if to_user: rel = Relationship.get_relationship(logged_user, to_user) to_username = to_user.username if rel == "REVERSE_FRIENDS_PENDING": # Person has requested you a friendship and waiting on you Relationship(from_user=logged_user, to_user=to_user, rel_type=Relationship.FRIENDS, status=Relationship.APPROVED).save() reverse_rel = Relationship.objects.get(from_user=to_user, to_user=logged_user) reverse_rel.status = Relationship.APPROVED reverse_rel.save() elif rel == None and rel != "REVERSE_BLOCKED": Relationship(from_user=logged_user, to_user=to_user, rel_type=Relationship.FRIENDS, status=Relationship.PENDING).save() # Email the user body_html = render_template( "mail/relationship/added_friend.html", from_user=logged_user, to_user=to_user, ) body_text = render_template( "mail/relationship/added_friend.txt", from_user=logged_user, to_user=to_user, ) email( to_user.email, "{0} has requested to be friends".format( logged_user.first_name), body_html, body_text) if ref: return redirect(ref) else: return redirect( url_for("user_app.profile", username=to_user.username)) else: abort(404)
def connect(request,object_id): '''用户(身份病人)发送connect请求''' result = {} data = json.loads(request.POST['data']) msg = data['msg'] msg = msg.strip() receiver = User.objects.filter(id=object_id) dentistuser = receiver[0] patient = request.user DentistProfileObj = DentistProfile.objects.get(user=dentistuser) PatientProfileObj = PatientProfile.objects.get(user=request.user) try: RelationshipObj = Relationship.objects.get(patient = PatientProfileObj,dentist = DentistProfileObj) if RelationshipObj.status == 0: RelationshipObj.status=1 RelationshipObj.save() relation_type_object = ContentType.objects.get(model='relationship') Event.objects.filter(user=patient, content_type=relation_type_object, object_id=RelationshipObj.id).update(message=msg) result = { "msg":"Success", "status":1, } except: RelationshipNew = Relationship(patient = PatientProfileObj,dentist = DentistProfileObj,status = 1) RelationshipNew.save() relation_type_object = ContentType.objects.get(model='relationship') Event.objects.filter(user=patient, content_type=relation_type_object, object_id=RelationshipNew.id).update(message=msg) result = { "msg":"Success", "status":1, } return result
def _is_there_relationship_between_users(logged_user, to_user): relationship_type = Relationship.get_relationship(logged_user, to_user) return relationship_type == constants.PENDING_REQUEST or \ relationship_type == constants.FRIEND_APPROVED or \ relationship_type == constants.REVERSED_BLOCK or \ relationship_type == constants.REVERSE_PENDING_FRIEND_REQUEST or \ relationship_type == constants.FRIENDS_PENDING or constants.BLOCKED
def unblock(to_username): ref = request.referrer logged_user = User.getByName(session.get('username')) to_user = User.getByName(to_username) if to_user: rel_status = Relationship.get_relationship_status(logged_user.id, to_user.id) if rel_status == "BLOCKED": rel = Relationship.get_relationship(logged_user.id, to_user.id) rel.delete_record() if ref: return redirect(ref) else: return redirect(url_for('user_blueprint.profile', username=to_user.username)) else: abort(404)
def add_friend(username): logged_user, to_user = _get_requesting_user_and_logged_in_user_obj( username) if to_user: relationship = Relationship.get_relationship(logged_user, to_user) if relationship == constants.REVERSE_PENDING_FRIEND_REQUEST: _save_approved_relationship_to_database(logged_user, to_user) elif relationship is None and relationship != constants.REVERSED_BLOCK: Relationship(from_user=logged_user, to_user=to_user, relationship_type=Relationship.FRIENDS, status=Relationship.PENDING).save() _email_user_about_friend_request(logged_user, to_user) return _redirect_to_referred_url_if_safe(username) abort(404)
def _save_approved_relationship_to_database(logged_user, to_user): Relationship(from_user=logged_user, to_user=to_user, relationship_type=Relationship.FRIENDS, status=Relationship.APPROVED).save() reversed_relationship = Relationship.objects.get(from_user=to_user, to_user=logged_user) reversed_relationship.status = Relationship.APPROVED reversed_relationship.save()
def post_message_to_all_friends_feeds(self): friends = self._get_all_my_friends_obj() for friend in friends: rel_status = Relationship.get_relationship( friend.to_user, self._message_obj.to_user) if rel_status != constants.BLOCKED: Feed(user=friend.to_user, message=self._message_obj).save() return True
def Unblock(to_username): logged_user = User.objects.filter(username=session.get('username')).first() to_user = User.objects.filter(username=to_username).first() if to_user: rel = Relationship.get_relationship(logged_user, to_user) if rel == "BLOCKED": rel = Relationship.objects.filter(from_user=logged_user, to_user=to_user).delete() return redirect(url_for('user_app.profile', username=to_username)) else: abort(404)
def profile(username): edit_profile = False rel = None user = User.objects.filter(username=username).first() if user.username == session.get('username') and session.get('username'): edit_profile = True if user: if session.get('username'): logged_user = User.objects.filter(username=session.get('username')).first() rel = Relationship.get_relationship(logged_user, user) return render_template('user/profile.html', user=user, rel=rel, edit_profile=edit_profile) else: abort(404)
def process_message(message): # Get the from users friends from_user = message.from_user friends = Relationship.objects.filter(from_user=from_user, rel_type=Relationship.FRIENDS, status=Relationship.APPROVED) for friend in friends: rel = Relationship.get_relationship(friend.to_user, message.to_user) if rel != 'BLOCKED': feed = Feed(user=friend.to_user, message=message).save() return True
def add_friend(to_username): ref = request.referrer logged_user = User.objects.filter(username=session.get('username')).first() to_user = User.objects.filter(username=to_username).first() if to_user: rel = Relationship.get_relationship(logged_user, to_user) to_username = to_user.username if rel == "REVERSE_FRIENDS_PENDING": Relationship( from_user=logged_user, to_user=to_user, rel_type=Relationship.FRIENDS, status=Relationship.APPROVED ).save() reverse_rel = Relationship.objects.get( from_user=to_user, to_user=logged_user) reverse_rel.status=Relationship.APPROVED reverse_rel.save() elif rel == None and rel != "REVERSE_BLOCKED": Relationship( from_user=logged_user, to_user=to_user, rel_type=Relationship.FRIENDS, status=Relationship.PENDING ).save() # email the user body_html = render_template( 'mail/relationship/added_friend.html', from_user=logged_user, to_user=to_user, ) body_text = render_template( 'mail/relationship/added_friend.txt', from_user=logged_user, to_user=to_user, ) email(to_user.email, ("%s has requested to be friends") % logged_user.first_name, body_html, body_text) if ref: return redirect(ref) else: return redirect(url_for('user_app.profile', username=to_user.username)) else: abort(404)
def remove_friend(to_username): logged_user = User.objects.filter(username=session.get('username')).first() to_user = User.objects.filter(username=to_username).first() if to_user: rel = Relationship.get_relationship(logged_user, to_user) to_username = to_user.username if rel == "FRIENDS_PENDING" or rel == "FRIENDS_APPROVED" or rel == "REVERSE_FRIENDS_PENDING": rel = Relationship.objects.filter(from_user=logged_user, to_user=to_user).delete() reverse_rel = Relationship.objects.filter( from_user=to_user, to_user=logged_user).delete() return redirect(url_for('user_app.profile', username=to_username)) else: abort(404)
def process_message(message): # get the from_user friends from_user = User.getById(message.from_user) friends = Relationship.get_friends(user=from_user.id, rel_type=RELATIONSHIP_TYPE.get(FRIENDS), status=STATUS_TYPE.get(APPROVED)) """ Fan out pattern: means that each user have a list of posts of users that are friends with him (friends_approved). So each user have it's feed. NB: Fan out pattern is Scalable. """ # get the from_user's friends for friend in friends: rel_status = Relationship.get_relationship_status( friend.to_user, message.to_user) if rel_status != "BLOCKED": Feed( user=friend.to_user, message=message.id, ).save_database() return True
def remove_friend(to_username): ref = request.referrer logged_user = User.getByName(session.get('username')) to_user = User.getByName(to_username) if to_user: rel_status = Relationship.get_relationship_status(logged_user.id, to_user.id) if rel_status == "FRIENDS_PENDING" \ or rel_status == "FRIENDS_APPROVED" \ or rel_status == "REVERSE_FRIENDS_PENDING": rel = Relationship.get_relationship(logged_user.id, to_user.id) rel.delete_record() reverse_rel = Relationship.get_relationship(to_user.id, logged_user.id) if reverse_rel: reverse_rel.delete_record() if ref: return redirect(ref) else: return redirect(url_for('user_blueprint.profile', username=to_user.username)) else: abort(404)
def profile(username, friends_page_number=1): # Removed everything with edit_profile variable because it isn't needed logged_user = None rel = None friends_page = False user = User.objects.filter(username=username).first() profile_messages = [] if user: if session.get("username"): logged_user = User.objects.filter(username=session.get("username")).first() rel=Relationship.get_relationship(logged_user, user) # Get friends friends = Relationship.objects.filter( from_user=user, rel_type=Relationship.FRIENDS, status=Relationship.APPROVED ) friends_total = friends.count() if "friends" in request.url: friends_page = True friends = friends.paginate(page=friends_page_number, per_page=3) # paginate is a mongoengine helper else: friends = friends[:5] form = FeedPostForm() # Get user messages if friends or self if logged_user and (rel == "SAME" or rel == "FRIENDS_APPROVED"): profile_messages = Message.objects.filter( Q(from_user=user) | Q(to_user=user), message_type=POST ).order_by("-create_date")[:10] return render_template("user/profile.html", user=user, rel=rel, logged_user=logged_user, friends=friends, friends_total=friends_total, friends_page=friends_page, form=form, profile_messages=profile_messages, ) else: # Don't find the user abort(404)
def profile(username, friends_page_number=1): logged_user = None edit_profile = False rel = None friends_page = False user = User.objects.filter(username=username).first() if user: if session.get('username'): logged_user = User.objects.filter( username=session.get('username')).first() rel = Relationship.get_relationship(logged_user, user) if session.get('username') and user.username == session.get( 'username'): edit_profile = True # get friends friends = Relationship.objects.filter(from_user=user, rel_type=Relationship.FRIENDS, status=Relationship.APPROVED) friends_total = friends.count() if 'friends' in request.url: friends_page = True friends = friends.paginate(page=friends_page_number, per_page=3) else: friends = friends[:5] form = FeedPostForm() # get user messages profile_messages = Message.objects.filter( Q(from_user=user) | Q(to_user=user)).order_by('-create_date')[:10] return render_template('user/profile.html', user=user, logged_user=logged_user, rel=rel, edit_profile=edit_profile, friends=friends, friends_total=friends_total, friends_page=friends_page, form=form, profile_messages=profile_messages, images=None) else: abort(404)
def profile(username, friends_page_number=1): logged_user = None rel = None friends_page = False user = User.objects.filter(username=username).first() profile_messages = [] if user: if session.get('username'): logged_user = User.objects.filter(username=session.get('username')).first() rel = Relationship.get_relationship(logged_user, user) # get friends friends = Relationship.objects.filter( from_user=user, rel_type=Relationship.FRIENDS, status=Relationship.APPROVED ) friends_total = friends.count() if 'friends' in request.url: friends_page = True friends = friends.paginate(page=friends_page_number, per_page=3) else: friends = friends[:5] form = FeedPostForm() # get user messages if friends or self if logged_user and (rel == "SAME" or rel == "FRIENDS_APPROVED"): profile_messages = Message.objects.filter( Q(from_user=user) | Q(to_user=user), message_type=POST ).order_by('-create_date')[:10] return render_template('user/profile.html', user=user, logged_user=logged_user, rel=rel, friends=friends, friends_total=friends_total, friends_page=friends_page, form=form, profile_messages=profile_messages ) else: abort(404)
def profile(username, friends_page_number=1): logged_user = None rel = None friends_page = None user = User.objects.filter(username=username).first() profile_messages = [] if user: if session.get('username'): logged_user = User.objects.filter( username=session.get('username')).first() rel = Relationship.get_relationship(logged_user, user) # Get friends friends = Relationship.objects.filter( from_user=user, rel_type=Relationship.FRIENDS, status=Relationship.APPROVED) friends_total = friends.count() if 'friends' in request.url: friends_page = True friends = friends.paginate(page=page, per_page=3) else: friends = friends[:5] form = FeedPostForm() # Get user messages if friends or self if logged_user and (rel == "SAME" or rel == "FRIENDS_APPROVED"): profile_messages = Message.objects.filter( Q(from_user=user) | Q(to_user=user), message_type=POST).order_by('-create_date')[:10] return render_template('user/profile.html', user=user, logged_user=logged_user, rel=rel, friends=friends, friends_total=friends_total, friends_page=friends_page, form=form, profile_messages=profile_messages) else: abort(404)
def unblock(to_username): ref = request.referrer logged_user = User.objects.filter(username=session.get("username")).first() to_user = User.objects.filter(username=to_username).first() if to_user: rel = Relationship.get_relationship(logged_user, to_user) to_username = to_user.username if rel == "BLOCKED": rel = Relationship.objects.filter(from_user=logged_user, to_user=to_user).delete() if ref: return redirect(ref) else: return redirect( url_for("user_app.profile", username=to_user.username)) else: abort(404)
def process_message(message): # get the from_user's friends from_user = message.from_user friends = Relationship.objects.filter( from_user=from_user, rel_type=Relationship.FRIENDS, status=Relationship.APPROVED ) # get the from_user's friends for friend in friends: rel = Relationship.get_relationship(friend.to_user, message.to_user) if rel != "BLOCKED": feed = Feed( user=friend.to_user, message=message ).save() return True
def process_message(message): ## get from user's friends and broadcast message ## to all his friends # get the from_user's friends from_user = message.from_user friends = Relationship.objects.filter(from_user=from_user, rel_type=Relationship.FRIENDS, status=Relationship.APPROVED) for friend in friends: # post on all of friends feeds the message # except if to_user is blocked rel = Relationship.get_relationship(friend.to_user, message.to_user) if rel != "BLOCKED": feed = Feed(user=friend.to_user, message=message).save() return True
def profile(username): logged_user = None edit_profile = False rel = None user = User.objects.filter(username=username).first() profile_messages = [] if user: if session.get('username'): # compare relationship between user being looked at and user that is logged in logged_user = User.objects.filter( username=session.get('username')).first() rel = Relationship.get_relationship(logged_user, user) if user.username == session.get( 'username'): #if user is looking at his own profile page edit_profile = True #get friends friends = Relationship.objects.filter(from_user=user, rel_type=Relationship.FRIENDS, status=Relationship.APPROVED) friends_total = friends.count() if 'friends' in request.url: friends_page = True friends = friends.paginate(page=page, per_page=3) else: friends = friends[:5] form = FeedPostForm() return render_template('user/profile.html', user=user, logged_user=logged_user, rel=rel, edit_profile=edit_profile, friends=friends, friends_total=friends_total, form=form) else: abort(404)
def unblock(to_username): ref = request.referrer logged_user = User.objects.filter(username=session.get('username')).first() to_user = User.objects.filter(username=to_username).first() if to_user: rel = Relationship.get_relationship(logged_user, to_user) to_username = to_user.username if rel == "BLOCKED": rel = Relationship.objects.filter( from_user=logged_user, to_user=to_user).delete() if ref: return redirect(ref) else: return redirect(url_for('user_app.profile', username=to_user.username)) else: abort(404)
def profile(username, page=1): logged_user = None edit_profile = False rel = None friends_page = False user = User.objects.filter(username=username).first() if user: if session.get('username'): logged_user = User.objects.filter( username=session.get('username')).first() rel = Relationship.get_relationship(logged_user, user) if session.get('username') and user.username == session.get( 'username'): edit_profile = True # get friends friends = Relationship.objects.filter(from_user=user, rel_type=Relationship.FRIENDS, status=Relationship.APPROVED) friends_total = friends.count() if 'friends' in request.url: friends_page = True friends = friends.paginate(page=page, per_page=3) else: friends = friends[:5] return render_template( 'user/profile.html', user=user, logged_user=logged_user, rel=rel, edit_profile=edit_profile, friends=friends, friends_total=friends_total, friends_page=friends_page, ) else: abort(404)