Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
royalty calculation - model, admin, form, html
- Loading branch information
1 parent
63abb92
commit 81c1bd0
Showing
7 changed files
with
626 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 3.0.6 on 2020-06-06 10:53 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('music_publisher', '0005_work__work_id'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='RoyaltyCalculation', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('in_file', models.FileField(upload_to='')), | ||
('out_file', models.FileField(upload_to='')), | ||
], | ||
options={ | ||
'managed': False, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
from django.contrib import admin, messages | ||
from django.db import models | ||
from django import forms | ||
from django.conf import settings | ||
|
||
from .models import WorkAcknowledgement, SOCIETY_DICT | ||
|
||
|
||
class RoyaltyCalculation(models.Model): | ||
class Meta: | ||
managed = False | ||
in_file = models.FileField(verbose_name='Incoming statement') | ||
out_file = models.FileField(blank=True, null=True) | ||
|
||
|
||
class RoyaltyCalculationForm(forms.ModelForm): | ||
class Meta: | ||
fields = ('in_file', ) | ||
|
||
def get_id_sources(): | ||
yield None, settings.PUBLISHER_NAME | ||
codes = WorkAcknowledgement.objects.values_list('society_code', flat=True) | ||
codes = [(code, SOCIETY_DICT.get(code, '') ) for code in codes] | ||
codes.sort(key=lambda code: code[1]) | ||
for code in codes: | ||
yield code | ||
|
||
def get_right_types(): | ||
yield 'p', 'Performance' | ||
yield 'm', 'Mechanical' | ||
yield 's', 'Sync' | ||
|
||
SPLITS = [ | ||
('cw', 'Controlled writers only'), | ||
('cwp', 'Controlled writers and {}'.format(settings.PUBLISHER_NAME)), | ||
] | ||
|
||
work_id_column = forms.ChoiceField(choices=[], label='Work ID', required=False) | ||
work_id_source = forms.ChoiceField(choices=get_id_sources, required=False) | ||
amount_column = forms.ChoiceField(choices=[], label='Amount', required=False) | ||
right_type_column = forms.ChoiceField(choices=get_right_types, label='Right Type') | ||
split = forms.ChoiceField(choices=SPLITS) | ||
apply_fees = forms.BooleanField(required=False) | ||
default_fee = forms.DecimalField(max_digits=5, decimal_places=2, initial=0) | ||
|
||
def clean(self): | ||
print('cleaning_form') | ||
super().clean() | ||
|
||
def save(self, commit=True): | ||
print('saving form') | ||
return super().save(commit) | ||
|
||
|
||
@admin.register(RoyaltyCalculation) | ||
class RoyaltyCalculationAdmin(admin.ModelAdmin): | ||
|
||
form = RoyaltyCalculationForm | ||
change_form_template = 'admin/royalty_calculation_form.html' | ||
|
||
fieldsets = ( | ||
('Incoming statement', { | ||
'fields': ( | ||
'in_file', | ||
), | ||
}), | ||
('Columns', { | ||
'fields': ( | ||
('work_id_column', 'work_id_source'), | ||
'right_type_column', | ||
'amount_column' | ||
), | ||
}), | ||
('Algorithm', { | ||
'fields': ( | ||
('split', 'apply_fees'), | ||
'default_fee', | ||
), | ||
}), | ||
) | ||
|
||
save_as = False | ||
|
||
def add_view(self, request, form_url='', extra_context=None): | ||
response = super().add_view(request, form_url='', extra_context=None) | ||
print(response) | ||
return response | ||
|
||
def has_delete_permission(self, request, obj=None): | ||
return False | ||
|
||
def has_change_permission(self, request, obj=None): | ||
return False | ||
|
||
def has_view_permission(self, request, obj=None): | ||
return False | ||
|
||
def save_form(self, request, form, change): | ||
# returns object | ||
print('save form') | ||
r = super().save_form(request, form, change) | ||
print(type(r)) | ||
return r | ||
|
||
def save_model(self, request, obj, form, change): | ||
print('save_model') | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
music_publisher/templates/admin/royalty_calculation_form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
{% extends "admin/change_form.html" %} | ||
{% load i18n admin_urls static admin_modify %} | ||
|
||
{% block extrahead %}{{ block.super }}{% endblock %} | ||
|
||
{% block extrastyle %}{{ block.super }}{% endblock %} | ||
|
||
{% block content_title %}<h1>{% blocktrans with name=opts.verbose_name %}{{ name }}{% endblocktrans %}</h1>{% endblock %} | ||
|
||
{% if not is_popup %} | ||
{% block breadcrumbs %} | ||
<div class="breadcrumbs"> | ||
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a> | ||
› <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_config.verbose_name }}</a> | ||
› {% if has_view_permission %}<a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} | ||
› {% blocktrans with name=opts.verbose_name %}{{ name }}{% endblocktrans %} | ||
</div> | ||
{% endblock %} | ||
{% endif %} | ||
|
||
{% block content %}<div id="content-main"> | ||
{% block object-tools %} | ||
{% if change %}{% if not is_popup %} | ||
<ul class="object-tools"> | ||
{% block object-tools-items %} | ||
{% change_form_object_tools %} | ||
{% endblock %} | ||
</ul> | ||
{% endif %}{% endif %} | ||
{% endblock %} | ||
<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.model_name }}_form" novalidate>{% csrf_token %}{% block form_top %}{% endblock %} | ||
<div> | ||
{% if is_popup %}<input type="hidden" name="{{ is_popup_var }}" value="1">{% endif %} | ||
{% if to_field %}<input type="hidden" name="{{ to_field_var }}" value="{{ to_field }}">{% endif %} | ||
{% if save_on_top %}{% block submit_buttons_top %}{% submit_row %}{% endblock %}{% endif %} | ||
{% if errors %} | ||
<p class="errornote"> | ||
{% if errors|length == 1 %}{% trans "Please correct the error below." %}{% else %}{% trans "Please correct the errors below." %}{% endif %} | ||
</p> | ||
{{ adminform.form.non_field_errors }} | ||
{% endif %} | ||
|
||
{% block field_sets %} | ||
{% for fieldset in adminform %} | ||
{% include "admin/includes/fieldset.html" %} | ||
{% endfor %} | ||
{% endblock %} | ||
|
||
{% block after_field_sets %}{% endblock %} | ||
|
||
{% block inline_field_sets %} | ||
{% for inline_admin_formset in inline_admin_formsets %} | ||
{% include inline_admin_formset.opts.template %} | ||
{% endfor %} | ||
{% endblock %} | ||
|
||
{% block after_related_objects %}{% endblock %} | ||
|
||
{% block submit_buttons_bottom %}<div class="submit-row"> | ||
<input type="submit" value="Process" class="default" name="_save"> | ||
</div>{% endblock %} | ||
|
||
{% block admin_change_form_document_ready %} | ||
<script type="text/javascript" | ||
id="django-admin-form-add-constants" | ||
src="{% static 'admin/js/change_form.js' %}" | ||
{% if adminform and add %} | ||
data-model-name="{{ opts.model_name }}" | ||
{% endif %}> | ||
</script> | ||
{% endblock %} | ||
|
||
{# JavaScript for prepopulated fields #} | ||
{% prepopulated_fields_js %} | ||
|
||
</div> | ||
</form></div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.