Skip to content

Commit

Permalink
Reorganise the project
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-tresontani committed May 4, 2012
1 parent c289008 commit f8f61c8
Show file tree
Hide file tree
Showing 20 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,2 +1,2 @@
*.pyc
rules/.idea/*
*/.idea/*
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions rules_engine/overview.rst
@@ -0,0 +1,5 @@
Automatic group creation
========================

Any object is automatically assigned a group by default containing the all objects of the same model.
For ex, any Product instead will belong to the group group_product_model.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions rules/core/models.py → rules_engine/rules_handler/models.py
@@ -1,3 +1,5 @@
import logging

from django.contrib.auth.models import Permission
from django.db import models
from django.db.models.query import QuerySet
Expand All @@ -6,6 +8,8 @@

from peak.rules import abstract, when

logger = logging.getLogger("rules")

# Create your models here.
class Group(object):
groups = set([])
Expand Down Expand Up @@ -52,11 +56,13 @@ def belong(cls_, obj):

@receiver(class_prepared)
def create_group_model(sender, **kwargs):
logging.debug("Receive prepared signal for %s", sender)
if isinstance(sender, type):
class_name = get_model_group_name(sender.__name__)
if not Group.get_by_name(class_name):
group = create_group_class(sender)
Group.register(group)
logger.info("Creating and registering automatic group %s" , class_name)


@abstract
Expand Down
@@ -1,7 +1,7 @@
import logging

from django.db.models.query_utils import Q
from core.models import ACL, Group, Rule
from rules_handler.models import ACL, Group, Rule


logger = logging.getLogger("rules")
Expand Down
4 changes: 2 additions & 2 deletions rules/core/tests.py → rules_engine/rules_handler/tests.py
Expand Up @@ -3,14 +3,14 @@
from hamcrest import *
from django_dynamic_fixture import get

from core.rules import ApplyRules, IsRuleMatching
from rules_handler.rules import ApplyRules, IsRuleMatching

from sample.models import *
from sample.rules import *
from sample.groups import *

from django.contrib.auth.models import User
from core.models import Group, ACL
from rules_handler.models import Group, ACL

class TestRules(TestCase):

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion rules/sample/groups.py → rules_engine/sample/groups.py
@@ -1,5 +1,5 @@
# Create your models here.
from core.models import Group
from rules_handler.models import Group

class CustomerGroup(Group):
name = "customergroup"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion rules/sample/rules.py → rules_engine/sample/rules.py
@@ -1,6 +1,6 @@
from django.contrib.auth.models import User
from django.db.models.query_utils import Q
from core.models import Rule, Group
from rules_handler.models import Rule, Group
from sample.groups import CustomerGroup
from sample.models import Product

Expand Down
File renamed without changes.
10 changes: 8 additions & 2 deletions rules/settings.py → rules_engine/settings.py
Expand Up @@ -118,7 +118,7 @@
'django.contrib.staticfiles',
'django_nose',

'core',
'rules_handler',

'sample',
# Uncomment the next line to enable the admin:
Expand All @@ -135,6 +135,11 @@
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters':{
'simple': {
'format': '%(levelname)s %(funcName)s | %(message)s'
},
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
Expand All @@ -143,6 +148,7 @@
'console': {
'level':'DEBUG',
'class':'logging.StreamHandler',
'formatter': 'simple',
'strm' if int(sys.version[2:3]) < 7 else 'stream': sys.stdout ,
}
},
Expand All @@ -159,7 +165,7 @@
},
'rules': {
'handlers': ['console'],
'level':'DEBUG',
'level':'INFO',
'propagate': False,
},
}
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions setup.py
@@ -1,11 +1,10 @@
from distutils.core import setup

requires = ['PEAK-Rules==0.5a1.dev-r2707']

setup(name='django-rules',
version='0.1',
description='Dynamic rule handling',
author='Anthony Tresontani',
author_email='dev.tresontani@gmail.com',
packages=['rules'],
packages=['rules_engine'],
install_requires = ['PEAK-Rules==0.5a1.dev-r2707']
)

0 comments on commit f8f61c8

Please sign in to comment.