From c9a65fb63ff4ebe672253e93cad6ddd98bdf814d Mon Sep 17 00:00:00 2001 From: Macartur Sousa Date: Sun, 1 Nov 2015 12:37:35 -0200 Subject: [PATCH] Adding timestamp feature to plugins --- colab/plugins/models.py | 13 ++++++++++++- docs/source/plugindev.rst | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/colab/plugins/models.py b/colab/plugins/models.py index ffe61fa..5ec030e 100644 --- a/colab/plugins/models.py +++ b/colab/plugins/models.py @@ -3,8 +3,19 @@ from datetime import datetime class TimeStampPlugin(models.Model): ''' - Class used to store timestamp from plugins + Class used to store timestamps from plugins ''' id = models.IntegerField(primary_key= True) name = models.CharField(max_length=255,unique=True,null=False) timestamp = models.DateTimeField(default=datetime.min,blank=True) + + @classmethod + def update_timestamp(cls, class_name): + instance = TimeStampPlugin.objects.filter(name=class_name)[0] + instance.timestamp = datetime.now() + instance.save() + + @classmethod + def get_last_updated(cls, class_name): + instance = TimeStampPlugin.objects.get_or_create(name=class_name)[0] + return instance.timestamp diff --git a/docs/source/plugindev.rst b/docs/source/plugindev.rst index 4d4ba62..ae6bb27 100644 --- a/docs/source/plugindev.rst +++ b/docs/source/plugindev.rst @@ -79,3 +79,27 @@ signals structure, some steps are required: .. code-block:: shell celery -A colab worker --loglevel=debug + +Storing TimeStamp +--------------- +TimeStamp is a parameter to control the last time a model was updated, you should use it +when you want the data updated after a given time. To do that the colab's model (colab.plugins.models) have a +TimeStampPlugin class, used to store all last updates from timestamp from all plugins. + +Class Methods: + update_timestamp(cls,class_name): allow store a current datetime. + + get_last_updated_timestamp(cls,class_name): allow get a datetime with last timestamp stored from class_name. + +Example Usage: + +.. code-block:: python + from colab.plugins.models import TimeStapPlugin + + class TestPlugin(): + + def update_timestamp(self): + TimeStapPlugin.update_timestamp('TestPlugin') + + def get_last_updated_timestamp(self): + return TimeStapPlugin.get_last_updated_timestamp('TestPlugin') -- libgit2 0.21.2