コード例 #1
0
    def lock_record(self):
        """Lock a record.  If the lock is unable to be obtained, a
        RecordLockedError exception is raised with the username of the lock
        holder passed."""

        if (self.originalKeywordGroup == None) or \
           (self.originalKeyword == None):           # no record loaded?
            return

        tablename = self._table()

        db = DBInterface.get_db()
        c = db.cursor()

        lq = self._get_db_fields(('RecordLock', 'LockTime'), c)
        if (lq[1] == None) or (lq[0] == "") or (
            (DBInterface.ServerDateTime() - lq[1]).days > 1):
            (EpisodeClipLockCount,
             LockName) = self.checkEpisodesClipsSnapshotsForLocks()
            if EpisodeClipLockCount == 0:
                # Lock the record
                self._set_db_fields(('RecordLock', 'LockTime'),
                                    (DBInterface.get_username(),
                                     str(DBInterface.ServerDateTime())[:-3]),
                                    c)
                c.close()
            else:
                c.close()
                raise RecordLockedError, LockName
        else:
            # We just raise an exception here since GUI code isn't appropriate.
            c.close()
            raise RecordLockedError, lq[0]  # Pass name of person
コード例 #2
0
 def _db_start_save(self):
     """Return 0 if creating new record, 1 if updating an existing one."""
     tname = _(type(self).__name__)
     # You can save a Clip Transcript with a blank Transcript ID!
     if (self.id == "") and (tname != _('Transcript')):
         if 'unicode' in wx.PlatformInfo:
             # Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
             prompt = unicode(_("Cannot save a %s with a blank %s ID"),
                              'utf8')
         else:
             prompt = _("Cannot save a %s with a blank %s ID")
         raise SaveError, prompt % (tname.decode('utf8'),
                                    tname.decode('utf8'))
     else:
         # Verify record lock is still good
         if (self.number == 0) or \
             ((self.record_lock == DBInterface.get_username()) and
             ((self.lock_time == None) or
              ((DBInterface.ServerDateTime() - self.lock_time).days <= 1))):
             # If record num is 0, this is a NEW record and needs to be
             # INSERTed.  Otherwise, it is an existing record to be UPDATEd.
             if (self.number == 0):
                 return 0
             else:
                 return 1
         else:
             raise SaveError, _(
                 "Record lock no longer valid.\nYour changes cannot be saved."
             )
コード例 #3
0
 def _get_lt(self):
     # Get the Record Lock Time from the Database
     lt = self._get_db_fields(('LockTime', ))
     # If a Lock Time has been specified ...
     if (len(lt) > 0) and (lt[0] is not None):
         # ... If we're using sqlite, we get a string and need to convert it to a datetime object
         if TransanaConstants.DBInstalled in ['sqlite3']:
             import datetime
             # Start catching exceptions
             try:
                 # This conversion *almost* always works
                 tempDate = datetime.datetime.strptime(
                     lt[0], '%Y-%m-%d %H:%M:%S.%f')
             except ValueError:
                 # Every once in a while, we get an lt[0] value with no SECONDS, requiring this conversion.  I don't know why.
                 tempDate = datetime.datetime.strptime(
                     lt[0], '%Y-%m-%d %H:%M')
             return tempDate
         # ... If we're using MySQL, we get a MySQL DateTime value
         else:
             return lt[0]
     # If we don't get a Lock Time ...
     else:
         # ... return the current Server Time
         return DBInterface.ServerDateTime()
コード例 #4
0
    def lock_record(self):
        """Lock a record.  If the lock is unable to be obtained, a
        RecordLockedError exception is raised with the username of the lock
        holder passed."""

        if self.number == 0:  # no record or new record not yet in database loaded
            return

        tablename = self._table()
        numname = self._num()

        db = DBInterface.get_db()
        c = db.cursor()
        lq = self._get_db_fields(('RecordLock', 'LockTime'), c)

        if (lq[1] == None) or (lq[0] == "") or (
            (DBInterface.ServerDateTime() - lq[1]).days > 1):
            # Lock the record
            self._set_db_fields(('RecordLock', 'LockTime'),
                                (DBInterface.get_username(),
                                 str(DBInterface.ServerDateTime())[:-3]), c)
            c.close()
            # Indicate that the object was successfully locked
            self._isLocked = True

            if DEBUG:
                print "DataObject.lock_record(): Record '%s' locked by '%s'" % (
                    self.number, DBInterface.get_username())
        else:
            # We just raise an exception here since GUI code isn't appropriate.
            c.close()

            if DEBUG:
                print "DataObject.lock_record(): Record %s locked by %s raises exception" % (
                    self.id, lq[0])

            raise RecordLockedError, lq[0]  # Pass name of person
コード例 #5
0
 def _get_lt(self):
     # Get the Record Lock Time from the Database
     lt = self._get_db_fields(('LockTime', ))
     # If a Lock Time has been specified ...
     if len(lt) > 0:
         # ... If we're using sqlite, we get a string and need to convert it to a datetime object
         if TransanaConstants.DBInstalled in ['sqlite3']:
             import datetime
             tempDate = datetime.datetime.strptime(lt[0],
                                                   '%Y-%m-%d %H:%M:%S.%f')
             return tempDate
         # ... If we're using MySQL, we get a MySQL DateTime value
         else:
             return lt[0]
     # If we don't get a Lock Time ...
     else:
         # ... return the current Server Time
         return DBInterface.ServerDateTime()
コード例 #6
0
    def _db_start_save(self):
        """Return 0 if creating new record, 1 if updating an existing one."""
        tname = type(self).__name__
        if (self.keywordGroup == ""):
            if 'unicode' in wx.PlatformInfo:
                # Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
                prompt = unicode(
                    _("Cannot save a %s with a blank Keyword Group."),
                    'utf8') % tname
            else:
                prompt = _(
                    "Cannot save a %s with a blank Keyword Group.") % tname
            raise SaveError, prompt
        elif (self.keyword == ""):
            if 'unicode' in wx.PlatformInfo:
                # Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
                prompt = unicode(_("Cannot save a %s with a blank Keyword."),
                                 'utf8') % tname
            else:
                prompt = _("Cannot save a %s with a blank Keyword.") % tname
            raise SaveError, prompt
        else:
            # Verify record lock is still good
            db = DBInterface.get_db()

            if ((self.originalKeywordGroup == None) and \
                (self.originalKeyword == None)) or \
               ((self.record_lock == DBInterface.get_username()) and
               ((DBInterface.ServerDateTime() - self.lock_time).days <= 1)):
                c = db.cursor()
                # If record num is 0, this is a NEW record and needs to be
                # INSERTed.  Otherwise, it is an existing record to be UPDATEd.
                if (self.originalKeywordGroup == None) or \
                   (self.originalKeyword == None):           # no record loaded?
                    return 0
                else:
                    return 1
            else:
                raise SaveError, _("Record lock no longer valid.")