How to use update_last_modified method in localstack

Best Python code snippet using localstack_python

models.py

Source:models.py Github

copy

Full Screen

...21 initial_model = self.get_registered_model()22 self._schema_editor = ModelSchemaEditor(initial_model)23 def save(self, **kwargs):24 super().save(**kwargs)25 cache.update_last_modified(self.model_name)26 cache.update_last_modified(self.initial_model_name)27 self.last_modified = self._modified28 self._schema_editor.update_table(self._factory.make_model())29 def delete(self, **kwargs):30 self._schema_editor.drop_table(self.as_model())31 self._factory.destroy_model()32 cache.clear_last_modified(self.initial_model_name)33 super().delete(**kwargs)34 35 @property36 def last_modified(self):37 return self._cache.get(self)38 @last_modified.setter39 def last_modified(self, timestamp):40 self._cache.set(self, timestamp)41 @last_modified.deleter42 def last_modified(self):43 self._cache.delete(self)44 def get_registered_model(self):45 return self._registry.get_model(self.model_name)46 def is_current_schema(self):47 return self._modified >= self.last_modified48 def is_current_model(self, model):49 if model._schema.pk != self.pk:50 raise ValueError("Can only be called on a model of this schema")51 return model._declared >= self.last_modified52 @property53 def _factory(self):54 return ModelFactory(self)55 @property56 def app_label(self):57 return config.dynamic_models_app_label()58 @property59 def model_name(self):60 return self.get_model_name(self.name)61 @property62 def initial_model_name(self):63 return self.get_model_name(self._initial_name)64 @classmethod65 def get_model_name(cls, name):66 return name.title().replace(' ', '')67 @property68 def db_table(self):69 parts = (self.app_label, slugify(self.name).replace('-', '_'))70 return '_'.join(parts)71 def get_db_table(self):72 return self._factory._model_meta()73 def as_model(self):74 return self._factory.get_model()75class FieldSchema(models.Model):76 _PROHIBITED_NAMES = ('__module__', '_schema', '_declared')77 _MAX_LENGTH_DATA_TYPES = ('character',)78 name = models.CharField(max_length=63)79 model_schema = models.ForeignKey(80 ModelSchema,81 on_delete=models.CASCADE,82 related_name='fields'83 )84 data_type = models.CharField(85 max_length=16,86 choices=FieldFactory.data_type_choices(),87 editable=False88 )89 null = models.BooleanField(default=False)90 unique = models.BooleanField(default=False)91 max_length = models.PositiveIntegerField(null=True)92 93 input_type = models.CharField(max_length=65)94 description= models.TextField(max_length=1500)95 columns = models.JSONField()96 class Meta:97 unique_together = (98 ('name', 'model_schema'),99 )100 def __init__(self, *args, **kwargs):101 super().__init__(*args, **kwargs)102 self._initial_name = self.name103 self._initial_null = self.null104 self._initial_field = self.get_registered_model_field()105 self._schema_editor = FieldSchemaEditor(self._initial_field)106 107 def save(self, **kwargs):108 # self.validate()109 super().save(**kwargs)110 self.update_last_modified()111 model, field = self._get_model_with_field()112 try:113 self._schema_editor.update_column(model, field)114 except:115 print("Handle")116 def delete(self, **kwargs):117 model, field = self._get_model_with_field()118 self._schema_editor.drop_column(model, field)119 self.update_last_modified()120 super().delete(**kwargs)121 def validate(self):122 print("From the model.py",self.columns)123 if self._initial_null and not self.null:124 print("self._initial_null:-",self._initial_null, "and", self.null)125 raise NullFieldChangedError(f"Cannot change NULL field '{self.name}' to NOT NULL")126 if self.name in self.get_prohibited_names():127 raise InvalidFieldNameError(f'{self.name} is not a valid field name')128 def get_registered_model_field(self):129 latest_model = self.model_schema.get_registered_model()130 if latest_model and self.name:131 try:132 return latest_model._meta.get_field(self.name)133 except FieldDoesNotExist:134 pass135 @classmethod136 def get_prohibited_names(cls):137 # TODO: return prohbited names based on backend138 return cls._PROHIBITED_NAMES139 @classmethod140 def get_data_types(cls):141 return FieldFactory.get_data_types()142 @property143 def db_column(self):144 return slugify(self.name).replace('-', '_')145 def requires_max_length(self):146 147 return self.data_type in self.__class__._MAX_LENGTH_DATA_TYPES148 def update_last_modified(self):149 self.model_schema.last_modified = timezone.now()150 151 def get_options(self):152 """153 Get a dictionary of kwargs to be passed to the Django field constructor154 """155 options = {'null': self.null, 'unique': self.unique}156 if self.requires_max_length():157 options['max_length'] = self.max_length or config.default_charfield_max_length()158 159 # if self.data_type == 'date':160 # options['input_formats'] = settings.DATE_INPUT_FORMATS161 162 if self.data_type == 'file':...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

...11 last_modified: datetime.datetime12 services: dict13 etag: str14 def __init__(self):15 self.update_last_modified()16 self.services = {}17 def _set_etag(self):18 self.etag = base64.b64encode(19 self.last_modified.isoformat().encode('utf-8')20 ).decode('utf-8')21 def update_last_modified(self):22 self.last_modified = ddt.now()23 self._set_etag()24 def add_service(self, type_uri, value):25 if callable(value):26 self.services[type_uri] = value27 else:28 self.services[type_uri] = lambda request=None: reverse(29 f"{value}-list", request=request30 )31 self.update_last_modified()32 def get_last_modified(self):33 return self.last_modified34 def get_etag(self):35 return self.etag36services = ScrudServices()37def collection_type_uri_for(type_uri):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful