~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to lib/common/db.py

  • Committer: dcoles
  • Date: 2008-07-02 04:11:34 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:799
Setup: Added 3rd party (wgrant) packages for NLTK and matplotlib without TeX 
dependency. Also fixed typos.

Show diffs side-by-side

added added

removed removed

Lines of Context:
810
810
            raise
811
811
        return mand_done, mand_total, opt_done, opt_total
812
812
 
813
 
    def add_enrolment(self, login, subj_code, semester, year=None, dry=False):
814
 
        """
815
 
        Enrol a student in the given offering of a subject.
816
 
        Returns True on success, False on failure (which usually means either
817
 
        the student is already enrolled in the subject, the student was not
818
 
        found, or no offering existed with the given details).
819
 
        The return value can usually be ignored.
820
 
        """
821
 
        subj_code = str(subj_code)
822
 
        semester = str(semester)
823
 
        if year is None:
824
 
            year = str(time.gmtime().tm_year)
825
 
        else:
826
 
            year = str(year)
827
 
        query = """\
828
 
INSERT INTO enrolment (loginid, offeringid)
829
 
    VALUES (
830
 
        (SELECT loginid FROM login WHERE login=%s),
831
 
        (SELECT offeringid
832
 
            FROM (offering INNER JOIN subject
833
 
                ON subject.subjectid = offering.subject)
834
 
            WHERE subj_code=%s AND semester=%s AND year=%s)
835
 
        );""" % (_escape(login), _escape(subj_code), _escape(semester),
836
 
                 _escape(year))
837
 
        if dry:
838
 
            return query
839
 
        try:
840
 
            result = self.db.query(query)
841
 
        except pg.ProgrammingError:
842
 
            return False
843
 
        return True
844
 
 
845
813
    def close(self):
846
814
        """Close the DB connection. Do not call any other functions after
847
815
        this. (The behaviour of doing so is undefined).