예제 #1
0
    def update(self, revision, data, user=None):
        """Using revision and data update all data pretaining to self
        :param str or None revision: The revision that data points to
        :param dict data: Metadata recieved from waterbutler
        :returns: FileVersion
        """
        self.name = data['name']
        self.materialized_path = data['materialized']

        version = FileVersion(identifier=revision)
        version.update_metadata(data, save=False)

        # Transform here so it can be sortted on later
        if data['modified'] is not None and data['modified'] != '':
            data['modified'] = parse_date(
                data['modified'],
                ignoretz=True,
                default=timezone.now()  # Just incase nothing can be parsed
            )

        # if revision is none then version is the latest version
        # Dont save the latest information
        if revision is not None:
            version.save()
            self.versions.add(version)
        for entry in self.history:
            if ('etag' in entry and 'etag' in data) and (entry['etag'] == data['etag']):
                break
        else:
            # Insert into history if there is no matching etag
            if data.get('modified'):
                utils.insort(self.history, data, lambda x: x['modified'])
            # If modified not included in the metadata, insert at the end of the history
            else:
                self.history.append(data)

        # Finally update last touched
        self.last_touched = timezone.now()

        self.save()
        return version
예제 #2
0
파일: files.py 프로젝트: adlius/osf.io
    def update(self, revision, data, user=None):
        """Using revision and data update all data pretaining to self
        :param str or None revision: The revision that data points to
        :param dict data: Metadata recieved from waterbutler
        :returns: FileVersion
        """
        self.name = data['name']
        self.materialized_path = data['materialized']

        version = FileVersion(identifier=revision)
        version.update_metadata(data, save=False)

        # Transform here so it can be sortted on later
        if data['modified'] is not None and data['modified'] != '':
            data['modified'] = parse_date(
                data['modified'],
                ignoretz=True,
                default=timezone.now()  # Just incase nothing can be parsed
            )

        # if revision is none then version is the latest version
        # Dont save the latest information
        if revision is not None:
            version.save()
            self.versions.add(version)
        for entry in self.history:
            if ('etag' in entry and 'etag' in data) and (entry['etag'] == data['etag']):
                break
        else:
            # Insert into history if there is no matching etag
            if data.get('modified'):
                utils.insort(self.history, data, lambda x: x['modified'])
            # If modified not included in the metadata, insert at the end of the history
            else:
                self.history.append(data)

        # Finally update last touched
        self.last_touched = timezone.now()

        self.save()
        return version
예제 #3
0
    def update(self, revision, data, user=None):
        """Using revision and data update all data pretaining to self
        :param str or None revision: The revision that data points to
        :param dict data: Metadata recieved from waterbutler
        :returns: FileVersion
        """
        self.name = data['name']
        self.materialized_path = data['materialized']

        version = FileVersion(identifier=revision)
        version.update_metadata(data, save=False)

        # Transform here so it can be sortted on later
        data['modified'] = parse_date(
            data['modified'] or '',  # None breaks things to pass a string
            ignoretz=True,
            default=datetime.datetime.utcnow(
            )  # Just incase nothing can be parsed
        )

        # if revision is none then version is the latest version
        # Dont save the latest information
        if revision is not None:
            version.save()
            self.versions.append(version)

        for entry in self.history:
            if entry['etag'] == data['etag']:
                break
        else:
            # Insert into history if there is no matching etag
            utils.insort(self.history, data, lambda x: x['modified'])

        # Finally update last touched
        self.last_touched = datetime.datetime.utcnow()

        self.save()
        return version
예제 #4
0
파일: base.py 프로젝트: Alpani/osf.io
    def update(self, revision, data, user=None):
        """Using revision and data update all data pretaining to self
        :param str or None revision: The revision that data points to
        :param dict data: Metadata recieved from waterbutler
        :returns: FileVersion
        """
        self.name = data['name']
        self.materialized_path = data['materialized']

        version = FileVersion(identifier=revision)
        version.update_metadata(data, save=False)

        # Transform here so it can be sortted on later
        data['modified'] = parse_date(
            data['modified'] or '',  # None breaks things to pass a string
            ignoretz=True,
            default=datetime.datetime.utcnow()  # Just incase nothing can be parsed
        )

        # if revision is none then version is the latest version
        # Dont save the latest information
        if revision is not None:
            version.save()
            self.versions.append(version)

        for entry in self.history:
            if entry['etag'] == data['etag']:
                break
        else:
            # Insert into history if there is no matching etag
            utils.insort(self.history, data, lambda x: x['modified'])

        # Finally update last touched
        self.last_touched = datetime.datetime.utcnow()

        self.save()
        return version