Skip to content

Commit

Permalink
Merge branch 'omaster'
Browse files Browse the repository at this point in the history
  • Loading branch information
evgenyfadeev committed Feb 8, 2024
2 parents f4897d4 + 3dc1838 commit c6b1565
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion askbot/jinja2/question/answers_sort_nav.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="answers-header">
<h2 class"js-answers-count">
<h2 class="js-answers-count">
{% set pluralized_item_term=settings.WORDS_ANSWERS_COUNTABLE_FORMS|py_pluralize(answer_count)|capitalize|escape %}
{% set item_count=answer_count %}
{% trans %}<span class="count">{{ item_count }}</span> {{ pluralized_item_term }}{% endtrans %}
Expand Down
1 change: 1 addition & 0 deletions askbot/media/jslib/htmx.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions askbot/startup_procedures.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from django.core.cache import cache
from django.core.exceptions import ImproperlyConfigured
from django.utils import timezone
from askbot.utils.loading import load_module
from askbot.utils.loading import load_function, load_module
from askbot.utils.functions import enumerate_string_list
from askbot.utils.url_utils import urls_equal

Expand Down Expand Up @@ -711,9 +711,9 @@ def test_custom_user_profile_tab():
"%s['SLUG'] must be url safe, make it simple" % setting_name)

try:
func = load_module(func_name)
func = load_function(func_name)
except ImportError:
errors.append("%s['CONTENT_GENERATOR'] must be a dotted path to a function" % setting_name)
errors.append("%s['CONTEXT_GENERATOR'] must be a dotted path to a function" % setting_name)
header = 'Custom user profile tab is configured incorrectly in your settings.py file'
footer = 'Please carefully read about adding a custom user profile tab.'
print_errors(errors, header=header, footer=footer)
Expand Down
30 changes: 22 additions & 8 deletions askbot/views/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
from askbot.search.state_manager import SearchState
from askbot.utils.http import get_request_params
from askbot.utils import url_utils
from askbot.utils.loading import load_module
from askbot.utils.loading import load_function
from askbot import spam_checker

def owner_or_moderator_required(func):
Expand Down Expand Up @@ -1400,8 +1400,8 @@ def user_custom_tab(request, user, context):
"""works only if `ASKBOT_CUSTOM_USER_PROFILE_TAB`
setting in the ``settings.py`` is properly configured"""
tab_settings = django_settings.ASKBOT_CUSTOM_USER_PROFILE_TAB
module_path = tab_settings['CONTEXT_GENERATOR']
context_generator = load_module(module_path)
func_python_path = tab_settings['CONTEXT_GENERATOR']
context_generator = load_function(func_python_path)

page_title = _('profile - %(section)s') % \
{'section': tab_settings['NAME']}
Expand All @@ -1427,9 +1427,23 @@ def user_custom_tab(request, user, context):
}

CUSTOM_TAB = getattr(django_settings, 'ASKBOT_CUSTOM_USER_PROFILE_TAB', None)
if CUSTOM_TAB:
CUSTOM_SLUG = CUSTOM_TAB['SLUG']
USER_VIEW_CALL_TABLE[CUSTOM_SLUG] = user_custom_tab


def user_can_see_custom_tab(request):
auth_func = CUSTOM_TAB.get('USER_IS_AUTHORIZED_FUNC')
return not auth_func or auth_func(request.user)


def get_user_view_func(request, tab_name, default_func=user_stats):
"""returns a view function for the user profile page"""
func = USER_VIEW_CALL_TABLE.get(tab_name)
if func:
return func

if CUSTOM_TAB and tab_name == CUSTOM_TAB['SLUG']:
if user_can_see_custom_tab(request):
return user_custom_tab
return default_func

#todo: rename this function - variable named user is everywhere
def user(request, id, slug=None, tab_name=None):
Expand Down Expand Up @@ -1468,7 +1482,7 @@ def user(request, id, slug=None, tab_name=None):
if can_show_karma == False and tab_name == 'reputation':
raise Http404

user_view_func = USER_VIEW_CALL_TABLE.get(tab_name, user_stats)
user_view_func = get_user_view_func(request, tab_name, default_func=user_stats)

search_state = SearchState(
scope=None,
Expand All @@ -1487,7 +1501,7 @@ def user(request, id, slug=None, tab_name=None):
'search_state': search_state,
'user_follow_feature_on': ('followit' in django_settings.INSTALLED_APPS),
}
if CUSTOM_TAB:
if CUSTOM_TAB and user_can_see_custom_tab(request):
context['custom_tab_name'] = CUSTOM_TAB['NAME']
context['custom_tab_slug'] = CUSTOM_TAB['SLUG']
return user_view_func(request, profile_owner, context)
Expand Down

0 comments on commit c6b1565

Please sign in to comment.