begin add coins :)))
This commit is contained in:
parent
f8024b747e
commit
1f157935bf
@ -49,7 +49,7 @@ class Country(Model):
|
||||
|
||||
|
||||
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)
|
||||
|
||||
buy_only = BooleanField('Kursmünze', default=False)
|
||||
|
||||
circulation = PositiveIntegerField('Auflage', default=0)
|
||||
|
||||
comment = TextField('Kommentar', default='', blank=True)
|
||||
|
||||
in_collector = BooleanField('Im Eurocollector 2002', default=False)
|
||||
buy_only = BooleanField('Kursmünze', 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)
|
||||
|
||||
fault_stamp = BooleanField('Fehlprägung', default=False)
|
||||
|
||||
comment = TextField('Kommentar', default='', blank=True)
|
||||
|
||||
|
||||
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}"
|
||||
|
@ -1,32 +1,25 @@
|
||||
/*
|
||||
|
||||
Copyright (C) 2020 willipink.eu
|
||||
Author Moritz Münch moritzmuench@mailbox.org
|
||||
Copyright (C) 2020 willipink.eu
|
||||
Author Moritz Münch moritzmuench@mailbox.org
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
|
||||
import { Cookie } from './modules/cookie.mjs';
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
//
|
||||
// Options
|
||||
//
|
||||
|
||||
let settings = {
|
||||
let settings = {
|
||||
found: true,
|
||||
found_by: '',
|
||||
found_on: '',
|
||||
@ -35,57 +28,193 @@ $(document).ready(function() {
|
||||
checked: false,
|
||||
ec: false,
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Buttons
|
||||
//
|
||||
// manage user login
|
||||
function render_login(input_name, input_color) {
|
||||
|
||||
// button #begin_edit
|
||||
$('#begin_edit').click(function() {
|
||||
$('nav.navbar').fadeIn('fast');
|
||||
$('button#begin_edit').fadeOut('fast');
|
||||
});
|
||||
let color = decodeURIComponent(input_color);
|
||||
let name = decodeURIComponent(input_name);
|
||||
new Cookie('coinc-name', name)
|
||||
|
||||
// button #finish_edit
|
||||
$('#finish_edit').click(function() {
|
||||
$('nav.navbar').fadeOut('fast');
|
||||
$('button#begin_edit').fadeIn('fast');
|
||||
});
|
||||
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
|
||||
}));
|
||||
}
|
||||
|
||||
// button #advanced_options
|
||||
$('#show_advanced_options').click(function() {
|
||||
$('#advanced_options').slideToggle();
|
||||
});
|
||||
$('nav.navbar option[value=' + name + ']').attr('selected', 'selected');
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Misc
|
||||
//
|
||||
// manage login colors
|
||||
function render_login_color(color) {
|
||||
|
||||
// checkbox #found
|
||||
$('#found').change(function() {
|
||||
render_found();
|
||||
});
|
||||
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
|
||||
//
|
||||
|
||||
// button #begin_edit
|
||||
$('#begin_edit').click(function() {
|
||||
$('nav.navbar').fadeIn('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
|
||||
$('#finish_edit').click(function() {
|
||||
$('nav.navbar').fadeOut('fast');
|
||||
$('#begin_edit').fadeIn('fast');
|
||||
});
|
||||
|
||||
// button #advanced_options
|
||||
$('#show_advanced_options').click(function() {
|
||||
$('#advanced_options').slideToggle();
|
||||
});
|
||||
|
||||
|
||||
//
|
||||
// Misc
|
||||
//
|
||||
|
||||
// checkbox #found
|
||||
$('#found').change(function() {
|
||||
render_found();
|
||||
});
|
||||
|
||||
// checkbox #exists
|
||||
$('input#exists').change(function() {
|
||||
$('#exists').change(function() {
|
||||
|
||||
if (this.checked === true) {
|
||||
|
||||
// save settings
|
||||
settings['circulation'] = $('#circulation').val();
|
||||
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]; }
|
||||
}
|
||||
save_settings();
|
||||
|
||||
// disable settings
|
||||
$('#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
|
||||
function hide_modal() {
|
||||
$('div#modal_add_user').fadeOut('fast');
|
||||
$('#modal_add_user').fadeOut('fast');
|
||||
}
|
||||
|
||||
// modal #add_user
|
||||
$('button#show_add_user').click(function() {
|
||||
$('div#modal_add_user').fadeIn('fast');
|
||||
$('#show_add_user').click(function() {
|
||||
$('#modal_add_user').fadeIn('fast');
|
||||
|
||||
$(document).on('click', function(event) {
|
||||
if ($('div#modal_add_user').is(':visible')) {
|
||||
if ($('#modal_add_user').is(':visible')) {
|
||||
let target = $(event.target);
|
||||
if (target.attr('id') === 'modal_add_user') {
|
||||
hide_modal();
|
||||
@ -211,16 +296,16 @@ $(document).ready(function() {
|
||||
|
||||
|
||||
// button #close_modal_add_user
|
||||
$('button#close_modal_add_user').click(function() {
|
||||
$('#close_modal_add_user').click(function() {
|
||||
hide_modal();
|
||||
});
|
||||
|
||||
|
||||
// button #add_user
|
||||
$('button#add_user').click(function() {
|
||||
$('#add_user').click(function() {
|
||||
|
||||
let name = encodeURIComponent($('input#text_user').val());
|
||||
let color = encodeURIComponent($('input#text_color').val());
|
||||
let name = encodeURIComponent($('#text_user').val());
|
||||
let color = encodeURIComponent($('#text_color').val());
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
@ -229,13 +314,13 @@ $(document).ready(function() {
|
||||
success: function(response) {
|
||||
|
||||
if (response.status === 0) {
|
||||
$('span#response').fadeOut('fast');
|
||||
$('#response').fadeOut('fast');
|
||||
hide_modal();
|
||||
render_login(name, color);
|
||||
|
||||
} else {
|
||||
$('span#response').html(response.message);
|
||||
$('span#response').css('color', 'red');
|
||||
$('#response').html(response.message);
|
||||
$('#response').css('color', 'red');
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -256,7 +341,12 @@ $(document).ready(function() {
|
||||
render_login(name, color);
|
||||
|
||||
} 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();
|
||||
|
||||
});
|
||||
|
@ -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>
|
||||
|
@ -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">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
{% csrf_token %}
|
||||
|
||||
<div id="advanced_options" class="fixed-bottom">
|
||||
<label for="circulation">
|
||||
|
@ -3,7 +3,7 @@
|
||||
{% include 'coinc/controlbar.html' with users=users %}
|
||||
{% endif %}
|
||||
<div class="container-fluid">
|
||||
<table>
|
||||
<table name="{{ country.name_iso }}">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="12">
|
||||
|
@ -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>
|
||||
{% for value in values %}{% show_coin country year_short stamp value %}{% endfor %} </tr>{% endfor %}{% ifnotequal year|length 1 %}
|
||||
<tr>
|
||||
|
@ -28,5 +28,6 @@ urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
path('statistik', views.statistic, name='statistic'),
|
||||
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')
|
||||
]
|
||||
|
@ -135,7 +135,6 @@ def show_coin(country, year, stamp, value):
|
||||
@param stamp: stamp_id
|
||||
@param value: int e [1,2,5,10,20,50,100,200,201,202,203]
|
||||
'''
|
||||
|
||||
# TODO fix this before the end of 2098
|
||||
year = int(year)
|
||||
if year == 99:
|
||||
@ -149,13 +148,16 @@ def show_coin(country, year, stamp, value):
|
||||
try:
|
||||
coin = Coin.objects.get(country=country, year=year, stamp=stamp, value=value)
|
||||
except Coin.DoesNotExist:
|
||||
return {}
|
||||
return {
|
||||
'value': value
|
||||
}
|
||||
|
||||
td_class = ''
|
||||
if coin.buy_only:
|
||||
td_class = 'buy_only'
|
||||
elif coin.circulation and coin.circulation < 1500000:
|
||||
td_class = 'rare'
|
||||
elif coin.noexist:
|
||||
elif not coin.exists:
|
||||
td_class = 'noexist'
|
||||
elif coin.value in [10, 20, 50]:
|
||||
td_class = 'brass'
|
||||
@ -173,6 +175,7 @@ def show_coin(country, year, stamp, value):
|
||||
'marker': marker,
|
||||
'td_class': td_class,
|
||||
'div_class': div_class,
|
||||
'value': value,
|
||||
}
|
||||
|
||||
|
||||
@ -198,6 +201,65 @@ def add_user(request, username, color):
|
||||
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
|
||||
def statistic(request):
|
||||
''' show statistics '''
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user