summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrimal Pappachan2012-03-20 11:55:17 +0530
committerPrimal Pappachan2012-03-20 11:55:17 +0530
commit8df546efd5b4821c7e1d2b500026380f490cc6c4 (patch)
tree1aab84f974827bf2ff0f89f8db43bf950403f7cc
parent4f63e2eca861d597c1041bbf58c63ea4ea3e9a61 (diff)
parent64f6b14cc6c1ee3cec4c2d65e6a130441555b6b4 (diff)
downloadaloha-8df546efd5b4821c7e1d2b500026380f490cc6c4.tar.gz
aloha-8df546efd5b4821c7e1d2b500026380f490cc6c4.tar.bz2
aloha-8df546efd5b4821c7e1d2b500026380f490cc6c4.zip
Merge github.com:FOSSEE/aloha
-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.py60
-rw-r--r--allotter/management/commands/loadusers.py65
-rw-r--r--allotter/models.py4
6 files changed, 167 insertions, 2 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..f7c01e6
--- /dev/null
+++ b/allotter/management/commands/loadoptions.py
@@ -0,0 +1,60 @@
+from optparse import make_option
+from csv import reader
+from django.core.management.base import BaseCommand
+from allotter.models import Exam, Option
+
+class Command(BaseCommand):
+ option_list = BaseCommand.option_list + (
+ make_option('--pcc',metavar='Paper course code file name', type=str),
+ make_option('--cc',metavar='Course code file name', type=str),
+ )
+ help = "Give the filenames of the csv files that has all the option code, name and exam code relation"
+
+ def handle(self, *args, **options):
+
+ clean_option()
+
+ load_option(options)
+
+ 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(options):
+ """Load option code and option name from the given csv file. The file should
+ declare a list of "exam_code,option_code,option,code".
+ """
+ paperCourseFileName=options.get('pcc')
+ courseCodeFileName=options.get('cc')
+ try:
+ paperCourseFile = open(paperCourseFileName, 'rb')
+ except IOError as (errno,strerror):
+ print "I/O error({0}): {1}".format(errno, strerror)
+
+ try:
+ courseCodeFile = open(courseCodeFileName, 'rb')
+ except IOError as (errno,strerror):
+ print "I/O error({0}): {1}".format(errno, strerror)
+
+ paperReader = reader(paperCourseFile, delimiter=",")
+ courseReader = reader(courseCodeFile, delimiter=",")
+
+ courseDict = {}
+
+ for data in courseReader:
+ courseDict[int(data[0])]=data[1]
+
+ for data in paperReader:
+ 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=courseDict[int(value)],opt_code=value)
+ new_option.save()
+ new_option.exam.add(exam)
+ print "Added (option {0} with code {1} and exam {2})".format(courseDict[int(value)],value,exam) \ No newline at end of file
diff --git a/allotter/management/commands/loadusers.py b/allotter/management/commands/loadusers.py
new file mode 100644
index 0000000..99fd075
--- /dev/null
+++ b/allotter/management/commands/loadusers.py
@@ -0,0 +1,65 @@
+from optparse import make_option
+from datetime import datetime
+from csv import DictReader
+from django.core.management.base import BaseCommand
+from allotter.models import Exam, Application, User, Profile
+
+class Command(BaseCommand):
+ option_list = BaseCommand.option_list + (
+ make_option('--usdf',metavar='User details file name', type=str),
+ )
+ help = "Give the filename of the csv files that has all the details of the users"
+
+ def handle(self, *args, **options):
+
+ clean_users()
+
+ load_users(options)
+
+ self.stdout.write('Done\n')
+
+
+def clean_users():
+ """Removes all the objects from the database, required as if not done there might be a case of multiple entries"""
+ User.objects.filter(is_superuser=False).delete()
+
+def load_users(options):
+ """Load option code and option name from the given csv file. The file should
+ declare a list of "exam_code,option_code,option,code".
+ """
+ userDetailsFileName=options.get('usdf')
+ try:
+ userDetailsFile = open(userDetailsFileName, 'rb')
+ except IOError as (errno,strerror):
+ print "I/O error({0}): {1}".format(errno, strerror)
+
+
+ userReader = DictReader(userDetailsFile, delimiter=":")
+
+
+ for data in userReader:
+ appno = data['AppNo.']
+ regno = data['Reg.No.']
+ new_user = User.objects.create_user(regno, password=appno, email="")
+ application = Application(user=new_user)
+ application.np = int(data['NP'])
+ if data['P1'].strip():
+ application.first_paper = Exam.objects.get(exam_code=data['P1'])
+ try:
+ application.second_paper = Exam.objects.get(exam_code=data['P2'])
+ except:
+ pass
+ else:
+ application.first_paper = Exam.objects.get(exam_code=data['P2'])
+
+
+ application.nat = data['Nat']
+ application.gender = data['Gdr']
+ application.cent = data['Cent']
+ application.cgy = data['Cgy']
+ application.save()
+ dob = datetime.strptime(data['DOB'], "%d/%m/%y")
+ new_profile = Profile(user=new_user, application=application)
+ new_profile.dob = dob
+ new_profile.save()
+ print "Added user with {0} and {1} with dob as {2}".format(appno,regno,dob) \ No newline at end of file
diff --git a/allotter/models.py b/allotter/models.py
index fc0353c..0004505 100644
--- a/allotter/models.py
+++ b/allotter/models.py
@@ -103,7 +103,7 @@ class Application(models.Model):
def __unicode__(self):
u = self.user
- return u'Application for {0} {1}'.format(u.first_name, u.last_name)
+ return u'Application for {0}'.format(u.username)
class Profile(models.Model):
@@ -118,7 +118,7 @@ class Profile(models.Model):
def __unicode__(self):
u = self.user
- return u'User Profile {0} {1}'.format(u.first_name, u.last_name)
+ return u'User Profile {0}'.format(u.username)