begin add coins :)))

This commit is contained in:
koksnuss 2020-05-10 01:09:44 +02:00
parent f8024b747e
commit 1f157935bf
9 changed files with 282 additions and 128 deletions

View File

@ -49,7 +49,7 @@ class Country(Model):
def __str__(self): def __str__(self):
return f"{self.name} - {self.name_iso}, Mitglied seit {self.euro_member_since}" return f"{self.name} - {self.name_iso}"
@ -85,20 +85,20 @@ class Coin(Model):
found_on = DateField('Gefunden am', auto_now_add=True) found_on = DateField('Gefunden am', auto_now_add=True)
buy_only = BooleanField('Kursmünze', default=False)
circulation = PositiveIntegerField('Auflage', default=0) circulation = PositiveIntegerField('Auflage', default=0)
comment = TextField('Kommentar', default='', blank=True) buy_only = BooleanField('Kursmünze', default=False)
in_collector = BooleanField('Im Eurocollector 2002', default=False)
checked = BooleanField('Von Gigo geprüft und einsortiert', default=False) checked = BooleanField('Von Gigo geprüft und einsortiert', default=False)
in_collector = BooleanField('Im Eurocollector 2002', default=False)
exists = BooleanField('Existiert', default=True) exists = BooleanField('Existiert', default=True)
fault_stamp = BooleanField('Fehlprägung', default=False) fault_stamp = BooleanField('Fehlprägung', default=False)
comment = TextField('Kommentar', default='', blank=True)
def __str__(self): def __str__(self):
return f"Wert: {self.value}, Jahr: {self.year}, Land: {self.country}, Prägerei {self.stamp}, Name {self.name}" return f"{self.country} {self.year} {self.stamp} {self.value} {self.name}"

View File

@ -19,14 +19,7 @@
import { Cookie } from './modules/cookie.mjs'; import { Cookie } from './modules/cookie.mjs';
let settings = {
$(document).ready(function() {
//
// Options
//
let settings = {
found: true, found: true,
found_by: '', found_by: '',
found_on: '', found_on: '',
@ -35,8 +28,106 @@ $(document).ready(function() {
checked: false, checked: false,
ec: false, ec: false,
exists: true exists: true
}
//
// Functions
//
// return a datetime YYYY.MM.DD
function get_datetime() {
let datetime = new Date();
return ('0' + datetime.getDate()).slice(-2) + '.' +
('0' + (datetime.getMonth() + 1)).slice(-2) + '.' +
datetime.getFullYear();
}
// manage user login
function render_login(input_name, input_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>', {
value: name, color: color, html: name
}));
} }
$('nav.navbar option[value=' + name + ']').attr('selected', 'selected');
}
// manage login colors
function render_login_color(color) {
new Cookie('coinc-color', color);
if ($('nav.navbar').css('display') == 'block') {
$('nav.navbar').prop('style', 'background-color:' + color + ' !important; display: block;');
} else {
$('nav.navbar').attr('style', 'background-color:' + color + ' !important;');
}
}
// show/update #found_by and #found_on
function render_found() {
let checked = $('#found').prop('checked');
if (checked) {
console.log(settings);
$('#found_by option[selected=selected]').html(settings['found_by']);
let found_on = ''
if (settings['found_on']) {
found_on = settings['found_on'];
} else {
found_on = get_datetime();
}
$('#found_on').val(found_on);
} else {
save_settings();
$('#found_by option[selected=selected]').html('');
$('#found_on').val('');
}
$('#found_by, #found_on').each(function() {
if (checked) {
$(this).prop('disabled', '');
} else {
$(this).prop('disabled', 'disabled');
}
});
}
// save/update global settings
function save_settings() {
settings['circulation'] = $('#circulation').val();
let found_on = $('#found_on').val();
if (found_on) {
settings['found_on'] = found_on;
} else {
settings['found_on'] = get_datetime();
}
let found_by = $('#found_by option[selected=selected]').html();
console.log(found_by);
if (found_by) {
settings['found_by'] = found_by;
}
let checkboxes = $('#found, #buy_only, #checked, #ec').map(function() {
return { [$(this).prop('id')]: $(this).prop('checked') }
}).get();
for (let box of checkboxes) {
for (let item in box) { settings[item] = box[item]; }
}
console.log(settings);
}
$(document).ready(function() {
// //
// Buttons // Buttons
@ -45,13 +136,61 @@ $(document).ready(function() {
// button #begin_edit // button #begin_edit
$('#begin_edit').click(function() { $('#begin_edit').click(function() {
$('nav.navbar').fadeIn('fast'); $('nav.navbar').fadeIn('fast');
$('button#begin_edit').fadeOut('fast'); $('#begin_edit').fadeOut('fast');
// add coin
$('td.coin').each(function() {
$(this).click(function() {
save_settings();
let csrf_token = $('input[name=csrfmiddlewaretoken]').val();
let value = $(this).attr('value');
let year = Number($(this).parent('tr').attr('name'));
// TODO fix this before the end of 2098
year += (year == 99) ? 1900 : 2000;
let country = $(this).parents('table').attr('name');
let stamp = $(this).parent('tr').attr('stamp');
// TODO
let name = ''
let found_by = (settings['found'] === true) ? settings['found_by'] : ''
let found_on = (settings['found'] === true) ? settings['found_on'] : ''
let circulation = (settings['circulation'] == 'Auflage') ? 0 : settings['circulation'];
let data = {
csrfmiddlewaretoken: csrf_token,
value: value,
year: year,
country: country,
stamp: stamp,
name: name,
found_by: found_by,
found_on: found_on,
circulation: circulation,
buy_only: settings['buy_only'],
checked: settings['checked'],
ec: settings['ec'],
exists: settings['exists']
}
$.ajax({
type: 'POST',
url: 'add/coin',
data: data,
success: function(response) {
if (response.status === 0) {
console.log('yarp');
} else {
console.log('nope');
}
}
});
});
});
}); });
// button #finish_edit // button #finish_edit
$('#finish_edit').click(function() { $('#finish_edit').click(function() {
$('nav.navbar').fadeOut('fast'); $('nav.navbar').fadeOut('fast');
$('button#begin_edit').fadeIn('fast'); $('#begin_edit').fadeIn('fast');
}); });
// button #advanced_options // button #advanced_options
@ -70,22 +209,12 @@ $(document).ready(function() {
}); });
// checkbox #exists // checkbox #exists
$('input#exists').change(function() { $('#exists').change(function() {
if (this.checked === true) { if (this.checked === true) {
// save settings // save settings
settings['circulation'] = $('#circulation').val(); save_settings();
settings['found_on'] = $('#found_on').val();
let checkboxes = $('#found, #buy_only, #checked, #ec')
.map(function() {
return {
[$(this).prop('id')]: $(this).prop('checked')
}
}).get();
for (let box of checkboxes) {
for (let item in box) { settings[item] = box[item]; }
}
// disable settings // disable settings
$('#found, #buy_only, #checked, #ec').each(function() { $('#found, #buy_only, #checked, #ec').each(function() {
@ -132,50 +261,6 @@ $(document).ready(function() {
}); });
//
// Functions
//
// manage user login
function render_login(input_name, input_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>', {
value: name, color: color, html: name
}));
}
$('nav.navbar option[value=' + name + ']').attr('selected', 'selected');
}
// manage login colors
function render_login_color(color) {
new Cookie('coinc-color', color);
if ($('nav.navbar').css('display') == 'block') {
$('nav.navbar').prop('style', 'background-color:' + color + ' !important; display: block;');
} else {
$('nav.navbar').attr('style', 'background-color:' + color + ' !important;');
}
}
function render_found() {
let checked = $('#found').prop('checked');
console.log(checked);
$('#found_by, #found_on').each(function() {
if (checked) {
$(this).prop('disabled', '');
} else {
$(this).prop('disabled', 'disabled');
}
});
}
// //
@ -184,15 +269,15 @@ $(document).ready(function() {
// hide modal add user // hide modal add user
function hide_modal() { function hide_modal() {
$('div#modal_add_user').fadeOut('fast'); $('#modal_add_user').fadeOut('fast');
} }
// modal #add_user // modal #add_user
$('button#show_add_user').click(function() { $('#show_add_user').click(function() {
$('div#modal_add_user').fadeIn('fast'); $('#modal_add_user').fadeIn('fast');
$(document).on('click', function(event) { $(document).on('click', function(event) {
if ($('div#modal_add_user').is(':visible')) { if ($('#modal_add_user').is(':visible')) {
let target = $(event.target); let target = $(event.target);
if (target.attr('id') === 'modal_add_user') { if (target.attr('id') === 'modal_add_user') {
hide_modal(); hide_modal();
@ -211,16 +296,16 @@ $(document).ready(function() {
// button #close_modal_add_user // button #close_modal_add_user
$('button#close_modal_add_user').click(function() { $('#close_modal_add_user').click(function() {
hide_modal(); hide_modal();
}); });
// button #add_user // button #add_user
$('button#add_user').click(function() { $('#add_user').click(function() {
let name = encodeURIComponent($('input#text_user').val()); let name = encodeURIComponent($('#text_user').val());
let color = encodeURIComponent($('input#text_color').val()); let color = encodeURIComponent($('#text_color').val());
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
@ -229,13 +314,13 @@ $(document).ready(function() {
success: function(response) { success: function(response) {
if (response.status === 0) { if (response.status === 0) {
$('span#response').fadeOut('fast'); $('#response').fadeOut('fast');
hide_modal(); hide_modal();
render_login(name, color); render_login(name, color);
} else { } else {
$('span#response').html(response.message); $('#response').html(response.message);
$('span#response').css('color', 'red'); $('#response').css('color', 'red');
} }
} }
}); });
@ -256,7 +341,12 @@ $(document).ready(function() {
render_login(name, color); render_login(name, color);
} else { } else {
//#TODO log in as default if any name = $('#found_by option:first-child').html();
color = $('#found_by option:first-child').val();
render_login(name, color);
} }
save_settings()
render_found();
}); });

View File

@ -1 +1 @@
<td class="{{ td_class }}"><div class="coin">{{ marker }}<div class="{{ div_class }}"></div></div></td> <td class="coin {{ td_class }}" value="{{ value }}"><div class="coin">{{ marker }}<div class="{{ div_class }}"></div></div></td>

View File

@ -5,6 +5,7 @@
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor03" aria-controls="navbarColor03" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor03" aria-controls="navbarColor03" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>
{% csrf_token %}
<div id="advanced_options" class="fixed-bottom"> <div id="advanced_options" class="fixed-bottom">
<label for="circulation"> <label for="circulation">

View File

@ -3,7 +3,7 @@
{% include 'coinc/controlbar.html' with users=users %} {% include 'coinc/controlbar.html' with users=users %}
{% endif %} {% endif %}
<div class="container-fluid"> <div class="container-fluid">
<table> <table name="{{ country.name_iso }}">
<thead> <thead>
<tr> <tr>
<th colspan="12"> <th colspan="12">

View File

@ -1,4 +1,4 @@
{% for stamp in year %} <tr> {% for stamp in year %} <tr name="{{ year_short }}" stamp="{{ stamp }}">
<td class="year"><div class="">{{ stamp }}{{ year_short }}</div></td> <td class="year"><div class="">{{ stamp }}{{ year_short }}</div></td>
{% for value in values %}{% show_coin country year_short stamp value %}{% endfor %} </tr>{% endfor %}{% ifnotequal year|length 1 %} {% for value in values %}{% show_coin country year_short stamp value %}{% endfor %} </tr>{% endfor %}{% ifnotequal year|length 1 %}
<tr> <tr>

View File

@ -28,5 +28,6 @@ urlpatterns = [
path('', views.index, name='index'), path('', views.index, name='index'),
path('statistik', views.statistic, name='statistic'), path('statistik', views.statistic, name='statistic'),
path('<str:name_iso>', views.detail_country, name='country'), path('<str:name_iso>', views.detail_country, name='country'),
path('add/user/<str:username>/color/<str:color>', views.add_user, name='add_user') path('add/user/<str:username>/color/<str:color>', views.add_user, name='add_user'),
path('add/coin', views.add_coin, name='add_coin')
] ]

View File

@ -135,7 +135,6 @@ def show_coin(country, year, stamp, value):
@param stamp: stamp_id @param stamp: stamp_id
@param value: int e [1,2,5,10,20,50,100,200,201,202,203] @param value: int e [1,2,5,10,20,50,100,200,201,202,203]
''' '''
# TODO fix this before the end of 2098 # TODO fix this before the end of 2098
year = int(year) year = int(year)
if year == 99: if year == 99:
@ -149,13 +148,16 @@ def show_coin(country, year, stamp, value):
try: try:
coin = Coin.objects.get(country=country, year=year, stamp=stamp, value=value) coin = Coin.objects.get(country=country, year=year, stamp=stamp, value=value)
except Coin.DoesNotExist: except Coin.DoesNotExist:
return {} return {
'value': value
}
td_class = ''
if coin.buy_only: if coin.buy_only:
td_class = 'buy_only' td_class = 'buy_only'
elif coin.circulation and coin.circulation < 1500000: elif coin.circulation and coin.circulation < 1500000:
td_class = 'rare' td_class = 'rare'
elif coin.noexist: elif not coin.exists:
td_class = 'noexist' td_class = 'noexist'
elif coin.value in [10, 20, 50]: elif coin.value in [10, 20, 50]:
td_class = 'brass' td_class = 'brass'
@ -173,6 +175,7 @@ def show_coin(country, year, stamp, value):
'marker': marker, 'marker': marker,
'td_class': td_class, 'td_class': td_class,
'div_class': div_class, 'div_class': div_class,
'value': value,
} }
@ -198,6 +201,65 @@ def add_user(request, username, color):
return HttpResponse(dumps({ 'status': status, 'message': message })) return HttpResponse(dumps({ 'status': status, 'message': message }))
def add_coin(request):
country = Country.objects.get(name_iso=request.POST['country'])
try:
stamp = Stamp.objects.get(name_short=request.POST['stamp'])
except Stamp.DoesNotExist:
stamp = None
try:
found_by = User.objects.get(name=request.POST['found_by'])
except User.DoesNotExist:
if not request.POST['exists']:
print('errorrr')
exit(0)
found_by = None
buy_only = True if request.POST['buy_only'] == 'true' else False
checked = True if request.POST['checked'] == 'true' else False
ec = True if request.POST['ec'] == 'true' else False
exists = True if request.POST['exists'] == 'true' else False
try:
print('update')
Coin.objects.update(
value=int(request.POST['value']),
year=int(request.POST['year']),
country=country,
stamp=stamp,
name=request.POST['name'],
found_by=found_by,
found_on=request.POST['found_on'],
circulation=request.POST['circulation'],
buy_only=buy_only,
checked=checked,
in_collector=ec,
exists=exists)
except Coin.DoesNotExist:
print('new')
Coin.objects.create(
value=int(request.POST['value']),
year=int(request.POST['year']),
country=country,
stamp=stamp,
name=request.POST['name'],
found_by=found_by,
found_on=request.POST['found_on'],
circulation=request.POST['circulation'],
buy_only=buy_only,
checked=checked,
in_collector=ec,
exists=exists
)
return HttpResponse(dumps({'status': 'ok'}))
# TODO # TODO
def statistic(request): def statistic(request):
''' show statistics ''' ''' show statistics '''

Binary file not shown.