Skip to content

Commit

Permalink
Sync cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tsileo committed Jun 4, 2013
1 parent f12c282 commit 5df9e37
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.pyc
*wip.py
build/
dist/
bakthat.egg-info/
Expand Down
38 changes: 4 additions & 34 deletions bakthat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import json
import sqlite3
import os
import requests
import logging

log = logging.getLogger(__name__)

database = peewee.SqliteDatabase(DATABASE)

Expand All @@ -30,40 +34,6 @@ class SyncedModel(peewee.Model):
class Meta:
database = database

@classmethod
def create(cls, **attributes):
if cls._meta.name != "history":
History.create(data=json.dumps(dict(**attributes)),
ts=int(datetime.utcnow().strftime("%s")),
action="create",
model=cls._meta.name,
pk=attributes.get(cls.Sync.pk))
return super(SyncedModel, cls).create(**attributes)

def delete_instance(self):
if self._meta.name != "history":
History.create(data={},
ts=int(datetime.utcnow().strftime("%s")),
action="delete",
model=self._meta.name,
pk=self._data.get(self.Sync.pk))
return super(SyncedModel, self).delete_instance(self)

@classmethod
def sync(cls):
# Gere les 2 dates de derniere sync
# 1. PUSH
for history in History.select().where(History.model == cls._meta.name,
History.ts > 0):
if history.action == "create":
print "create", history.pk
elif history.action == "delete":
print "delete", history.pk
#add clientHistoryItem to server History table
# 2. PULL
# Faire l'appel a eve
return


class History(BaseModel):
"""History for sync."""
Expand Down

0 comments on commit 5df9e37

Please sign in to comment.