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

« back to all changes in this revision

Viewing changes to ivle/database.py

  • Committer: William Grant
  • Date: 2010-02-25 06:43:12 UTC
  • mto: This revision was merged to the branch mainline in revision 1722.
  • Revision ID: grantw@unimelb.edu.au-20100225064312-a8fcg7y4chrc32ml
Cache exercise and worksheet rST->XHTML conversions in the DB.

Show diffs side-by-side

added added

removed removed

Lines of Context:
889
889
    id = Unicode(primary=True, name="identifier")
890
890
    name = Unicode()
891
891
    description = Unicode()
 
892
    _description_xhtml_cache = Unicode(name='description_xhtml_cache')
892
893
    partial = Unicode()
893
894
    solution = Unicode()
894
895
    include = Unicode()
937
938
 
938
939
        return perms
939
940
 
 
941
    def _cache_description_xhtml(self, invalidate=False):
 
942
        # Don't regenerate an existing cache unless forced.
 
943
        if self._description_xhtml_cache is not None and not invalidate:
 
944
            return
 
945
 
 
946
        if self.description:
 
947
            self._description_xhtml_cache = rst(self.description)
 
948
        else:
 
949
            self._description_xhtml_cache = None
 
950
 
940
951
    @property
941
952
    def description_xhtml(self):
942
953
        """The XHTML exercise description, converted from reStructuredText."""
943
 
        if self.description:
944
 
            return rst(self.description)
945
 
        else:
946
 
            return None
 
954
        self._cache_description_xhtml()
 
955
        return self._description_xhtml_cache
947
956
 
948
957
    def set_description(self, description):
949
958
        self.description = description
 
959
        self._cache_description_xhtml(invalidate=True)
950
960
 
951
961
    def delete(self):
952
962
        """Deletes the exercise, providing it has no associated worksheets."""
971
981
    assessable = Bool()
972
982
    published = Bool()
973
983
    data = Unicode()
 
984
    _data_xhtml_cache = Unicode(name='data_xhtml_cache')
974
985
    seq_no = Int()
975
986
    format = Unicode()
976
987
 
1023
1034
 
1024
1035
        return perms
1025
1036
 
 
1037
    def _cache_data_xhtml(self, invalidate=False):
 
1038
        # Don't regenerate an existing cache unless forced.
 
1039
        if self._data_xhtml_cache is not None and not invalidate:
 
1040
            return
 
1041
 
 
1042
        if self.format == u'rst':
 
1043
            self._data_xhtml_cache = rst(self.data)
 
1044
        else:
 
1045
            self._data_xhtml_cache = None
 
1046
 
1026
1047
    @property
1027
1048
    def data_xhtml(self):
1028
1049
        """The XHTML of this worksheet, converted from rST if required."""
 
1050
        # Update the rST -> XHTML cache, if required.
 
1051
        self._cache_data_xhtml()
 
1052
 
1029
1053
        if self.format == u'rst':
1030
 
            ws_xml = rst(self.data)
1031
 
            return ws_xml
 
1054
            return self._data_xhtml_cache
1032
1055
        else:
1033
1056
            return self.data
1034
1057
 
1035
1058
    def set_data(self, data):
1036
1059
        self.data = data
 
1060
        self._cache_data_xhtml(invalidate=True)
1037
1061
 
1038
1062
    def delete(self):
1039
1063
        """Deletes the worksheet, provided it has no attempts on any exercises.