User created communities are now sorted by posts. Some small bug fixes, changed lazy error messages.
This commit is contained in:
some weird guy
2023-08-09 12:37:48 -07:00
parent dbe93afb76
commit 46844a7cfb
5 changed files with 25 additions and 14 deletions
+1 -1
View File
@@ -87,7 +87,7 @@ class CommentAdmin(admin.ModelAdmin):
class CommunityAdmin(admin.ModelAdmin): class CommunityAdmin(admin.ModelAdmin):
raw_id_fields = ('creator', ) raw_id_fields = ('creator', )
list_display = ('id', 'name', 'description', 'type', 'creator', 'is_rm', 'is_feature', 'require_auth') list_display = ('id', 'name', 'description', 'type', 'creator', 'popularity', 'is_rm', 'is_feature', 'require_auth')
search_fields = ('id', 'unique_id', 'name', 'description', ) search_fields = ('id', 'unique_id', 'name', 'description', )
actions = [Hide_content, Show_content, Feature_community, Unfeature_community, force_login, unforce_login] actions = [Hide_content, Show_content, Feature_community, Unfeature_community, force_login, unforce_login]
def get_queryset(self, request): def get_queryset(self, request):
+5
View File
@@ -143,6 +143,7 @@ class User(models.Model):
user_agent = models.TextField(null=True, blank=True) user_agent = models.TextField(null=True, blank=True)
# C Tokens are things that let you make communities and shit. # C Tokens are things that let you make communities and shit.
c_tokens = models.IntegerField(default=1) c_tokens = models.IntegerField(default=1)
protect_data = models.BooleanField(default=False)
# Things that don't have to do with auth lol # Things that don't have to do with auth lol
hide_online = models.BooleanField(default=False) hide_online = models.BooleanField(default=False)
@@ -639,6 +640,10 @@ class Community(models.Model):
objects = PostManager() objects = PostManager()
real = models.Manager() real = models.Manager()
def popularity(self): def popularity(self):
if self.creator:
# don't count posts from the community owner.
popularity = Post.objects.filter(community=self).exclude(creator=self.creator).count()
else:
popularity = Post.objects.filter(community=self).count() popularity = Post.objects.filter(community=self).count()
return popularity return popularity
def __str__(self): def __str__(self):
@@ -74,11 +74,11 @@
{% if feature %} {% if feature %}
{% community_page_element feature "Featured Communities" True %} {% community_page_element feature "Featured Communities" True %}
{% endif %} {% endif %}
{% community_page_element general "General Communities" %} {% if general %}{% community_page_element general "General Communities" %}{% endif %}
{% community_page_element game "Game Communities" %} {% if game %}{% community_page_element game "Game Communities" %}{% endif %}
{% community_page_element special "Special Communities" %} {% if special %}{% community_page_element special "Special Communities" %}{% endif %}
{% community_page_element user_communities "Popular User-Created communities" %} {% if user_communities %}{% community_page_element user_communities "Popular User-Created Communities" %}{% endif %}
{% if my_communities %}{% community_page_element my_communities "My communities" %}{% endif %} {% if my_communities %}{% community_page_element my_communities "My Communities" %}{% endif %}
<a href="{% url "main:community-viewall" "gen" %}" class="big-button">Show more</a> <a href="{% url "main:community-viewall" "gen" %}" class="big-button">Show more</a>
</div> </div>
<div id="community-guide-footer"> <div id="community-guide-footer">
+13 -7
View File
@@ -66,7 +66,7 @@ def community_list(request):
WelcomeMSG = welcomemsg.objects.filter(show=True).order_by('-order', '-id') WelcomeMSG = welcomemsg.objects.filter(show=True).order_by('-order', '-id')
announcements = Post.objects.filter(community__tags='announcements').order_by('-id')[:6] announcements = Post.objects.filter(community__tags='announcements').order_by('-id')[:6]
if request.user.is_authenticated: if request.user.is_authenticated:
my_communities = obj.filter(type=3, creator=request.user).order_by('-created')[0:8] my_communities = obj.filter(creator=request.user).order_by('-created')[0:12]
else: else:
my_communities = None my_communities = None
return render(request, 'closedverse_main/community_list.html', { return render(request, 'closedverse_main/community_list.html', {
@@ -76,10 +76,10 @@ def community_list(request):
'WelcomeMSG': WelcomeMSG, 'WelcomeMSG': WelcomeMSG,
'availableads': availableads, 'availableads': availableads,
'classes': classes, 'classes': classes,
'general': obj.filter(type=0).order_by('-created')[0:8], 'general': obj.filter(type=0).order_by('-created')[0:12],
'game': obj.filter(type=1).order_by('-created')[0:8], 'game': obj.filter(type=1).order_by('-created')[0:12],
'special': obj.filter(type=2).order_by('-created')[0:8], 'special': obj.filter(type=2).order_by('-created')[0:12],
'user_communities': sorted(obj.filter(type=3), key=lambda x: x.popularity(), reverse=True)[0:8], 'user_communities': sorted(obj.filter(type=3), key=lambda x: x.popularity(), reverse=True)[0:12],
'my_communities': my_communities, 'my_communities': my_communities,
'feature': obj.filter(is_feature=True).order_by('-created'), 'feature': obj.filter(is_feature=True).order_by('-created'),
'favorites': favorites, 'favorites': favorites,
@@ -986,9 +986,11 @@ def community_tools_set(request, community):
if not can_edit: if not can_edit:
return HttpResponseForbidden() return HttpResponseForbidden()
if len(request.POST.get('community_name')) == 0 or len(request.POST.get('community_name')) >= 100: if len(request.POST.get('community_name')) == 0 or len(request.POST.get('community_name')) >= 100:
return json_response('bad name') return json_response('Your community name is either too short or too long.')
if len(request.POST.get('community_description')) >= 1024: if len(request.POST.get('community_description')) >= 1024:
return json_response('bad description') return json_response('Your community description is too long.')
if int(request.POST.get('community_platform')) >= 8:
return json_response('Invalid Platform type.')
if the_community.is_rm: if the_community.is_rm:
return json_response('Community is removed') return json_response('Community is removed')
if the_community.type == 4: if the_community.type == 4:
@@ -1066,6 +1068,8 @@ def community_create_action(request):
return json_response('Your community name is either too short or too long.') return json_response('Your community name is either too short or too long.')
if len(request.POST.get('community_description')) >= 1024: if len(request.POST.get('community_description')) >= 1024:
return json_response('Your community description is too long.') return json_response('Your community description is too long.')
if int(request.POST.get('community_platform')) >= 8:
return json_response('Invalid Platform type.')
get = request.POST.get get = request.POST.get
user.c_tokens -= 1 user.c_tokens -= 1
user.save() user.save()
@@ -1709,6 +1713,8 @@ def user_tools_meta(request, username):
raise Http404() raise Http404()
user = get_object_or_404(User, username__iexact=username) user = get_object_or_404(User, username__iexact=username)
profile = user.profile() profile = user.profile()
if user.protect_data:
return json_response('This user\'s data has been locked.')
# check if the requesting user is allowed to view someone # check if the requesting user is allowed to view someone
if user.has_authority(request.user): if user.has_authority(request.user):
raise Http404() raise Http404()
Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB