Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #107: specify seperator in GUI interface #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions csvimport/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import locale
from datetime import datetime
from django import forms
from django.db import models
Expand All @@ -16,6 +17,7 @@ class CSVImportAdmin(ModelAdmin):
"field_list",
"upload_file",
"file_name",
"delimiter",
"encoding",
"upload_method",
"error_log_html",
Expand All @@ -25,6 +27,11 @@ class CSVImportAdmin(ModelAdmin):
models.CharField: {"widget": forms.Textarea(attrs={"rows": "1", "cols": "40"})},
}

def get_changeform_initial_data(self, request):
#This works for my problem, but I don't know if there are side effects. So I won't push it
#locale.setlocale(locale.LC_ALL, '')
return {'delimiter': ";" if locale.localeconv()['decimal_point'] == "," else ","}

def save_model(self, request, obj, form, change):
""" Do save and process command - cant commit False
since then file wont be found for reopening via right charset
Expand All @@ -42,6 +49,7 @@ def save_model(self, request, obj, form, change):
charset=obj.encoding,
uploaded=obj.upload_file,
defaults=defaults,
delimiter=obj.delimiter,
)
errors = cmd.run(logid=obj.id)
if errors:
Expand Down
18 changes: 18 additions & 0 deletions csvimport/migrations/0002_csvimport_model_name_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.5 on 2021-01-25 21:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('csvimport', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='csvimport',
name='model_name',
field=models.CharField(default='app_label.model_name', help_text='Please specify the app_label.model_name', max_length=255),
),
]
18 changes: 18 additions & 0 deletions csvimport/migrations/0003_csvimport_delimiter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.5 on 2021-01-25 21:36

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('csvimport', '0002_csvimport_model_name_default'),
]

operations = [
migrations.AddField(
model_name='csvimport',
name='delimiter',
field=models.CharField(default=',', max_length=1),
),
]
1 change: 1 addition & 0 deletions csvimport/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class CSVImport(models.Model):
)
upload_file = models.FileField(upload_to="csv", storage=fs)
file_name = models.CharField(max_length=255, blank=True)
delimiter = models.CharField(max_length=1, default=",")
encoding = models.CharField(max_length=32, blank=True)
upload_method = models.CharField(
blank=False, max_length=50, default="manual", choices=CHOICES
Expand Down