aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby <[email protected]>2022-08-02 01:02:39 +0530
committerBobby <[email protected]>2022-08-02 01:02:39 +0530
commite52365a079a5fb2489a435c5ba3081d067d76ba2 (patch)
tree872d41c21b596dac47d2f41e1cae86e3f4841c99
parentd5c04b8b22199adef77052f4c01777673f752fd4 (diff)
downloadthatcomputerscientist-e52365a079a5fb2489a435c5ba3081d067d76ba2.tar.xz
thatcomputerscientist-e52365a079a5fb2489a435c5ba3081d067d76ba2.zip
Added user URLs
-rw-r--r--blog/templates/account.html5
-rw-r--r--blog/views.py8
2 files changed, 12 insertions, 1 deletions
diff --git a/blog/templates/account.html b/blog/templates/account.html
index 6e07cb6d..bf066346 100644
--- a/blog/templates/account.html
+++ b/blog/templates/account.html
@@ -11,6 +11,11 @@
<li>Please note that this is a support request related to your account. Please do not file any bugs here. If you have noticed a bug, please report it to the <a href="https://github.com/luciferreeves/thatcomputerscientist/issues">GitHub Issues</a> page.</li>
</ul>
<p>Your avatar is fetched from gravatar. Update your gravatar email to fetch the avatar. If you don't have an account, you can sign up for one <a href="https://en.gravatar.com/" target="_blank">here</a>. If you haven't set up your gravatar email, we would try to fetch your profile picture from your account email, by default. If your account email and gravatar email are the same, you do not need to set a gravatar email.</p>
+ {% if user_subdomain_url %}
+ <div class="alert" style="padding: 0 10px">
+ <p>Your account is publicly accessible at <a href="{{ user_subdomain_url }}">{{ user_subdomain_url }}</a>. If you wish to change your account to private, you can do so below.</p>
+ </div>
+ {% endif %}
{% for message in messages %}
<div class="alert {{message.tags}}">
<p>{{ message }}</p>
diff --git a/blog/views.py b/blog/views.py
index 28e8c893..ff41dc40 100644
--- a/blog/views.py
+++ b/blog/views.py
@@ -1,5 +1,6 @@
from django.shortcuts import render, redirect
from users.models import UserProfile
+from urllib.parse import urlparse
import hashlib
# Create your views here.
@@ -13,10 +14,15 @@ def account(request):
try:
user_profile = UserProfile.objects.get(user=user)
avatar = hashlib.md5(str(user_profile.gravatar_email).lower().encode('utf-8')).hexdigest() if user_profile.gravatar_email else hashlib.md5(str(user.email).lower().encode()).hexdigest()
+ user_subdomain_url = None
+ if user_profile.is_public:
+ scheme = urlparse(request.build_absolute_uri()).scheme
+ domain = urlparse(request.build_absolute_uri()).netloc
+ user_subdomain_url = '{}://{}.{}'.format(scheme, user.username, domain)
except UserProfile.DoesNotExist:
user_profile = None
avatar = hashlib.md5(str(user.email).lower().encode()).hexdigest()
- return render(request, 'account.html', {'title': 'Account', 'user_profile': user_profile, 'avatar': avatar})
+ return render(request, 'account.html', {'title': 'Account', 'user_profile': user_profile, 'avatar': avatar, 'user_subdomain_url': user_subdomain_url})
else:
# Redirect to login page
return redirect('/')