def view_myprofile(request): user = request.user user_participations = get_user_participations(user).order_by( "challenge__start_date") user_participations_action_required = user_participations.filter( status=PARTICIPATION_STATE.WAITING_FOR_SELFREFLECTION ) user_participations_upcoming = user_participations.filter( challenge__status=CHALLENGE_STATUS.UPCOMING, status__in=[ PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION, PARTICIPATION_STATE.CONFIRMED ]) user_participations_completed = user_participations.filter( challenge__status=CHALLENGE_STATUS.COMPLETED, status__in=[ PARTICIPATION_STATE.WAITING_FOR_ACKNOWLEDGEMENT, PARTICIPATION_STATE.ACKNOWLEDGED ]) admin_challenges = get_admin_challenges(user).order_by("start_date") admin_challenges_action_required = admin_challenges.filter( Q(pk__in=Participation.objects.filter( status__in=[ PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION, PARTICIPATION_STATE.WAITING_FOR_ACKNOWLEDGEMENT ]).values_list("challenge_id", flat=True) ) | Q( start_date__lt=datetime.date.today(), status=CHALLENGE_STATUS.UPCOMING ) ) admin_challenges_upcoming = admin_challenges.exclude( pk__in=Participation.objects.filter( status__in=[ PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION, PARTICIPATION_STATE.WAITING_FOR_ACKNOWLEDGEMENT ]).values_list("challenge_id", flat=True) ).filter( status=CHALLENGE_STATUS.UPCOMING, start_date__gte=datetime.date.today() ) admin_challenges_completed = admin_challenges.exclude( pk__in=Participation.objects.filter( status=PARTICIPATION_STATE.WAITING_FOR_ACKNOWLEDGEMENT ).values_list("challenge_id", flat=True) ).filter( status=CHALLENGE_STATUS.COMPLETED ) participations_cancelled_by_user = Participation.objects.filter( user=user, challenge__is_deleted=False, status=PARTICIPATION_STATE.CANCELLED_BY_USER, ) participations_cancelled_by_admin = Participation.objects.filter( user=user, challenge__is_deleted=False, status=PARTICIPATION_STATE.CANCELLED_BY_ADMIN, ) #TODO Enhance this behaviour try: profile = get_object_or_404(UserProfile, user=user) except: profile = None return render_to_response('account_myprofile.html', RequestContext(request, { "user": user, "profile": profile, "user_participations": [(user_participations_action_required, _("Action required")), (user_participations_upcoming, _("Upcoming")), (user_participations_completed, _("Completed")),], "admin_challenges": [(admin_challenges_action_required, _("Action required")), (admin_challenges_upcoming, _("upcoming")), (admin_challenges_completed, _("completed")),], "participations_cancelled_by_user": participations_cancelled_by_user, "participations_cancelled_by_admin": participations_cancelled_by_admin, "PARTICIPATION_STATE": PARTICIPATION_STATE, "CHALLENGE_STATUS": CHALLENGE_STATUS, }))
def view_myprofile(request): user = request.user user_participations = get_user_participations(user).order_by( "challenge__start_date") user_participations_action_required = user_participations.filter( status=PARTICIPATION_STATE.WAITING_FOR_SELFREFLECTION) user_participations_upcoming = user_participations.filter( challenge__status=CHALLENGE_STATUS.UPCOMING, status__in=[ PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION, PARTICIPATION_STATE.CONFIRMED ]) user_participations_completed = user_participations.filter( challenge__status=CHALLENGE_STATUS.COMPLETED, status__in=[ PARTICIPATION_STATE.WAITING_FOR_ACKNOWLEDGEMENT, PARTICIPATION_STATE.ACKNOWLEDGED ]) admin_challenges = get_admin_challenges(user).order_by("start_date") admin_challenges_action_required = admin_challenges.filter( Q(pk__in=Participation.objects.filter(status__in=[ PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION, PARTICIPATION_STATE.WAITING_FOR_ACKNOWLEDGEMENT ]).values_list("challenge_id", flat=True)) | Q(start_date__lt=datetime.date.today(), status=CHALLENGE_STATUS.UPCOMING)) admin_challenges_upcoming = admin_challenges.exclude( pk__in=Participation.objects.filter(status__in=[ PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION, PARTICIPATION_STATE.WAITING_FOR_ACKNOWLEDGEMENT ]).values_list("challenge_id", flat=True)).filter( status=CHALLENGE_STATUS.UPCOMING, start_date__gte=datetime.date.today()) admin_challenges_completed = admin_challenges.exclude( pk__in=Participation.objects.filter( status=PARTICIPATION_STATE.WAITING_FOR_ACKNOWLEDGEMENT). values_list("challenge_id", flat=True)).filter( status=CHALLENGE_STATUS.COMPLETED) participations_cancelled_by_user = Participation.objects.filter( user=user, challenge__is_deleted=False, status=PARTICIPATION_STATE.CANCELLED_BY_USER, ) participations_cancelled_by_admin = Participation.objects.filter( user=user, challenge__is_deleted=False, status=PARTICIPATION_STATE.CANCELLED_BY_ADMIN, ) try: profile = get_object_or_404(UserProfile, user=user) except: profile = None return render_to_response( 'account_myprofile.html', RequestContext( request, { "user": user, "profile": profile, "user_participations": [ (user_participations_action_required, _("Action required")), (user_participations_upcoming, _("Upcoming")), (user_participations_completed, _("Completed")), ], "admin_challenges": [ (admin_challenges_action_required, _("Action required")), (admin_challenges_upcoming, _("upcoming")), (admin_challenges_completed, _("completed")), ], "participations_cancelled_by_user": participations_cancelled_by_user, "participations_cancelled_by_admin": participations_cancelled_by_admin, "PARTICIPATION_STATE": PARTICIPATION_STATE, "CHALLENGE_STATUS": CHALLENGE_STATUS, }))
def view_profile(request, user_id): ctx = {} user = request.user account = get_object_or_404(User, pk=user_id) ctx.update({"account": account}) #TODO Enhance this behaviour try: profile = get_object_or_404(UserProfile, user=account) except: profile = None ctx.update({"profile": profile}) participations_current = Participation.objects.filter( user=account, challenge__is_deleted=False, status__in=[ PARTICIPATION_STATE.CONFIRMED, PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION, PARTICIPATION_STATE.WAITING_FOR_ACKNOWLEDGEMENT, PARTICIPATION_STATE.WAITING_FOR_SELFREFLECTION,] ) ctx.update({"participations_current": participations_current}) participations_acknowledged = Participation.objects.filter( user=account, challenge__is_deleted=False, status=PARTICIPATION_STATE.ACKNOWLEDGED, ) ctx.update({"participations_acknowledged": participations_acknowledged}) participations_cancelled_by_user = Participation.objects.filter( user=account, challenge__is_deleted=False, status=PARTICIPATION_STATE.CANCELLED_BY_USER, ) ctx.update({"participations_cancelled_by_user": participations_cancelled_by_user}) participations_cancelled_by_admin = Participation.objects.filter( user=account, challenge__is_deleted=False, status=PARTICIPATION_STATE.CANCELLED_BY_ADMIN, ) ctx.update({"participations_cancelled_by_admin": participations_cancelled_by_admin}) affiliated_organizations = Organization.objects.filter( affiliated_users=account, ) ctx.update({"affiliated_organizations": affiliated_organizations}) if user.is_authenticated(): admin_challenges = get_admin_challenges(user) desired_challenges = Challenge.objects.filter( pk__in=Participation.objects.filter( user=account, challenge__is_deleted=False, status=PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION ).values_list("challenge_id", flat=True)) # Related to viewer Challenges related_participated_challenges = [ participation.challenge for participation in participations_current.exclude( status=PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION ) if participation.challenge in admin_challenges] ctx.update({"related_participated_challenges": related_participated_challenges}) related_desired_challenges = [ challenge for challenge in desired_challenges if challenge in admin_challenges] ctx.update({"related_desired_challenges": related_desired_challenges}) ctx.update({"PRIVACY_MODE": PRIVACY_MODE}) return render_to_response('account_foreignprofile.html', RequestContext(request, ctx))
def view_profile(request, user_id): ctx = {} user = request.user account = get_object_or_404(User, pk=user_id) ctx.update({"account": account}) #TODO Enhance this behaviour try: profile = get_object_or_404(UserProfile, user=account) except: profile = None ctx.update({"profile": profile}) participations_current = Participation.objects.filter( user=account, challenge__is_deleted=False, status__in=[ PARTICIPATION_STATE.CONFIRMED, PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION, PARTICIPATION_STATE.WAITING_FOR_ACKNOWLEDGEMENT, PARTICIPATION_STATE.WAITING_FOR_SELFREFLECTION, ]) ctx.update({"participations_current": participations_current}) participations_acknowledged = Participation.objects.filter( user=account, challenge__is_deleted=False, status=PARTICIPATION_STATE.ACKNOWLEDGED, ) ctx.update({"participations_acknowledged": participations_acknowledged}) participations_cancelled_by_user = Participation.objects.filter( user=account, challenge__is_deleted=False, status=PARTICIPATION_STATE.CANCELLED_BY_USER, ) ctx.update( {"participations_cancelled_by_user": participations_cancelled_by_user}) participations_cancelled_by_admin = Participation.objects.filter( user=account, challenge__is_deleted=False, status=PARTICIPATION_STATE.CANCELLED_BY_ADMIN, ) ctx.update({ "participations_cancelled_by_admin": participations_cancelled_by_admin }) affiliated_organizations = Organization.objects.filter( affiliated_users=account, ) ctx.update({"affiliated_organizations": affiliated_organizations}) if user.is_authenticated(): admin_challenges = get_admin_challenges(user) desired_challenges = Challenge.objects.filter( pk__in=Participation.objects.filter( user=account, challenge__is_deleted=False, status=PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION). values_list("challenge_id", flat=True)) # Related to viewer Challenges related_participated_challenges = [ participation.challenge for participation in participations_current.exclude( status=PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION) if participation.challenge in admin_challenges ] ctx.update({ "related_participated_challenges": related_participated_challenges }) related_desired_challenges = [ challenge for challenge in desired_challenges if challenge in admin_challenges ] ctx.update({"related_desired_challenges": related_desired_challenges}) ctx.update({"PRIVACY_MODE": PRIVACY_MODE}) return render_to_response('account_foreignprofile.html', RequestContext(request, ctx))