This commit is contained in:
some weird guy
2023-08-29 11:56:34 -07:00
parent 7909335304
commit f381d1d1af
14 changed files with 88 additions and 77 deletions
+2 -3
View File
@@ -1,9 +1,8 @@
from django.contrib import admin
#from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import Group
from django.forms import ModelForm, PasswordInput
from closedverse_main import models
from closedverse import settings
#from django.forms import ModelForm, PasswordInput
from django.conf import settings
from . import models
+5 -6
View File
@@ -1,14 +1,13 @@
try:
from closedverse.settings import brand_name
except ImportError:
from closedverse import settings
if not hasattr(settings, 'brand_name'):
# use default app name by default as brand name
from closedverse_main import apps
brand_name = apps.ClosedverseMainConfig.verbose_name
else:
brand_name = settings.brand_name
# for brand logo
from closedverse.settings import STATIC_URL
# variable for this and name are here for imports
brand_logo = STATIC_URL + 'img/menu-logo.svg'
brand_logo = settings.STATIC_URL + 'img/menu-logo.svg'
# the name of the function is merely what's imported into settings.py
def brand_name_universal(request):
-1
View File
@@ -1,7 +1,6 @@
from django.http import HttpResponseForbidden
from closedverse import settings
from django.shortcuts import redirect
from django.contrib.auth import logout
from .models import Ban
from django.utils import timezone
from re import compile
+34 -19
View File
@@ -2,13 +2,13 @@ from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.models import BaseUserManager
from django.db.models import Q, QuerySet, Max, F, Count, Case, When, Exists, OuterRef, Subquery
from django.db.models import Q, Max, F, Count, Exists, OuterRef, Subquery #, QuerySet, Case, When,
from django.utils import timezone
from django.http import Http404
from django.core.validators import RegexValidator, URLValidator
from django.core.exceptions import ValidationError
from datetime import timedelta, time
#from passlib.hash import bcrypt_sha256
# you may want to import django.conf.settings instead (then change checks for DEFAULT_FROM_EMAIL)
from closedverse import settings
from closedverse_main.context_processors import brand_name, brand_logo
from . import util
@@ -128,7 +128,7 @@ class Role(models.Model):
organization = models.CharField(max_length=255, blank=True, null=True, help_text='Text that shows above one\'s username')
def __str__(self):
return "role \"" + str(self.organization) + "\""
return "role \"" + str(self.organization) + "\", name " + str(self.image)
#mii_domain = 'https://mii-secure.cdn.nintendo.net'
# as of writing, mii-secure is unstable, nintendo please do not f*ck me for this
@@ -195,13 +195,17 @@ class User(AbstractBaseUser):
return self.warned
def get_warned_reason(self):
return self.warned_reason
def profile(self, thing=None):
# If thing is specified, that field is retrieved
if thing:
def profile(self, attr=None):
# If attr is specified, that field is retrieved
if attr:
# could this be shortened? or discontinued in general
return self.profile_set.all().values_list(thing, flat=True).first()
return self.profile_set.all().values_list(attr, flat=True).first()
# Otherwise just get full profile
return self.profile_set.filter().first()
result = self.profile_set.filter().first()
if not result:
# hacky but should make any page that requests this where it's not there, return a 404
raise Http404()
return result
def gravatar(self):
g = util.get_gravatar(self.email)
if not g:
@@ -344,7 +348,7 @@ class User(AbstractBaseUser):
# trailing
if UserBlock.objects.filter(source=source, target=self).exists():
return False
if not self.can_block(source):
if not self.can_block(source) or self == source:
return False
fs = Friendship.find_friendship(self, source)
if fs:
@@ -378,18 +382,29 @@ class User(AbstractBaseUser):
for post in posts:
post.setup(request)
return posts
def get_yeahed(self, type=0, limit=20, offset=0):
def get_yeahed(self, type, limit, offset, user):
# 0 - post, 1 - comment, 2 - any
if type == 2:
yeahs = self.yeah_set.select_related('post').select_related('comment').select_related('comment__original_post').select_related('comment__original_post__creator').annotate(num_yeahs_post=Count('post__yeah', distinct=True), num_yeahs_comment=Count('comment__yeah', distinct=True), num_comments=Count('post__comment', distinct=True)).filter().order_by('-created')[offset:offset + limit]
yeahs = self.yeah_set.select_related('post', 'comment', 'comment__original_post', 'comment__original_post__creator').annotate(
# todo clean up all queries like this lmao
num_yeahs_post=Count('post__yeah', distinct=True),
num_yeahs_comment=Count('comment__yeah', distinct=True),
num_comments=Count('post__comment', distinct=True)
)
# add type= if NOT selecting all
type_query = Q(type=type) if type != 2 else Q()
if not user.is_authenticated:
# if user is not authenticated then only search yeahs in communities that don't require auth
require_auth_query = Q(post__community__require_auth=False) | Q(comment__community__require_auth=False)
else:
yeahs = self.yeah_set.select_related('post').select_related('post__creator').annotate(num_yeahs_post=Count('post__yeah', distinct=True), num_comments=Count('post__comment', distinct=True)).filter(type=type, post__is_rm=False).order_by('-created')[offset:offset + limit]
for thing in yeahs:
if thing.post:
thing.post.num_yeahs = thing.num_yeahs_post
thing.post.num_comments = thing.num_comments
elif thing.comment:
thing.comment.num_yeahs = thing.num_yeahs_comment
require_auth_query = Q()
# sometimes is_rm'ed posts are searched so it's necessary to specifically specify non deleted
yeahs = yeahs.filter(type_query, require_auth_query, Q(post__is_rm=False) | Q(comment__is_rm=False)).order_by('-created')[offset:offset + limit]
for yeah in yeahs:
if yeah.post:
yeah.post.num_yeahs = yeah.num_yeahs_post
yeah.post.num_comments = yeah.num_comments
elif yeah.comment:
yeah.comment.num_yeahs = yeah.num_yeahs_comment
return yeahs
def get_following(self, limit=50, offset=0, request=None):
return self.follow_source.select_related('target').filter().order_by('-created')[offset:offset + limit]
@@ -41,7 +41,7 @@
{% endif %}
{% endif %}
{% if post.screenshot %}<a class="screenshot-container still-image" href="{% if post.is_reply %}{% url "main:comment-view" post.id %}{% else %}{% url "main:post-view" post.id %}{% endif %}"><img src="{{ post.screenshot }}"></a>{% endif %}
{% if post.video %}<div class="screenshot-container still-image"><video class="vidya" controls src="{{ post.video }}" style="max-width:100%;max-height: 450px;"></video></div>{% endif %}
{% if post.video %}<div class="screenshot-container still-image"><video controls src="{{ post.video }}" style="max-width:100%;max-height: 450px;"></video></div>{% endif %}
{% if post.spoils and not post.is_mine and not post.creator.banned %}
<div class="hidden-content"><p>This post contains spoilers.</p>
<button type="button" class="hidden-content-button">View Post</button>
@@ -88,7 +88,7 @@
{% if post.yt_vid %}
<div class="screenshot-container video"><iframe class="youtube-player" type="text/html" style="max-width:100%;max-height: 450px;" src="https://www.youtube.com/embed/{{ post.yt_vid }}?rel=0&modestbranding=1&iv_load_policy=3" frameborder="0"></iframe></div>
{% elif post.video %}
<div class="screenshot-container video"><video class="vidya" controls src="{{ post.video }}" style="max-width:100%;max-height: 450px;"></video></div>
<div class="screenshot-container video"><video controls src="{{ post.video }}" style="max-width:100%;max-height: 450px;"></video></div>
{% elif post.discord_vid %}
<div class="DiscordCDN-container video">
<video class="discord-player" src="{{ post.url }}" style="max-width:100%;max-height: 450px;" controls></video>
@@ -18,7 +18,7 @@
</div>
{% endif %}
</div><a class="big-button" href="{% url "main:user-posts" user.username %}">View posts</a>
{% if profile.yeahs_visible and request.user.is_authenticated %}
{% if profile.yeahs_visible %}
<div class="post-list-outline">
<h2 class="label">Recently yeahed posts</h2>
{% if yeahed.count < 1 %}
@@ -1 +0,0 @@
@@ -1,9 +1,7 @@
from django import template
from closedverse_main.models import User
from closedverse_main.util import HumanTime
from closedverse_main.models import mii_domain
from closedverse import settings
import re
register = template.Library()
+4 -4
View File
@@ -1,10 +1,10 @@
from django.conf.urls import url, re_path
from django.conf.urls.static import static
from django.views.static import serve
from django.shortcuts import redirect
#from django.conf.urls.static import static
#from django.shortcuts import redirect
from . import views
from closedverse.settings import MEDIA_URL, MEDIA_ROOT
from django.conf import settings
username = r'(?P<username>[A-Za-z0-9-\'-._ ]+)'
community = r'(?P<community>[0-9]+)'
@@ -113,4 +113,4 @@ urlpatterns = [
]
# + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# serve static and media i think???? mighTTT???????
urlpatterns += [re_path(r'^i/(?P<path>.*)$', serve, {'document_root': MEDIA_ROOT, }), ]
urlpatterns += [re_path(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT, }), ]
+1 -7
View File
@@ -2,22 +2,16 @@ import urllib.request, urllib.error
# requests is only used for get_mii which is not being used currently
#import requests
from lxml import etree
from random import choice
import json
import time
import os.path
import random
from PIL import Image, ExifTags, ImageFile
from PIL import Image, ImageFile #, ExifTags,
from datetime import datetime
from binascii import crc32
from math import floor
from hashlib import md5, sha1
import io
from uuid import uuid4
import imghdr
import base64
from closedverse import settings
import re
from os import remove, rename
def HumanTime(date, full=False):
+5 -11
View File
@@ -208,7 +208,7 @@ def login_page(request):
'title': 'Log in',
'form': form,
'allow_signups': settings.allow_signups,
'reset_supported': hasattr(settings, 'DEFAULT_FROM_EMAIL'),
'reset_supported': settings.DEBUG or hasattr(settings, 'EMAIL_HOST_USER'),
})
def signup_page(request):
@@ -369,8 +369,7 @@ def forgot_passwd(request):
if not request.POST['password'] == request.POST['password_again']:
return HttpResponseBadRequest("Your passwords don't match.")
try:
new = request.POST['password']
validate_password(new, user=user)
validate_password(request.POST['password'], user=user)
except ValidationError as error:
return HttpResponseBadRequest(error)
user.set_password(request.POST['password'])
@@ -383,7 +382,7 @@ def forgot_passwd(request):
})
return render(request, 'closedverse_main/forgot_page.html', {
'title': 'Reset password',
'reset_supported': hasattr(settings, 'DEFAULT_FROM_EMAIL'),
'reset_supported': settings.DEBUG or hasattr(settings, 'EMAIL_HOST_USER'),
#'classes': ['no-login-btn'],
})
@@ -586,7 +585,7 @@ def user_view(request, username):
user.save()
return HttpResponse()
posts = user.get_posts(3, 0, request, timezone.now())
yeahed = user.get_yeahed(0, 3)
yeahed = user.get_yeahed(0, 3, 0, request.user)
for yeah in yeahed:
if user.is_me(request):
yeah.post.yeah_given = True
@@ -668,8 +667,6 @@ def user_yeahs(request, username):
user = get_object_or_404(User, username__iexact=username)
if user.is_me(request):
title = 'My yeahs'
elif not request.user.is_authenticated:
raise Http404()
else:
if request.user.is_authenticated and not user.can_view(request.user):
raise Http404()
@@ -686,10 +683,7 @@ def user_yeahs(request, username):
if not profile.yeahs_visible:
raise Http404()
if request.GET.get('offset'):
yeahs = user.get_yeahed(2, 20, int(request.GET['offset']))
else:
yeahs = user.get_yeahed(2, 20, 0)
yeahs = user.get_yeahed(2, 20, int(request.GET.get('offset', 0)), request.user)
if yeahs.count() > 19:
if request.GET.get('offset'):
next_offset = int(request.GET['offset']) + 20
+1 -1
View File
@@ -18,7 +18,7 @@ input[type=text], input[type=password], input[type=email], input:not([type]), se
}
.guest .guest-message p {
color: #ccc;
background: #1b1b1b;
background: #15151f;
}
.guest-message .arrow-button {
border-top: 1px solid #000 !important;
+30 -16
View File
@@ -616,6 +616,14 @@ var Olv = Olv || {};
a(window).on("click submit", this.onMayLeavePage)
},
onDataHrefClick: function(c) {
// if is video then don't navigate
// bc most of the time you click on a video it plays in the background while navigating to the next post
// this may make it more inconvenient to click on the post but it's a win to me
//if (a(c.target).is('video')) {
if (a(c.target).attr('controls')) {
// ignore
return;
}
if (a(c.target).attr("data-href")) {
b.Net.go($(this).attr("data-href"));
return;
@@ -1118,10 +1126,15 @@ var Olv = Olv || {};
b.ModalWindowManager.setup()
}),
a(document).on("olv:pagechange", function() {
b.ModalWindowManager.closeAll();
if(!Olv.ModalWindowManager._windows.length && $('.mask').length) {
b.ModalWindowManager.toggleMask();
}
// hackily re-add modals that were open on page forward/backwards, restoring their functionality
b.ModalWindowManager._windows = [];
a('.modal-window-open').each(function(i, v) {
var modal = new b.ModalWindow(v);
modal.triggerOpenHandlers(a.Deferred());
b.ModalWindowManager._windows.push(modal);
b.ModalWindowManager.currentWindow = modal;
});
//b.ModalWindowManager.closeAll()
}),
b.ModalWindow = function(b, c) {
this.element = a(b),
@@ -1949,23 +1962,25 @@ var Olv = Olv || {};
var handleFileChange = function(event) {
//var fileList;
console.log('handleFileChange: files is being assigned...');
//console.log('handleFileChange: files is being assigned...');
var files;
switch(true) {
case event.target.files !== undefined:
uploadFile[0].files = event.target.files;
files = event.target.files;
break;
case event.originalEvent.dataTransfer !== undefined:
uploadFile[0].files = event.originalEvent.dataTransfer.files;
files = event.originalEvent.dataTransfer.files;
break;
case event.originalEvent.clipboardData !== undefined:
uploadFile[0].files = event.originalEvent.clipboardData.files;
files = event.originalEvent.clipboardData.files;
break;
default:
return;
}
if (!(null === uploadFile[0].files || uploadFile[0].files.length < 1 || void 0 === uploadFile[0].files[0] || uploadFile[0].files[0].type.indexOf("image") < 0)) {
if (!(null === files || files.length < 1 || void 0 === files[0] || files[0].type.indexOf("image") < 0)) {
event.preventDefault();
uploadFile[0].files = files;
Olv.Form.toggleDisabled($("input.black-button"), false);
uploadPreview.hide();
uploadPreviewContainer.hide();
@@ -1977,7 +1992,7 @@ var Olv = Olv || {};
console.log('here is your fileList, and uploadFile')
*/
var blobURL = URL.createObjectURL(uploadFile[0].files[0]);
console.log(uploadFile[0].files[0])
//console.log(uploadFile[0].files[0])
uploadPreview.attr("src", blobURL);
uploadPreview.show();
@@ -2021,9 +2036,7 @@ var Olv = Olv || {};
event.preventDefault();
});
c.on("drop", handleFileChange);
// upon choosing an image, and pasting plain text after, no image would be uploaded for some reason.
// yeah i got no fucking clue how to fix this shit.
c.on("drop paste", handleFileChange);
c.on("olv:entryform:post:done", function() {
imageDimensions.text(b.EntryForm.tempPollutionButImageFormAllowedText);
@@ -2597,7 +2610,6 @@ var Olv = Olv || {};
b.Closed.changesel("news");
$('.received-request-button').on('click', function(a) {
a.preventDefault()
window.ass = a
fr = new b.ModalWindow($('div[data-modal-types=accept-friend-request][data-action="'+ $(this).parent().parent().data('action') +'"]'));fr.open();
})
$('div[data-modal-types=accept-friend-request] .ok-button.post-button').on('click', function(a){
@@ -2916,7 +2928,7 @@ $('.post-poll .poll-votes').on('click', function() {
$('.edit-post-button').on('click',function(){
if($('.post-content-memo').length) {
b.showMessage("", "You can't edit a drawing, sorry.");
} else if($('.vidya').length) {
} if($('.screenshot-container > video').length) {
b.showMessage("", "You can't edit your uploaded video, sorry. But you can edit the contents of the post.");
et();
b.Form.toggleDisabled(submit_btn, true);
@@ -2948,7 +2960,9 @@ $('.post-poll .poll-votes').on('click', function() {
lock_comments_button.on('click',function(){
b.showConfirm("Lock comments", "Really lock up the comments? This cannot be undone.")
$('.ok-button').on('click',function(){
b.Form.post(lock_comments_button.attr('data-action')).done
b.Form.post(lock_comments_button.attr('data-action')).done(function() {
b.Net.reload();
});
})
})
}