Skip to content

Commit

Permalink
User management page fix + + user nickname colors
Browse files Browse the repository at this point in the history
  • Loading branch information
ariankordi committed Dec 19, 2017
1 parent 81b55b2 commit dcae083
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 34 deletions.
2 changes: 1 addition & 1 deletion closedverse_main/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class LoginAdmin(admin.ModelAdmin):
search_fields = ('user__username', )

class AuditAdmin(admin.ModelAdmin):
raw_id_fields = ('by', 'user', 'post', 'comment', )
raw_id_fields = ('by', 'user', 'post', 'comment', 'reversed_by', )
search_fields = ('by__username', 'user__username', )

#class BlockAdmin(admin.ModelAdmin)
Expand Down
13 changes: 12 additions & 1 deletion closedverse_main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.utils import timezone
from django.forms.models import model_to_dict
from django.utils.dateformat import format
from django.core.validators import URLValidator
from django.core.validators import RegexValidator, URLValidator
from django.core.exceptions import ValidationError
from datetime import timedelta, datetime, date, time
from passlib.hash import bcrypt_sha256
Expand Down Expand Up @@ -120,6 +120,15 @@ class CommunityFavoriteManager(models.Manager):
def get_queryset(self):
return super(CommunityFavoriteManager, self).get_queryset().filter(community__is_rm=False).exclude(community__type=3)

# Taken from https://github.com/jaredly/django-colorfield/blob/master/colorfield/fields.py
color_re = re.compile('^#([A-Fa-f0-9]{6})$')
validate_color = RegexValidator(color_re, "Enter a valid color", 'invalid')
class ColorField(models.CharField):
default_validators = [validate_color]
def __init__(self, *args, **kwargs):
kwargs['max_length'] = 18
super(ColorField, self).__init__(*args, **kwargs)

class User(models.Model):
unique_id = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
id = models.AutoField(primary_key=True)
Expand All @@ -137,7 +146,9 @@ class User(models.Model):
role = models.SmallIntegerField(default=0, choices=((0, 'normal'), (1, 'bot'), (2, 'administrator'), (3, 'moderator'), (4, 'openverse'), (5, 'donator'), (6, 'tester'), (7, 'urapp'), (8, 'developer'), ))
addr = models.CharField(max_length=64, null=True, blank=True)

# Things that don't have to do with auth lol
hide_online = models.BooleanField(default=False)
color = ColorField(default='', null=True, blank=True)

staff = models.BooleanField(default=False)
#active = models.SmallIntegerField(default=1, choices=((0, 'Disabled'), (1, 'Good'), (2, 'Redirect')))
Expand Down
4 changes: 2 additions & 2 deletions closedverse_main/templates/closedverse_main/comment-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="post-list-outline">
<a class="post-permalink-button info-ticker" href="{% url "main:post-view" comment.original_post.id %}">
<span class="icon-container"><img src="{% avatar comment.original_post.creator comment.original_post.feeling %}" class="icon"></span>
<span>View <span class="post-user-description">{{ comment.original_post.creator.nickname }}'s post ({{ comment.original_post.trun|truncatechars:35 }})</span> for this comment.</span>
<span>View <span class="post-user-description" {% if comment.original_post.creator.color %}style=color:{{ comment.original_post.creator.color }}{% endif %}>{{ comment.original_post.creator.nickname }}'s post ({{ comment.original_post.trun|truncatechars:35 }})</span> for this comment.</span>
</a>
</div>
<div class="post-list-outline more">
Expand All @@ -24,7 +24,7 @@
<div class="user-content">
{% user_icon_container comment.creator comment.feeling %}
<div class="user-name-content">
<p class="user-name"><a href="{% url "main:user-view" comment.creator.username %}">{{ comment.creator.nickname }}</a></p>
<p class="user-name"><a {% if comment.creator.color %}style=color:{{ comment.creator.color }}{% endif %} href="{% url "main:user-view" comment.creator.username %}">{{ comment.creator.nickname }}</a></p>
<p class="timestamp-container">
<span class="spoiler-status{% if comment.spoils %} spoiler{% endif %}">Spoilers ·</span>
<span class="timestamp">{% time comment.created %}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</p>
{% endif %}
{% user_icon_container post.creator post.feeling %}
<p class="user-name"><a href="{% url "main:user-view" post.creator.username %}">{{ post.creator.nickname }}</a></p>
<p class="user-name"><a href="{% url "main:user-view" post.creator.username %}"{% if post.creator.color %}style=color:{{ post.creator.color }}{% endif %}>{{ post.creator.nickname }}</a></p>
<p class="timestamp-container">
<span class="spoiler-status{% if post.spoils %} spoiler{% endif %}">Spoilers·</span>
{% if post.has_edit %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p class="user-name"><a href="{% url "main:user-view" user.username %}">{{ user.nickname }}</a><span class="user-id">{{ user.username }}</span></p>
<p class="user-name"><a {% if user.color %}style=color:{{ user.color }}{% endif %} href="{% url "main:user-view" user.username %}">{{ user.nickname }}</a><span class="user-id">{{ user.username }}</span></p>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% user_icon_container comment.creator comment.feeling %}
<div class="body">
<div class="header">
<p class="user-name"><a href="{% url "main:user-view" comment.creator.username %}">{{ comment.creator.nickname }}</a></p>
<p class="user-name"><a {% if comment.creator.color %}style=color:{{ comment.creator.color }}{% endif %} href="{% url "main:user-view" comment.creator.username %}">{{ comment.creator.nickname }}</a></p>
<p class="timestamp-container">
<a class="timestamp" {% if comment.spoils and not comment.is_mine %}data-href-hidden{% else %}href{% endif %}="{% url "main:comment-view" comment.id %}">{% time comment.created %}</a>
{% if comment.drawing %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="post-content">
{% user_icon_container post.creator post.feeling %}

<p class="user-name"><a href="{% url "main:user-view" post.creator.username %}">{{ post.creator.nickname }}</a></p>
<p class="user-name"><a {% if post.creator.color %}style=color:{{ post.creator.color }}{% endif %} href="{% url "main:user-view" post.creator.username %}">{{ post.creator.nickname }}</a></p>

<p class="timestamp-container">
{% if post.spoils %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
</div>
{% if user.get_class.1 %}<p class="user-organization">{% user_level user %}</p>{% endif %}

<a href="{% url "main:user-view" user.username %}" class="nick-name">{{ user.nickname }}</a>
<a href="{% url "main:user-view" user.username %}" class="nick-name"{% if user.color %}style=color:{{ user.color }}{% endif %}>{{ user.nickname }}</a>
<p class="id-name">{{ user.username }}</p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h2 class="label">{{ title }}</h2>
<div class="news-list-content trigger" tabindex="0" id="{{ fr.unique_id }}" data-href="{% url "main:user-view" fr.source.username %}">
{% user_icon_container fr.source %}
<div class="body">
<a href="{% url "main:user-view" fr.source.username %}" class="nick-name">{{ fr.source.nickname }}</a><br><span class="timestamp"> {% time fr.created %}</span>
<a href="{% url "main:user-view" fr.source.username %}" class="nick-name"{% if fr.source.color %}style=color:{{ fr.source.color }}{% endif %}>{{ fr.source.nickname }}</a><br><span class="timestamp"> {% time fr.created %}</span>
<button class="button received-request-button" type="button">View friend request</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ <h2 class="label">{{ title }}</h2>
<input type="text" name="external" maxlength="255" placeholder="DiscordTag" value="{{ profile.external }}">
</div>
<p class="note">Actually, you don't have to put a DiscordTag here, you can put anything here, such as your PlayStation Network account. Discord sure is popular though.</p>
</li>
<li class="setting-color">
<p class="settings-label">Nickname color</p>
<div class="center center-input">
<input type="hidden" name="color" maxlength="7" placeholder="Enter a hex color value here" value="{{ user.color }}">
<button class="button color-thing">Open color picker</button>
</div>
<p class="note">This is the color your nickname will appear as. Leave it blank for the default. It will appear like so.</p>
{% user_sidebar_info user %}
</li>
{% if profile.origin_id %}
<li>
Expand Down
2 changes: 1 addition & 1 deletion closedverse_main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
url(r'posts/'+ post +'\.rm$', views.post_rm, name='post-rm'),
url(r'comments/'+ comment +'$', views.comment_view, name='comment-view'),
url(r'comments/'+ comment +'/yeah$', views.comment_add_yeah, name='comment-add-yeah'),
url(r'comments/'+ comment +'/unyeah$', views.comment_delete_yeah, name='comment-delete-yeah'),
url(r'comments/'+ comment +'/yeahu$', views.comment_delete_yeah, name='comment-delete-yeah'),
url(r'comments/'+ comment +'/change$', views.comment_change, name='comment-change'),
url(r'comments/'+ comment +'/rm$', views.comment_rm, name='comment-rm'),
# Post-meta: polls
Expand Down
25 changes: 14 additions & 11 deletions closedverse_main/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,26 @@ def image_upload(img, stream=False, drawing=False):
# Todo: Put this into post/comment delete thingy method
def image_rm(image_url):
if settings.image_delete_opt:
sysfile = image_url.split(settings.MEDIA_URL)[1]
sysloc = settings.MEDIA_ROOT + sysfile
if settings.image_delete_opt > 1:
if settings.MEDIA_URL in image_url:
sysfile = image_url.split(settings.MEDIA_URL)[1]
sysloc = settings.MEDIA_ROOT + sysfile
if settings.image_delete_opt > 1:
try:
remove(sysloc)
except:
return False
else:
return True
# The RM'd directory to move it to
rmloc = sysloc.replace(settings.MEDIA_ROOT, settings.MEDIA_ROOT + 'rm/')
try:
remove(sysloc)
rename(sysloc, rmloc)
except:
return False
else:
return True
# The RM'd directory to move it to
rmloc = sysloc.replace(settings.MEDIA_ROOT, settings.MEDIA_ROOT + 'rm/')
try:
rename(sysloc, rmloc)
except:
return False
else:
return True
return False

def get_gravatar(email):
try:
Expand Down
26 changes: 22 additions & 4 deletions closedverse_main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from django.core.validators import EmailValidator
from django.core.exceptions import ValidationError
from django.db.models import Q, Count, Exists, OuterRef
from .models import User, Community, Post, Comment, Yeah, Profile, Notification, Complaint, FriendRequest, Friendship, Message, Follow, Poll, Conversation, UserBlock, LoginAttempt
from .util import get_mii, recaptcha_verify, get_gravatar, filterchars, HumanTime, nnid_blacked, iphub
from .models import *
from .util import *
from .serializers import CommunitySerializer
from closedverse import settings
import re
Expand Down Expand Up @@ -382,7 +382,25 @@ def user_view(request, username):
user.avatar = getmii[0]
profile.origin_id = getmii[2]
profile.origin_info = dumps(getmii)
user.email = request.POST.get('email')
if request.POST.get('color'):
try:
validate_color(request.POST['color'])
except ValidationError:
return json_response("Invalid color")
else:
dark = True if user.color == '#000000' else False
light = True if user.color == '#ffffff' else False
if dark:
return json_response("Too dark")
if light:
return json_response("Too light")
user.color = request.POST['color']
else:
user.color = None
if request.POST.get('email') == 'None':
user.email = None
else:
user.email = request.POST.get('email')
profile.country = request.POST.get('country')
website = request.POST.get('website')
if ' ' in website or not '.' in website:
Expand Down Expand Up @@ -762,7 +780,7 @@ def community_view(request, community):
@login_required
def community_favorite_create(request, community):
the_community = get_object_or_404(Community, id=community)
if not community.type == 3:
if not the_community.type == 3:
the_community.favorite_add(request)
return HttpResponse()
@require_http_methods(['POST'])
Expand Down
2 changes: 1 addition & 1 deletion static/blueness.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#sidebar-profile-body .nick-name, .news-list .nick-name, .list-content-with-icon-and-text .nick-name a, .user-name a {
color: #fff !important;
color: #fff;
}
.post-permalink-button:hover, .favorite-community-link.symbol, .trigger:active, #wrapper, #reply-content button.more-button:hover, .spoiler-button:hover, #sidebar-profile-status, #guide-menu:hover, .community-eyecatch-info:hover, #community-favorite:hover, #reply-content .list > li.my:hover, .big-button:hover, .sidebar-setting a:hover, .multi-timeline-post-list .post.hidden .screenshot-container, .multi-timeline-post-list .post .screenshot-container, .trigger:hover, .textarea-container .community-container, .post-form-album-content, .admin-messages .post.my, #identified-user-banner:hover, .sidebar-setting a.selected, .sidebar-container h4 a:hover, #empathy-content, .sidebar-profile .profile-comment, .post-list .recent-reply-content, .community-name .owner, .post-list-heading-button, .topic-title-input, .textarea, .yeah-button, .hidden-content-button, .community-description {
background-color: #161626 !important;
Expand Down
8 changes: 1 addition & 7 deletions static/closedverse.css
Original file line number Diff line number Diff line change
Expand Up @@ -9153,13 +9153,7 @@ See http://bgrins.github.io/spectrum/themes/ for instructions.
border: solid 1px #aaa;
padding: 0;
}
.sp-container, .sp-container button, .sp-container input, .sp-color, .sp-hue, .sp-clear {
font: normal 12px "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Geneva, Verdana, sans-serif;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}

.sp-top {
margin-bottom: 3px;
}
Expand Down
21 changes: 21 additions & 0 deletions static/closedverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3274,6 +3274,27 @@ mode_post = 0;
$('.setting-avatar > .icon-container > .nnid-icon.mii').addClass('none');
$('.nnid-icon.gravatar').removeClass('none');
})
$('.color-thing').click(function(a) {
a.preventDefault();
$('.color-thing').spectrum({
color: $('input[name=color]'),
preferredFormat: "hex",
showInput: true,
showButtons: false,
flat: true,
change: function(color) {
$('.nick-name').attr('style', 'color:' + color);
$('input[name=color]').val(color);
}
});
$('.color-thing').on('dragstop.spectrum', function(e, color) {
$('.nick-name').attr('style', 'color:' + color.toHexString());
$('input[name=color]').val(color);
});
$('div.form-buttons > input').click(function(a) {
$('.color-thing').spectrum('destroy');
});
});
// }
}
b.User.setupUserSidebar(e)
Expand Down

0 comments on commit dcae083

Please sign in to comment.