def intro(request): if request.me.moderation_status == User.MODERATION_STATUS_APPROVED: return redirect("profile", request.me.slug) if request.method == "POST": form = UserIntroForm(request.POST, request.FILES, instance=request.me) if form.is_valid(): user = form.save(commit=False) # send to moderation user.moderation_status = User.MODERATION_STATUS_ON_REVIEW user.save() # create intro post intro_post = Post.upsert_user_intro(user, form.cleaned_data["intro"], is_visible=False) Geo.update_for_user(user) # notify moderators to review profile async_task(notify_profile_needs_review, user, intro_post) return redirect("on_review") else: existing_intro = Post.get_user_intro(request.me) form = UserIntroForm( instance=request.me, initial={"intro": existing_intro.text if existing_intro else ""}, ) return render(request, "users/intro.html", {"form": form})
def handle(self, *args, **options): users = User.objects.filter( moderation_status=User.MODERATION_STATUS_ON_REVIEW) for user in users: intro = Post.get_user_intro(user) notify_profile_needs_review(user, intro) self.stdout.write("Done 🥙")
def profile(request, user_slug): if user_slug == "me": return redirect("profile", request.me.slug, permanent=False) user = get_object_or_404(User, slug=user_slug) if not request.me.is_moderator: # hide unverified and deleted users if user.moderation_status != User.MODERATION_STATUS_APPROVED or user.deleted_at: raise Http404() # handle auth redirect if user.id == request.me.id: goto = request.GET.get("goto") if goto and goto.startswith(settings.APP_HOST): return redirect(goto) tags = Tag.objects.filter(is_visible=True).all() intro = Post.get_user_intro(user) projects = Post.objects.filter(author=user, type=Post.TYPE_PROJECT, is_visible=True).all() # select user tags and calculate similarity with me active_tags = {t.tag_id for t in UserTag.objects.filter(user=user).all()} similarity = {} if user.id != request.me.id: my_tags = {t.tag_id for t in UserTag.objects.filter(user=request.me).all()} similarity = calculate_similarity(my_tags, active_tags, tags) achievements = UserAchievement.objects.filter(user=user).select_related("achievement") expertises = UserExpertise.objects.filter(user=user).all() comments = Comment.visible_objects()\ .filter(author=user, post__is_visible=True)\ .order_by("-created_at")\ .select_related("post") posts = Post.objects_for_user(request.me)\ .filter(author=user, is_visible=True)\ .exclude(type__in=[Post.TYPE_INTRO, Post.TYPE_PROJECT, Post.TYPE_WEEKLY_DIGEST])\ .order_by("-published_at") return render(request, "users/profile.html", { "user": user, "intro": intro, "projects": projects, "tags": tags, "active_tags": active_tags, "achievements": [ua.achievement for ua in achievements], "expertises": expertises, "comments": comments[:3], "comments_total": comments.count(), "posts": posts[:15], "posts_total": posts.count(), "similarity": similarity, })
def profile(request, user_slug): if user_slug == "me": return redirect("profile", request.me.slug, permanent=False) user = get_object_or_404(User, slug=user_slug) if not request.me.is_moderator: # hide unverified users if user.moderation_status != User.MODERATION_STATUS_APPROVED: raise Http404() if user.id == request.me.id: goto = request.GET.get("goto") if goto and goto.startswith(settings.APP_HOST): return redirect(goto) tags = Tag.objects.filter(is_visible=True).all() intro = Post.get_user_intro(user) projects = Post.objects.filter(author=user, type=Post.TYPE_PROJECT, is_visible=True).all() active_tags = {t.tag_id for t in UserTag.objects.filter(user=user).all()} achievements = UserAchievement.objects.filter( user=user).select_related("achievement") expertises = UserExpertise.objects.filter(user=user).all() comments = Comment.visible_objects().filter( author=user, post__is_visible=True).order_by("-created_at")[:3] posts = Post.objects_for_user(request.me)\ .filter(author=user, is_visible=True)\ .exclude(type__in=[Post.TYPE_INTRO, Post.TYPE_PROJECT]) return render( request, "users/profile.html", { "user": user, "intro": intro, "projects": projects, "tags": tags, "active_tags": active_tags, "achievements": [ua.achievement for ua in achievements], "expertises": expertises, "comments": comments, "posts": paginate(request, posts), })