WIP: General CSV importer #90
No reviewers
Labels
No labels
Security
TeX
auto-update
board
done
board
ready
board
todo
check
delete-eslint-rc-js
check
update-builddeps-package-json
check
update-eslint-rc-js
check
update-gitignore
check
update-merge-request-template
check
update-prettier-ignore
check
update-pyproject-toml
check
update-renovate-json
check
update-tox-ini
part
backend
part
ci
part
docs
part
frontend
part
i18n
part
non-technical
part
packaging
prio
1
prio
2
prio
3
release-mr-5.x
size
large
size
medium
size
small
source
customer
source
customer::fsmw
source
customer::fss
source
customer::teckids
source
downstream
type
breaking
type
bug
type
feature
type
refactoring
workflow
blocked
workflow
confirmed
workflow
current-todo
workflow
discussing
workflow
new-app
workflow
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
aleksis/AlekSIS-App-CSVImport!90
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/general-csv-importer"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #11
Closes #12
changed milestone to %5
added 1 commit
b7402243- Fix validatorsCompare with previous version
added 3 commits
e2c9420a- Add models for defining import templates6e871b0c- Move util code to own modulea6cabecb- Add models for defining import templatesCompare with previous version
added 1 commit
55be02d6- Refactor CSV import form and template for general usageCompare with previous version
added 6 commits
00d86982- Update processing of CSV files8d526d0a- Move import code to one function and define some constants68bcbfa4- Move parser for phone numbers and sexes to own functions62bd3c91- Get converters from template field definitione2dc05ad- Validate field typesef5d8ea6- Process date_of_birth only if used in current templateCompare with previous version
added 4 commits
a5a8b209- Add field separator to import templated814ebbc- Add some new field types and a getter method for field types527b2ea9- Improve basic CSV parsing4db2d336- Add teachers template for PedasosCompare with previous version
added 4 commits
b6f2d05a- Activate advanced logging again and deactivate old objectsda05ee54- Add import_ref_csv field53956ea4- Add support for importing the departments of a person (subject-orientated)9d072df6- Reformat and lintCompare with previous version
added 2 commits
61b87c3c- Refactor filese5b9b2ea- Fix regex for whitespaceCompare with previous version
added 1 commit
8a805727- Enable testsuiteCompare with previous version
added 1 commit
2aa0e556- Update dependency of AlekSIS and update poetry.lockCompare with previous version
added 3 commits
8bdddb17- Write tests for converters45da0773- Improve converters791c1995- Reformat and lintCompare with previous version
added 1 commit
4689f642- Write some more unit testsCompare with previous version
added 3 commits
60387bba- Refactor names of some constants9792245c- Move creation of departments to helper function3a630c98- Add Chronos as a dependencyCompare with previous version
added 2 commits
eef3dbfd- Create groups with all imported persons, if wantede23339c0- Fix creation of department groupsCompare with previous version
mentioned in issue #11
added 2 commits
a6c2b4b0- Add field type "NAME"e826c754- Add is_active to update_dict only if the model has the field "is_active" |...Compare with previous version
added 3 commits
afb999f7- Add support for field types which can be used multiple times54c3cf17- Add helper method bulk_get_or_create42f57320- Add support for group owners by short name (multiple cols)Compare with previous version
added 1 commit
0ad1a452- Add import template for classes from PedasosCompare with previous version
added 1 commit
366edce6- Add support for setting a group type for all objectsCompare with previous version
added 3 commits
747e4f12- Use progress bar to track import status700ce085- Add support for group subjects and Pedasos class ranges3ed8cf01- Add template for Pedasos coursesCompare with previous version
added 3 commits
d3dda1b1- Add support for importing group memberships6076649b- Add support for importing guardians from students list9476781d- Add template for students from PedasosCompare with previous version
added 1 commit
4349d1a0- Add admin.pyCompare with previous version
added 1 commit
30d0d43a- Fix connection of subjects to department groups (update or create GroupSubject)Compare with previous version
Ready for review, @nik.
Tested with real data.
unmarked as a Work In Progress
assigned to @nik
What is the benefit of this function, compared to just calling
strptime? Sure, it suppresses theValueError, but is that always correct? Even if that is the case, maybe we want a wrapper that allows passing a format string and suppresses the exception, but even then, I would prefer handling the exception everywhere where it can occur instead. Wrapping a silenttry/except passin a function will ultimately lead to misconceptions about the code using it.If I see it correctly, there is no alternative to silently catch the exception because the parse functions are all directly used by pandas'
read_csvfunction.But using a wrapper to provide different format strings seems to be a good idea.
This documentation is too unspecific. What exactly is "parsed"? I do, actually, not see any parsing done in this function. If I get the code right, it simply splits the string and suppresses any non-truethy values. Again, while on first glance having a function that hides the list/filter/lambda construct makes teh code calling it more readable, on second glance, it leads to misconceptions.
I'd call it
split_commaand usere.split(",+", value)instead of the filter construct, which I consider most readable. However, it seemsre.splitis really slow:(measured on 1,000,000 operations)
In any case, I stick with renaming the function and properly documenting it.
I see a common anti-pattern of creating a function that silences an exception and falsely claiming it were doing some parsing. This should, in all cases in this file, be clearly visible in the name of the function.
Please use relative imports for imports from the same package.
Okay, should I rename them to
convert_xy_or_noneor what else?This should be an injected method on
Subjectusing themodel_extensionsmechanism (or even a method onSubjectin chronos itself, or on a manager).Besides being cleaner, that circumvents the model import in
utilcode — it is best practice to not have code in autilmodule depend on model initialisation, because depending on models being ready in utility code will backfire on you or the developer next door some time soon.Same here as in last comment.
s/list/Sequence, because, what's wrong with a tuple?Missing docstring.
These must be explained. Even if this implements a very specific use case for a geographically limited data source, it dhould still be somewhat conceivable for other developers (maybe intending to fork this importer for other use cases). Probaby a good way would be to explain what Pedasos is and what kind of school system it implies in a module docstring.
The name clash between the programming term
classand theschool classis still very unfortunate. If you have an idea, please rename it (and we should do that globally in turn). If not, just resolve this thread as wont-fix.(NB. The British term
form, besides sounding stupid, doesn't help much either 😂.)This does not hold what the docstring promises. It will return at most one object for each short name, not all short names that match, and is more likely to raise an exception on second occurance than it is to magically come up with a list as value ;).
Missing return type.
Missing return type.
Missing return tyoe (please check this mistake on other functions yourself).
Fortunately the short name is unique 😂
You're most welcome here ;).
Self review: CSVImport is official again.
Please use
contextlib.suppressto make the intention clear.This (and the following settings) look very much as if they should be defaults inside one importer.
Uh, that's one opinionated default.
Maybe this should be a global setting as well, or probably even a preference.
templates.pyis an unfortunate naming. It will at some point in time cause confusion with thetemplateddirectory. Although Python made an__init__.pymandotory some time ago to make a directory recognisable as a package, I would not count on every tool out there having realised that by now. Probably jsut move this toutil/.Please use relative imports.
ANother argument: Until I read more of the code, I thought you were actually talking about Django templates. Avoid such ambiguous naming. I propose
sourceinstead oftemplate.It seems that hard-coded German date format has a lot of occurances.
This part of the code looks funny. You are allowed to make sarcastic comments about third-party software that explain why such a mess is necessary ;).
Already posted a a clear notion in other comments, but in general: I do not like the mixing of opinionated code, source-spiecific code, and global utility code. Each supported import source should be in a seaprate package. Probably using a base class that uses the general settings, and sub-classes with importer-specific defaults and code. Most of the utility functions should be methods on these classes. Object-orientation was invented for a reason :).
Feel free to do that ;-)
Nope, not going to tidy up your code :).
That makes it even more questionnable what this function is for. You cannot group a single object, "group by short_name" means there are several objects with a common key that are grouped together, resulting in a
Dict[str, Sequence]type.And your's also :) (a little bit)
added 1 commit
a5bc6ac2- Update path of progress templateCompare with previous version
marked as a Work In Progress
added 1 commit
efca55fb- Use virtual foreign key for linking subjects to groupsCompare with previous version
TODO: Use school term for groups
added 1 commit
ff5de98c- Add support for import of school term related dataCompare with previous version
TODO: Set primary group of persons.
changed the description
changed the description
Done.
changed this line in version 26 of the diff
added 2 commits
67bf161c- Filter groups created while importing other objects by school term1b221201- Import primary groups of persons correctlyCompare with previous version
changed this line in version 27 of the diff
added 2 commits
6f6794b9- Update poetry.lock91e484cc- ReformatCompare with previous version
added 1 commit
6f83472e- Fix URL to save buttonCompare with previous version
added 1 commit
4a90c4cc- Catch IndexError exception while getting current school termCompare with previous version
added 1 commit
d30b60ce- Mark imported objects with flag to identify them laterCompare with previous version
added 1 commit
6575cef9- Delete old group membershipsCompare with previous version
added 1 commit
fc5402e1- Fix importCompare with previous version
changed this line in version 33 of the diff
added 2 commits
85813975- Catch error in app config19d64d20- ReformatCompare with previous version
changed the description
Pull request closed