Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gitcoin.co/profile/owocki => gitcoin.co/owocki #5278

Merged
merged 8 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/app/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def preprocess(request):
'is_moderator': profile.is_moderator if profile else False,
'persona_is_funder': profile.persona_is_funder if profile else False,
'persona_is_hunter': profile.persona_is_hunter if profile else False,
'profile_url': profile.url if profile else False,
'quests_live': settings.QUESTS_LIVE,
}
context['json_context'] = json.dumps(context)
Expand Down
5 changes: 5 additions & 0 deletions app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,11 @@
re_path(r'^500/$', retail.views.handler500, name='500'),
]

urlpatterns += [
re_path(r'^(.*)/(.*)?', dashboard.views.profile, name='profile_min_by_tab'),
re_path(r'^(.*)', dashboard.views.profile, name='profile_min'),
]

handler403 = 'retail.views.handler403'
handler404 = 'retail.views.handler404'
handler500 = 'retail.views.handler500'
Expand Down
4 changes: 2 additions & 2 deletions app/assets/v2/js/pages/quests.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ $(document).ready(function() {
$('.difficulty_tab.' + target).removeClass('hidden');

$('html,body').animate({
scrollTop: '+=1px'
})
scrollTop: '+=1px'
});
});

$('.quest-card.available').click(function(e) {
Expand Down
7 changes: 6 additions & 1 deletion app/dashboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3138,7 +3138,12 @@ def __str__(self):
return self.handle

def get_relative_url(self, preceding_slash=True):
return f"{'/' if preceding_slash else ''}profile/{self.handle}"
from dashboard.utils import get_url_first_indexes # avoid circular import
prefix = ''
if self.handle in get_url_first_indexes():
# handle collision
prefix = 'profile/'
return f"{'/' if preceding_slash else ''}{prefix}{self.handle}"

def get_absolute_url(self):
return settings.BASE_URL + self.get_relative_url(preceding_slash=False)
Expand Down
3 changes: 3 additions & 0 deletions app/dashboard/templates/profiles/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
{% endif %}
{% include 'shared/head.html' %}
{% include 'shared/cards_pic.html' %}
{% if not hidden %}
<link rel="canonical" href="{{profile.url}}/{{tab}}" />
{% endif %}
<link rel="stylesheet" href={% static "v2/css/dashboard.css" %} />
<link rel="stylesheet" href={% static "v2/css/profile.css" %} />
<link rel="stylesheet" href={% static "v2/css/tag.css" %} />
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/templates/shared/nav_auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
{% trans "Send Kudos" %}
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" data-gtm="profile" href="{% url "profile" %}">
<a class="dropdown-item" data-gtm="profile" href="{{profile_url}}">
<i class="fas fa-user"></i>
{% trans "My Profile" %}
</a>
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/tests/test_dashboard_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def test_profile():
assert profile.tips.first() == tip
assert profile.desc == '@gitcoinco is a organization who has participated in 1 funded issue on Gitcoin'
assert profile.github_url == 'https://github.com/gitcoinco'
assert profile.get_relative_url() == '/profile/gitcoinco'
assert profile.get_relative_url() == '/gitcoinco'

def test_tool(self):
"""Test the dashboard Tool model."""
Expand Down
26 changes: 26 additions & 0 deletions app/dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from json.decoder import JSONDecodeError

from django.conf import settings
from django.urls import URLPattern, URLResolver
from django.utils import timezone

import ipfshttpclient
Expand Down Expand Up @@ -896,3 +897,28 @@ def release_bounty_to_the_public(bounty, auto_save = True):
return True
else:
return False


def get_url_first_indexes():

urlconf = __import__(settings.ROOT_URLCONF, {}, {}, [''])

def list_urls(lis, acc=None):
if acc is None:
acc = []
if not lis:
return
l = lis[0]
if isinstance(l, URLPattern):
yield acc + [str(l.pattern)]
elif isinstance(l, URLResolver):
yield from list_urls(l.url_patterns, acc + [str(l.pattern)])

yield from list_urls(lis[1:], acc)

urls = []
for p in list_urls(urlconf.urlpatterns):
url = ''.join(p).split('/')[0].replace('^', '').replace('\\', '').replace('\$', '')
urls += url

return set(urls)