fix #15
This commit is contained in:
parent
fb09a02a22
commit
5d088f0461
@ -28,9 +28,9 @@ year_now = int(datetime.now().year)
|
||||
|
||||
|
||||
class User(Model):
|
||||
name = CharField('Name', max_length=50, default='Anonym')
|
||||
name = CharField('Name', max_length=20, default='Anonym')
|
||||
|
||||
color = CharField('Farbe', max_length=20, default='white')
|
||||
color = CharField('Farbe', max_length=20, default='purple')
|
||||
|
||||
|
||||
def __str__(self):
|
||||
|
@ -44,13 +44,11 @@ function get_datetime() {
|
||||
|
||||
|
||||
// manage user login
|
||||
function render_login(input_name, input_color) {
|
||||
function render_login(name, color) {
|
||||
|
||||
let color = decodeURIComponent(input_color);
|
||||
let name = decodeURIComponent(input_name);
|
||||
new Cookie('coinc-name', name)
|
||||
|
||||
render_login_color(color);
|
||||
|
||||
let option = $('nav.navbar option[value=' + name + ']');
|
||||
if (option.length == 0) {
|
||||
$('nav.navbar select').append($('<option>', {
|
||||
@ -172,6 +170,7 @@ function save_settings() {
|
||||
}
|
||||
|
||||
|
||||
// begin document.ready
|
||||
$(document).ready(function() {
|
||||
|
||||
//
|
||||
@ -320,89 +319,81 @@ $(document).ready(function() {
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Modals
|
||||
//
|
||||
|
||||
//
|
||||
// Modals
|
||||
//
|
||||
// hide modal add user
|
||||
function hide_modal() { $('#modal_add_user').fadeOut('fast'); }
|
||||
|
||||
// hide modal add user
|
||||
function hide_modal() {
|
||||
$('#modal_add_user').fadeOut('fast');
|
||||
}
|
||||
// modal #add_user
|
||||
$('#show_add_user').click(function() {
|
||||
$('#modal_add_user').fadeIn('fast');
|
||||
|
||||
// modal #add_user
|
||||
$('#show_add_user').click(function() {
|
||||
$('#modal_add_user').fadeIn('fast');
|
||||
$(document).on('click', function(event) {
|
||||
if ($('#modal_add_user').is(':visible')) {
|
||||
if ($(event.target).attr('id') === 'modal_add_user') { hide_modal(); }
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('click', function(event) {
|
||||
if ($('#modal_add_user').is(':visible')) {
|
||||
let target = $(event.target);
|
||||
if (target.attr('id') === 'modal_add_user') {
|
||||
hide_modal();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// detect ESC keypress
|
||||
$(document).keypress(function(event) {
|
||||
if (event.keyCode == 27) { // ESC is pressed
|
||||
hide_modal();
|
||||
$(document).off('keypress');
|
||||
}
|
||||
});
|
||||
|
||||
// button #close_modal_add_user
|
||||
$('#close_modal_add_user').click(function() {
|
||||
hide_modal();
|
||||
// detect ESC keypress
|
||||
$(document).keypress(function(event) {
|
||||
if (event.keyCode == 27) { // ESC is pressed
|
||||
hide_modal();
|
||||
$(document).off('keypress');
|
||||
}
|
||||
});
|
||||
|
||||
// button #close_modal_add_user
|
||||
$('#close_modal_add_user').click(function() { hide_modal(); });
|
||||
|
||||
// button #add_user
|
||||
$('#add_user').click(function() {
|
||||
|
||||
let name = encodeURIComponent($('#text_user')
|
||||
.val().trim().substring(0, 19).replace(' ', '-'));
|
||||
let color = encodeURIComponent($('#text_color')
|
||||
.val().trim().substring(0, 9 ).replace(' ', '-'));
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
url: 'add/user/' + name + '/color/' + color,
|
||||
success: function(response) {
|
||||
|
||||
if (response.status === 0) {
|
||||
$('#response').fadeOut('fast');
|
||||
hide_modal();
|
||||
render_login(name, color);
|
||||
|
||||
} else {
|
||||
$('#response').html(response.message);
|
||||
$('#response').css('color', 'red');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
// end modal #add_user
|
||||
|
||||
|
||||
// button #add_user
|
||||
$('#add_user').click(function() {
|
||||
//
|
||||
// Main routine
|
||||
//
|
||||
|
||||
let name = encodeURIComponent($('#text_user').val());
|
||||
let color = encodeURIComponent($('#text_color').val());
|
||||
let cookie = new Cookie();
|
||||
let name = cookie.get('coinc-name');
|
||||
let color = cookie.get('coinc-color');
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
url: 'add/user/' + name + '/color/' + color,
|
||||
success: function(response) {
|
||||
if (name != '' && color != '') {
|
||||
render_login(name, color);
|
||||
} else {
|
||||
name = $('#found_by option:first-child').html();
|
||||
color = $('#found_by option:first-child').attr('color');
|
||||
render_login(name, color);
|
||||
}
|
||||
|
||||
if (response.status === 0) {
|
||||
$('#response').fadeOut('fast');
|
||||
hide_modal();
|
||||
render_login(name, color);
|
||||
|
||||
} else {
|
||||
$('#response').html(response.message);
|
||||
$('#response').css('color', 'red');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
//
|
||||
// Main routine
|
||||
//
|
||||
|
||||
let cookie = new Cookie();
|
||||
let name = cookie.get('coinc-name');
|
||||
let color = cookie.get('coinc-color');
|
||||
|
||||
if (name != '') {
|
||||
render_login(name, color);
|
||||
|
||||
} else {
|
||||
name = $('#found_by option:first-child').html();
|
||||
color = $('#found_by option:first-child').val();
|
||||
render_login(name, color);
|
||||
}
|
||||
|
||||
save_settings()
|
||||
render_found();
|
||||
save_settings()
|
||||
render_found();
|
||||
|
||||
});
|
||||
|
@ -186,23 +186,17 @@ def show_coin(country, year, stamp, value):
|
||||
def add_user(request, username, color):
|
||||
''' add a user '''
|
||||
|
||||
status = 0
|
||||
message = ''
|
||||
|
||||
if username and color:
|
||||
try:
|
||||
existing_user = User.objects.get(name=username)
|
||||
status = 1
|
||||
message = f"'{username}' ist schon vergeben."
|
||||
return response(1, f"'{username}' ist schon vergeben.")
|
||||
|
||||
except User.DoesNotExist:
|
||||
User.objects.create(name=username, color=color)
|
||||
message = 'success'
|
||||
else:
|
||||
status = 1
|
||||
message = 'Du musst einen Namen und Farbe angeben.'
|
||||
return response(1, 'Du musst einen Namen und Farbe angeben.')
|
||||
|
||||
return HttpResponse(dumps({ 'status': status, 'message': message }))
|
||||
return response()
|
||||
|
||||
|
||||
def response(status=0, message=''):
|
||||
|
Loading…
x
Reference in New Issue
Block a user