Skip to content

Commit

Permalink
Hack in some rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Muller committed Oct 8, 2023
1 parent 0b624c4 commit e270159
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions wafer/users/templates/wafer.users/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ <h1>
</h1>
{% endblock name %}
{% block social %}
{% for tag, site_url in social_sites.items %}
<p><b>{{ tag }}</b>: {{ site_url }}</p>
{% endfor %}
{% for tag, site_url in code_sites.items %}
<p><b>{{ tag }}</b>: {{ site_url }}</p>
{% endfor %}
{% endblock social %}
{% endspaceless %}
</div>
Expand Down
22 changes: 21 additions & 1 deletion wafer/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AnonymousUser
from django.contrib.auth.models import AnonymousUser, Group
from django.core.exceptions import PermissionDenied
from django.http import Http404
from django.urls import reverse
Expand Down Expand Up @@ -91,6 +91,26 @@ def get_object(self, *args, **kwargs):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['can_edit'] = self.can_edit(context['object'])
# Add social and code profile info
group = Group.objects.get_by_natural_key('Online Profiles')

context['social_sites'] = {}
context['code_sites'] = {}

profile = self.get_object().userprofile

for field in settings.SOCIAL_MEDIA_ENTRIES:
if profile.kv.filter(group=group, key=field).exists():
value = profile.kv.get(group=group, key=field).value
if value:
context['social_sites'][settings.SOCIAL_MEDIA_ENTRIES[field]] = value

for field in settings.CODE_HOSTING_ENTRIES:
if profile.kv.filter(group=group, key=field).exists():
value = profile.kv.get(group=group, key=field).value
if value:
context['code_sites'][settings.CODE_HOSTING_ENTRIES[field]] = value

return context

def can_edit(self, user):
Expand Down

0 comments on commit e270159

Please sign in to comment.