Skip to content

Commit

Permalink
custom user-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
dethi committed Jun 17, 2015
1 parent 2c1a8a5 commit ed6bee6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 114 deletions.
15 changes: 7 additions & 8 deletions AlgoliaSearch/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, model, client):
for field in self.fields:
if not (hasattr(model, field) or (field in all_fields)):
raise AlgoliaIndexError(
'{} is not a attributes of {}.'.format(field, model))
'{} is not an attribute of {}.'.format(field, model))

# If no fields are specified, index all the fields of the model
if not self.fields:
Expand All @@ -62,22 +62,21 @@ def __init__(self, model, client):
attr = getattr(model, self.geo_field)
if not (isinstance(attr, tuple) or callable(attr)):
raise AlgoliaIndexError(
'`geo_field` should be a tuple or a callable that returns a tuple.')
'`geo_field` should be a tuple or a callable that returns a tuple.')
else:
raise AlgoliaIndexError(
'{} is not an attributes of {}.'.format(self.geo_field, model))
raise AlgoliaIndexError('{} is not an attribute of {}.'.format(
self.geo_field, model))

# Check custom_objectID
if self.custom_objectID:
if hasattr(model, self.custom_objectID):
attr = getattr(model, elf.custom_objectID)
if not isinstance(attr, str):
raise AlgoliaIndexError(
'`custom_objectID` should be a string.')
'`custom_objectID` should be a string.')
else:
raise AlgoliaIndex(
'`{}` is not an attribute of {}.'.format(self.custom_objectID, model))

raise AlgoliaIndex('`{}` is not an attribute of {}.'.format(
self.custom_objectID, model))

def __set_index(self, client):
'''Get an instance of Algolia Index'''
Expand Down
2 changes: 2 additions & 0 deletions AlgoliaSearch/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.db.models.signals import post_save, pre_delete

from AlgoliaSearch.models import AlgoliaIndex
from AlgoliaSearch.version import VERSION

from algoliasearch import algoliasearch

Expand All @@ -24,6 +25,7 @@ def __init__(self,
'''Initializes Algolia engine.'''
self.__registered_models = {}
self.client = algoliasearch.Client(app_id, api_key)
self.client.set_extra_header('User-Agent', 'Algolia for Django {}'.format(VERSION))

def is_registered(self, model):
'''Checks whether the given models is registered with Algolia engine.'''
Expand Down
1 change: 1 addition & 0 deletions AlgoliaSearch/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION = '1.0.0'
22 changes: 18 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
#!/usr/bin/env python

import os
from setuptools import setup
import sys

try:
from setuptools import setup
except ImportError:
from distutils.core import setup

with open(os.path.join(os.path.dirname(__file__), 'README.md')) as readme:
README = readme.read()

# Allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))

with open(os.path.join(os.path.dirname(__file__), 'README.md')) as readme:
README = readme.read()

path_version = os.path.join(os.path.dirname(__file__), 'AlgoliaSearch/version.py')
if sys.version_info[0] == 3:
execfile(path_version)
else:
exec(open(path_version).read())


setup(
name = 'algoliasearch-django',
version = '1.0.0',
version = VERSION,
license = 'MIT License',
packages = ['AlgoliaSearch'],
install_requires = ['django', 'algoliasearch'],
Expand Down
Empty file removed tests/__init__.py
Empty file.
102 changes: 0 additions & 102 deletions tests/settings.py

This file was deleted.

0 comments on commit ed6bee6

Please sign in to comment.