diff options
author | prathamesh | 2017-11-06 14:50:21 +0530 |
---|---|---|
committer | prathamesh | 2017-11-06 14:50:21 +0530 |
commit | cde2eeb4f15de06def22d3bf07120a0a416e807f (patch) | |
tree | f2d1a713796f22339377f066cfad7b9423b9ccb8 /yaksh/file_utils.py | |
parent | 840c00b9e939d2b33058d236ef4170923e0a018b (diff) | |
download | online_test-cde2eeb4f15de06def22d3bf07120a0a416e807f.tar.gz online_test-cde2eeb4f15de06def22d3bf07120a0a416e807f.tar.bz2 online_test-cde2eeb4f15de06def22d3bf07120a0a416e807f.zip |
Upload user to the course via csv.
The csv takes firstname, lastname and email.
User and Profile are created with username and password been same as
email.
Following cases are handled for csv upload:
- wrong csv headders
- missing csv values
- already existing users
- invalid csv
Diffstat (limited to 'yaksh/file_utils.py')
-rw-r--r-- | yaksh/file_utils.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/yaksh/file_utils.py b/yaksh/file_utils.py index f41c531..361b29c 100644 --- a/yaksh/file_utils.py +++ b/yaksh/file_utils.py @@ -2,7 +2,7 @@ import shutil import os import zipfile import tempfile - +import csv def copy_files(file_paths): """ Copy Files to current directory, takes @@ -50,3 +50,30 @@ def extract_files(zip_file, path=None): zip_file.close() return zfiles, extract_path + +def is_csv(document): + try: + try: + content = document.read(1024).decode('utf-8') + except AttributeError: + document.seek(0) + content = document.read(1024) + sniffer = csv.Sniffer() + dialect = sniffer.sniff(content) + document.seek(0) + except (csv.Error, UnicodeDecodeError): + return False + return True + + +def headers_present(dict_reader, headers): + fields = dict_reader.fieldnames + clist = set() + for field in fields: + if field.strip() in headers.keys(): + headers[field.strip()] = field + clist.add(field.strip()) + if clist != headers.keys(): + return False + return True + |