Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

made delete_remote, restore_remote methods for VKCRUDModel, updated t…

…ravis conf
  • Loading branch information...
commit 49a1311f87b9805dc80f03956bbcd76697c7c13e 1 parent 1b266fe
@ramusus authored
View
21 .travis.yml
@@ -2,12 +2,27 @@ language: python
python:
- "2.7"
env:
- - DJANGO=1.4
+ - DJANGO=1.4 DB=postgres
+ - DJANGO=1.5 DB=postgres
+ - DJANGO=1.6 DB=postgres
+before_script:
+ - mysql -e 'create database django;'
+ - psql -c 'create database django;' -U postgres
install:
- - pip install Django>=$DJANGO --use-mirrors
+ - if [[ $DB == mysql ]]; then pip install mysql-python --use-mirrors; fi
+ - if [[ $DB == postgres ]]; then pip install psycopg2 --use-mirrors; fi
+ - DJANGO_VER=$(./travis_django_version.py $DJANGO)
+ - pip install $DJANGO_VER --use-mirrors
+ - pip install simplejson --use-mirrors
+ - pip install factory_boy --use-mirrors
+ - pip install coveralls --use-mirrors
+ - pip install mock --use-mirrors
- pip install . --use-mirrors
script:
- - python quicktest.py vkontakte_api
+ - django-admin.py --version
+ - coverage run --source=vkontakte_api quicktest.py vkontakte_api
+after_success:
+ - coveralls
notifications:
email:
recipients:
View
2  README.md
@@ -1,7 +1,7 @@
Django Vkontakte API
====================
-[![PyPI version](https://badge.fury.io/py/django-vkontakte-api.png)](http://badge.fury.io/py/django-vkontakte-api) [![Build Status](https://travis-ci.org/ramusus/django-vkontakte-api.png?branch=master)](https://travis-ci.org/ramusus/django-vkontakte-api)
+[![PyPI version](https://badge.fury.io/py/django-vkontakte-api.png)](http://badge.fury.io/py/django-vkontakte-api) [![Build Status](https://travis-ci.org/ramusus/django-vkontakte-api.png?branch=master)](https://travis-ci.org/ramusus/django-vkontakte-api) [![Coverage Status](https://coveralls.io/repos/ramusus/django-vkontakte-api/badge.png?branch=master)](https://coveralls.io/r/ramusus/django-vkontakte-api)
Приложение позволяет взаимодействовать с объектами Вконтакте API используя стандартные модели Django
View
35 quicktest.py
@@ -65,17 +65,36 @@ def _new_tests(self):
"""
INSTALLED_APPS, settings_test = self.custom_settings()
+ test_db = os.environ.get('DB', 'sqlite')
+ if test_db == 'mysql':
+ database = {
+ 'ENGINE': 'django.db.backends.mysql',
+ 'NAME': 'django',
+ 'USER': 'root',
+ }
+ elif test_db == 'postgres':
+ database = {
+ 'ENGINE': 'django.db.backends.postgresql_psycopg2',
+ 'USER': 'postgres',
+ 'NAME': 'django',
+ 'OPTIONS': {
+ 'autocommit': True,
+ }
+ }
+ else:
+ database = {
+ 'ENGINE': 'django.db.backends.sqlite3',
+ 'NAME': os.path.join(self.DIRNAME, 'database.db'),
+ 'USER': '',
+ 'PASSWORD': '',
+ 'HOST': '',
+ 'PORT': '',
+ }
+
settings.configure(
DEBUG = True,
DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.sqlite3',
- 'NAME': os.path.join(self.DIRNAME, 'database.db'),
- 'USER': '',
- 'PASSWORD': '',
- 'HOST': '',
- 'PORT': '',
- }
+ 'default': database,
},
INSTALLED_APPS = self.INSTALLED_APPS + INSTALLED_APPS + self.apps,
**settings_test
View
2  vkontakte_api/__init__.py
@@ -1,2 +1,2 @@
-VERSION = (0, 4, 12)
+VERSION = (0, 4, 13)
__version__ = '.'.join(map(str, VERSION))
View
98 vkontakte_api/models.py
@@ -334,6 +334,27 @@ def __init__(self, *args, **kwargs):
self._commit_remote = kwargs.pop('commit_remote', self._commit_remote)
super(VkontakteCRUDModel, self).__init__(*args, **kwargs)
+ def delete(self, commit_remote=None, *args, **kwargs):
+ if not self.archived:
+ self.delete_remote(commit_remote)
+
+ def restore(self, commit_remote=None, *args, **kwargs):
+ if self.archived:
+ self.restore_remote(commit_remote)
+
+ def refresh(self, *args, **kwargs):
+ """
+ Refresh remote data for current model.
+
+ You need to refresh the child to identify and send the kwargs,
+ which will allow the parent to get the current object.
+ """
+ objects = type(self).remote.fetch(*args, **kwargs)
+ if len(objects) == 1:
+ self.__dict__.update(objects[0].__dict__)
+ else:
+ raise VkontakteContentError("Remote server returned more objects, than expected - %d instead of one. Object details: %s, request details: %s" % (len(objects), self.__dict__, kwargs))
+
def save(self, commit_remote=None, *args, **kwargs):
'''
Update remote version of object before saving if data is different
@@ -365,6 +386,42 @@ def update_remote(self, **kwargs):
log.info("Remote object %s with ID=%s was updated with fields '%s' successfully" \
% (self._meta.object_name, self.remote_id, params))
+ def delete_remote(self, commit_remote=None):
+ '''
+ Delete objects remotely and mark it archived localy
+ '''
+ commit_remote = commit_remote if commit_remote is not None else self._commit_remote
+ if commit_remote and self.remote_id:
+ params = self.prepare_delete_params()
+ success = type(self).remote.api_call(method='delete', **params)
+ model = self._meta.object_name
+ if not success:
+ message = "Error response '%s' while deleting remote %s with ID %s" % (success, model, self.remote_id)
+ log.error(message)
+ raise VkontakteContentError(message)
+ log.info("Remote object %s with ID %s was deleted successfully" % (model, self.remote_id))
+
+ self.archived = True
+ self.save(commit_remote=False)
+
+ def restore_remote(self, commit_remote=None):
+ '''
+ Restore objects remotely and unmark it archived localy
+ '''
+ commit_remote = commit_remote if commit_remote is not None else self._commit_remote
+ if commit_remote and self.remote_id:
+ params = self.prepare_restore_params()
+ success = type(self).remote.api_call(method='restore', **params)
+ model = self._meta.object_name
+ if not success:
+ message = "Error response '%s' while restoring remote %s with ID %s" % (success, model, self.remote_id)
+ log.error(message)
+ raise VkontakteContentError(message)
+ log.info("Remote object %s with ID %s was restored successfully" % (model, self.remote_id))
+
+ self.archived = False
+ self.save(commit_remote=False)
+
@property
def fields_changed(self):
old = type(self).objects.get(remote_id=self.remote_id)
@@ -432,47 +489,6 @@ def parse_remote_id_from_response(self, response):
"""
raise NotImplementedError
- def delete(self, commit_remote=None, *args, **kwargs):
- if not self.archived:
- self.archive(commit_remote)
-
- def restore(self, commit_remote=None, *args, **kwargs):
- if self.archived:
- self.archive(commit_remote, restore=True)
-
- def archive(self, commit_remote=None, restore=False):
- '''
- Archive or delete objects remotely and mark it archived localy
- '''
- commit_remote = commit_remote if commit_remote is not None else self._commit_remote
- if commit_remote and self.remote_id:
- method = 'delete' if not restore else 'restore'
- params = self.prepare_delete_params()
- success = type(self).remote.api_call(method=method, **params)
- model = self._meta.object_name
- if not success:
- message = "Error response '%s' while deleting remote %s with ID %s" % (success, model, self.remote_id)
- log.error(message)
- raise VkontakteContentError(message)
- log.info("Remote object %s with ID %s was deleted successfully" % (model, self.remote_id))
-
- self.archived = True if not restore else False
- self.save(commit_remote=False)
-
- def refresh(self, *args, **kwargs):
- """
- Refresh remote data for current model.
-
- You need to refresh the child to identify and send the kwargs,
- which will allow the parent to get the current object.
- """
- objects = type(self).remote.fetch(*args, **kwargs)
- if len(objects) == 1:
- self.__dict__.update(objects[0].__dict__)
- self.fetched = datetime.now()
- else:
- raise VkontakteContentError("Remote server returned more objects, than expected - %d instead of one. Object details: %s, request details: %s" % (len(objects), self.__dict__, kwargs))
-
def check_remote_existance(self, *args, **kwargs):
self.refresh(*args, **kwargs)
if self.archived:
Please sign in to comment.
Something went wrong with that request. Please try again.