summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorparth2012-03-19 22:32:12 +0530
committerparth2012-03-19 22:32:12 +0530
commitf3f59791bb4b272271c851b1ca34b131fae1a9d9 (patch)
treeab7bf0c4ade6b7bc984ca1db4f8e7fe2acca07f0
parent2c97aecefd592649e88f5ace6ed39ef98f93089d (diff)
downloadaloha-f3f59791bb4b272271c851b1ca34b131fae1a9d9.tar.gz
aloha-f3f59791bb4b272271c851b1ca34b131fae1a9d9.tar.bz2
aloha-f3f59791bb4b272271c851b1ca34b131fae1a9d9.zip
added management files
-rw-r--r--allotter/management/__init__.py0
-rw-r--r--allotter/management/commands/__init__.py0
-rw-r--r--allotter/management/commands/loadexam.py40
-rw-r--r--allotter/management/commands/loadoptions.py51
4 files changed, 91 insertions, 0 deletions
diff --git a/allotter/management/__init__.py b/allotter/management/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/allotter/management/__init__.py
diff --git a/allotter/management/commands/__init__.py b/allotter/management/commands/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/allotter/management/commands/__init__.py
diff --git a/allotter/management/commands/loadexam.py b/allotter/management/commands/loadexam.py
new file mode 100644
index 0000000..2fedb66
--- /dev/null
+++ b/allotter/management/commands/loadexam.py
@@ -0,0 +1,40 @@
+from csv import reader
+from django.core.management.base import BaseCommand, CommandError
+from allotter.models import Exam
+
+class Command(BaseCommand):
+ args = '<file_name...>'
+ help = "Give the filename of the csv file that has all the exam code and exam name relation"
+
+ def handle(self, *args, **options):
+
+ clean_exam()
+
+ for fname in args:
+ load_exam(fname)
+
+ self.stdout.write('Done\n')
+
+
+def clean_exam():
+ """Removes all the objects from the database, required as if not done there might be a case of multile entries"""
+ data = Exam.objects.all()
+ data.delete()
+
+def load_exam(filename):
+ """Load exam code and exam name from the given csv file. The file should
+ declare a list of "exam_code;exam_name".
+ """
+ try:
+ csvFile = open(filename, 'rb')
+ except IOError as (errno,strerror):
+ print "I/O error({0}): {1}".format(errno, strerror)
+
+ csvReader = reader(csvFile, delimiter=";")
+
+ for data in csvReader:
+ new_exam = Exam.objects.create()
+ new_exam.exam_code = data[0]
+ new_exam.exam_name = data[1]
+ new_exam.save()
+ print "Added ({0} : {1})".format(data[0], data[1]) \ No newline at end of file
diff --git a/allotter/management/commands/loadoptions.py b/allotter/management/commands/loadoptions.py
new file mode 100644
index 0000000..afa7234
--- /dev/null
+++ b/allotter/management/commands/loadoptions.py
@@ -0,0 +1,51 @@
+import argparse
+from csv import reader
+from django.core.management.base import BaseCommand, CommandError
+from allotter.models import Exam, Option
+
+class Command(BaseCommand):
+ args = '<file_name...>'
+ help = "Give the filename of the csv file that has all the option code, name and exam code relation"
+
+ def handle(self, *args, **options):
+
+ clean_option()
+
+ parser = argparse.ArgumentParser(description='Process some integers.')
+
+ parser.add_argument('-pcc',metavar='Paper course code file name', type=str)
+ parser.add_argument('-cc',metavar='Course code file name', type=str)
+
+ args = parser.parse_args()
+
+ load_option(vars(args)['pcc'])
+
+ self.stdout.write('Done\n')
+
+
+def clean_option():
+ """Removes all the objects from the database, required as if not done there might be a case of multiple entries"""
+ data = Option.objects.all()
+ data.delete()
+
+def load_option(filename):
+ """Load option code and option name from the given csv file. The file should
+ declare a list of "exam_code,option_code,option,code".
+ """
+ try:
+ csvFile = open(filename, 'rb')
+ except IOError as (errno,strerror):
+ print "I/O error({0}): {1}".format(errno, strerror)
+
+ csvReader = reader(csvFile, delimiter=",")
+
+ for data in csvReader:
+ exam = Exam.objects.get(exam_code=data[0])
+ for value in data[1:len(data)]:
+ try:
+ new_option = Option.objects.get(opt_code=value)
+ except Option.DoesNotExist:
+ new_option = Option(opt_name="Test",opt_code=value)
+ new_option.save()
+ new_option.exam.add(exam)
+ print "Added (option Test with code {0} and exam {1})".format(value,exam)