示例#1
0
def _descriptor_set(self: peewee.FieldDescriptor, instance: Model, value: Any) -> None:
    """Monkeypatch the __set__ method on peewee descriptors to always save immediately.

    This is useful for us because in interactive use, it is easy to forget to call .save(), and
    we are not concerned about the performance implications of saving often.

    """
    instance._data[self.att_name] = value
    instance._dirty.add(self.att_name)
    # Otherwise this gets called in the constructor.
    if getattr(instance, "_is_prepared", False):
        instance.save()
示例#2
0
 def save(self, return_instance=True, **kwargs):
     with database_proxy.transaction():        
         rows = BaseModel.save(self, **kwargs)                  
         if return_instance:
             pk = self._get_pk_value()
             return self.get(id=pk)
         return rows
示例#3
0
 def save(self, return_instance=True, **kwargs):
     with database_proxy.transaction():
         rows = BaseModel.save(self, **kwargs)
         if return_instance:
             pk = self._get_pk_value()
             return self.get(id=pk)
         return rows
示例#4
0
    def save(self, **kwargs):
        with vulner_db_proxy.transaction():
            self.cvss_rank = floor(float(self.cvss_score))
            if isinstance(self.published, datetime):
                self.published = dt2str(self.published)
            if isinstance(self.modified, datetime):
                self.modified = dt2str(self, modified)
            if isinstance(self.last_seen, datetime):
                self.last_seen = dt2str(self.last_seen)
            if isinstance(self.created, datetime):
                self.created = dt2str(self.created)
            if isinstance(self.cvss_time, datetime):
                self.cvss_time = dt2str(self.cvss_time)
            self.cwe_id_list = [onlydigits(cwe) for cwe in self.cwe_list]
            self.componentversions_string = ";".join(self.componentversions)

            # TODO: Check if self.id defined after Model.save or before Model.save

            if self.vulner_id == default_vulner_id_undefined:
                self.vulner_id = default_vulner_id_start + self.component + default_vulner_id_delimeter + self.id

            Model.save(self, **kwargs)
示例#5
0
 def save(self, **kwds):
     with db.transaction() as txn:
         Model.save(self, **kwds)
示例#6
0
 def save(self, obj: Model, save: bool = True) -> Model:
     self.populate_obj(obj)
     if save:
         obj.save()
     return obj