|
1 | 1 | import re |
2 | 2 | import time |
| 3 | +from random import random, shuffle |
3 | 4 |
|
4 | 5 | from django.conf import settings |
5 | 6 | from django.contrib import messages |
| 7 | +from django.contrib.auth.decorators import login_required |
6 | 8 | from django.http import Http404, JsonResponse |
7 | 9 | from django.shortcuts import get_object_or_404, redirect, render |
8 | 10 | from django.template.response import TemplateResponse |
9 | 11 | from django.utils import timezone |
10 | 12 |
|
11 | 13 | import metadata_parser |
| 14 | +from django.views.decorators.csrf import csrf_exempt |
| 15 | +from django.views.decorators.http import require_http_methods |
| 16 | + |
12 | 17 | from app.services import RedisService |
13 | 18 | from dashboard.helpers import load_files_in_directory |
14 | 19 | from dashboard.models import ( |
@@ -299,11 +304,33 @@ def get_param_metadata(request, tab): |
299 | 304 | return title, desc, page_seo_text_insert, avatar_url, is_direct_link, admin_link |
300 | 305 |
|
301 | 306 |
|
| 307 | +@login_required |
| 308 | +@require_http_methods(['PUT']) |
| 309 | +@csrf_exempt |
| 310 | +def ignored_suggested_tribe(request, tribeId): |
| 311 | + profile = request.user.profile |
| 312 | + tribe_profile = get_object_or_404(Profile, handle__iexact=tribeId) |
| 313 | + |
| 314 | + profile.ignore_tribes.add(tribe_profile) |
| 315 | + |
| 316 | + return JsonResponse({ |
| 317 | + 'tribes': get_suggested_tribes(request) |
| 318 | + }) |
| 319 | + |
| 320 | + |
302 | 321 | def get_suggested_tribes(request): |
303 | 322 | following_tribes = [] |
304 | 323 | if request.user.is_authenticated: |
305 | | - handles = TribeMember.objects.filter(profile=request.user.profile).distinct('org').values_list('org__handle', flat=True) |
306 | | - tribes = Profile.objects.filter(is_org=True).exclude(handle__in=list(handles)).order_by('-follower_count')[:5] |
| 324 | + profile = request.user.profile |
| 325 | + ignore = list(profile.ignore_tribes.all().values_list('pk', flat=True)) |
| 326 | + handles = TribeMember.objects.filter(profile=profile).distinct('org').values_list('org__handle', flat=True) |
| 327 | + tribes = Profile.objects.filter(is_org=True).exclude(handle__in=list(handles)).exclude(pk__in=ignore).order_by('-follower_count') |
| 328 | + count = tribes.count() |
| 329 | + |
| 330 | + if count > 5: |
| 331 | + index_shuffle = list(range(count if count < 60 else 60)) |
| 332 | + shuffle(index_shuffle) |
| 333 | + tribes = [tribes[index] for index in index_shuffle[:5]] |
307 | 334 |
|
308 | 335 | for profile in tribes: |
309 | 336 | handle = profile.handle |
|
0 commit comments