Skip to content
Snippets Groups Projects
Commit 6a17ebae authored by Tomáš Valenta's avatar Tomáš Valenta
Browse files

wip - ares data loading

parent 404253ce
Branches
No related tags found
No related merge requests found
from django.contrib import admin from django.contrib import admin
from django.utils.html import format_html
from shared.admin import MarkdownxGuardedModelAdmin from shared.admin import MarkdownxGuardedModelAdmin
...@@ -156,8 +157,32 @@ class SigneeRepresentativeInline(admin.TabularInline): ...@@ -156,8 +157,32 @@ class SigneeRepresentativeInline(admin.TabularInline):
class SigneeAdmin(MarkdownxGuardedModelAdmin): class SigneeAdmin(MarkdownxGuardedModelAdmin):
form = SigneeAdminForm form = SigneeAdminForm
fields = (
"name",
"entity_type",
"address_street_with_number",
"address_district",
"address_zip",
"address_country",
"ico_number",
"load_ares_data_button",
"date_of_birth",
"department",
"role",
)
readonly_fields = ("load_ares_data_button",)
inlines = (SigneeRepresentativeInline,) inlines = (SigneeRepresentativeInline,)
def load_ares_data_button(self, obj):
return format_html(
"<button type=\"button\" id=\"load_ares_data\">Načíst data</button>"
)
load_ares_data_button.allow_tags = True
load_ares_data_button.short_description = "ARES"
class ContracteeRepresentativeInline(admin.TabularInline): class ContracteeRepresentativeInline(admin.TabularInline):
form = ContractFileAdminForm form = ContractFileAdminForm
......
...@@ -73,6 +73,7 @@ class Signee(models.Model): ...@@ -73,6 +73,7 @@ class Signee(models.Model):
blank=True, blank=True,
null=True, null=True,
verbose_name="IČO", verbose_name="IČO",
help_text="Vyplněním můžeš automaticky načíst data z ARES."
) # WARNING: Legal entity status dependent! ) # WARNING: Legal entity status dependent!
date_of_birth = models.DateField( date_of_birth = models.DateField(
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"dependencies": { "dependencies": {
"@tailwindcss/typography": "^0.5.9", "@tailwindcss/typography": "^0.5.9",
"alertifyjs": "^1.13.1",
"css-loader": "^6.7.3", "css-loader": "^6.7.3",
"jquery": "^3.6.3", "jquery": "^3.6.3",
"style-loader": "^3.3.1", "style-loader": "^3.3.1",
...@@ -21,6 +22,6 @@ ...@@ -21,6 +22,6 @@
"vue": "v2-latest", "vue": "v2-latest",
"webpack": "^5.75.0", "webpack": "^5.75.0",
"webpack-bundle-tracker": "^1.8.0", "webpack-bundle-tracker": "^1.8.0",
"webpack-cli": "^5.0.1" "webpack-cli": "^5.0.1",
} }
} }
import $ from "jquery"; import $ from "jquery";
import alertify from "alertifyjs";
const xmlParser = require("xml2json");
const fieldDepartmentValues = new Set([ const fieldDepartmentValues = new Set([
"legal_entity", "legal_entity",
...@@ -19,7 +22,7 @@ $(window).ready( ...@@ -19,7 +22,7 @@ $(window).ready(
) )
); );
$(".field-ico_number"). $(".field-ico_number,.field-load_ares_data_button").
css( css(
"display", "display",
( (
...@@ -55,7 +58,7 @@ $(window).ready( ...@@ -55,7 +58,7 @@ $(window).ready(
"block" : "none" "block" : "none"
) )
); );
$(".field-ico_number"). $(".field-ico_number,.field-load_ares_data_button").
css( css(
"display", "display",
( (
...@@ -78,5 +81,31 @@ $(window).ready( ...@@ -78,5 +81,31 @@ $(window).ready(
if (!fieldDepartmentValues.has($(event.target).val()) && !isEmpty) $("#id_department").val(""); if (!fieldDepartmentValues.has($(event.target).val()) && !isEmpty) $("#id_department").val("");
} }
); );
$("#load_ares_data").on(
"click",
async (event) => {
const icoValue = $("#id_ico_number").val();
const aresXMLResponse = await fetch(
`https://wwwinfo.mfcr.cz/cgi-bin/ares/darv_std.cgi?ico=${icoValue}`
);
if (!aresXMLResponse.ok) {
alertify.error("Chyba při načítní dat z ARES. Je IČO správné?");
console.warn(
"Error loading ARES data: ",
await aresXMLResponse.text()
);
return;
}
const formattedAresResponse = xmlParser.toJson(aresXMLResponse);
console.log(formattedAresResponse);
}
);
} }
); );
...@@ -41,4 +41,14 @@ module.exports = { ...@@ -41,4 +41,14 @@ module.exports = {
plugins: [ plugins: [
new BundleTracker({filename: './webpack-stats.json'}) new BundleTracker({filename: './webpack-stats.json'})
], ],
resolve: {
fallback: {
"path": require.resolve("path-browserify"),
"crypto": require.resolve("crypto-browserify"),
"assert": require.resolve("assert/"),
"buffer": require.resolve("buffer/"),
"stream": require.resolve("stream-browserify"),
},
extensions: [".js"],
}
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment