Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
move debug logging from PUT view to model.
Browse files Browse the repository at this point in the history
  • Loading branch information
jedie committed Jul 19, 2013
1 parent da78655 commit d1b6131
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
21 changes: 18 additions & 3 deletions weave/models.py
Expand Up @@ -7,7 +7,7 @@
Created on 15.03.2010
@license: GNU GPL v3 or above, see LICENSE for more details.
@copyright: 2010 see AUTHORS for more details.
@copyright: 2010-2013 see AUTHORS for more details.
@author: Jens Diemer
@author: FladischerMichael
'''
Expand All @@ -20,6 +20,9 @@
from django.contrib.sites.managers import CurrentSiteManager

from weave.utils import weave_timestamp
from weave import Logging

logger = Logging.get_logger()


class BaseModel(models.Model):
Expand All @@ -31,17 +34,24 @@ class Meta:

class CollectionManager(CurrentSiteManager):
def create_or_update(self, user, col_name, timestamp, since=None):
logger.debug("Created or update collection %s for user %s" % (col_name, user.username))

collection, created = super(CollectionManager, self).get_or_create(
user=user, name=col_name,
)

# See if we have a constraint on the last modified date
# See if we have a constraint on the last modified date
if since is not None:
if since < collection.modified:
raise ValidationError

collection.modified = timestamp
collection.save()

if created:
logger.debug("New collection %s created." % collection)
else:
logger.debug("Existing collection %s updated." % collection)
return collection, created


Expand Down Expand Up @@ -73,6 +83,8 @@ def create_or_update(self, payload_dict, collection, user, timestamp):
- Check parentid, but how?
- must wboid + parentid be unique?
"""
logger.debug("Created or update WBO for collection %s" % collection)

payload = payload_dict['payload']
payload_size = len(payload)

Expand All @@ -90,7 +102,9 @@ def create_or_update(self, payload_dict, collection, user, timestamp):
'payload': payload,
}
)
if not created:
if created:
logger.debug("New wbo created: %r" % wbo)
else:
wbo.parentid = payload_dict.get("parentid", None)
wbo.predecessorid = payload_dict.get("predecessorid", None)
wbo.sortindex = payload_dict.get("sortindex", None)
Expand All @@ -99,6 +113,7 @@ def create_or_update(self, payload_dict, collection, user, timestamp):
wbo.payload_size = payload_size
wbo.payload = payload
wbo.save()
logger.debug("Existing wbo updated: %r" % wbo)

return wbo, created

Expand Down
12 changes: 1 addition & 11 deletions weave/views/sync.py
Expand Up @@ -6,7 +6,7 @@
Created on 15.03.2010
@license: GNU GPL v3 or above, see LICENSE for more details.
@copyleft: 2010-2011 by the django-sync-server team, see AUTHORS for more details.
@copyleft: 2010-2013 by the django-sync-server team, see AUTHORS for more details.
'''

from datetime import datetime
Expand Down Expand Up @@ -103,18 +103,8 @@ def storage(request, version, username, timestamp, col_name=None, wboid=None):
since,
)

if created:
logger.debug("Created new collection %s" % collection)
else:
logger.debug("Found existing collection %s" % collection)

wbo, created = Wbo.objects.create_or_update(val, collection, request.user, timestamp)

if created:
logger.debug("New wbo created: %r" % wbo)
else:
logger.debug("Existing wbo updated: %r" % wbo)

return weave_timestamp(timestamp)

elif request.method == 'POST':
Expand Down

0 comments on commit d1b6131

Please sign in to comment.