web/ldt/management/__init__.py
author ymh <ymh.work@gmail.com>
Sat, 12 Jun 2010 04:25:05 +0200
changeset 0 cc4a51750724
permissions -rw-r--r--
first commit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
from django.db.models import signals
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
from django.conf import settings
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
from django.contrib.auth.models import User, Group 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
from ldt.core.models import Owner
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
from ldt.user.models import ldt, IriGroup
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
from django.contrib.contenttypes.models import ContentType
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
# import logging
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
from django.core.exceptions import ObjectDoesNotExist
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
    
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
def post_save_ldt(instance, raw, created, **kwargs):
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
    signals.post_save.send(sender=User, instance=instance, raw=raw, created=created)     
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
    
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
signals.post_save.connect(post_save_ldt, ldt) 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
def post_save_irigroup(instance, raw, created, **kwargs):
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
    signals.post_save.send(sender=Group, instance=instance, raw=raw, created=created)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
    
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
signals.post_save.connect(post_save_irigroup, IriGroup) 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
def post_save_user(instance, raw, created, **kwargs):
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    if created:
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
        try:
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
            owner = Owner.objects.get(user=instance)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
        except ObjectDoesNotExist:
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
            owner=Owner(user=instance)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
            owner.save() 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
signals.post_save.connect(post_save_user, User) 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
def post_save_group(instance, raw, created, **kwargs):
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    if created:
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
        try:
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
            owner = Owner.objects.get(group=instance)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
        except ObjectDoesNotExist:
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
            owner=Owner(group=instance)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
            owner.save()
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
    
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
signals.post_save.connect(post_save_group, Group) 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
def test_cms():
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
    if 'cms' in settings.INSTALLED_APPS:
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
        return True
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
    else:
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
        return False
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
        
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
def test_ldt():
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
    if 'ldt.ldt_utils' in settings.INSTALLED_APPS:
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
        return True
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
    else:
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
        return False
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
def get_content_type_list() :
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
    content_type_list = []
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
    if test_cms():
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
        content_type = ContentType.objects.get(app_label='cms', model='page')
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
        content_type_list.append(content_type)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
        content_type = ContentType.objects.get(app_label='snippet', model='snippet')
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
        content_type_list.append(content_type)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
    # if test_ldt():
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
        # content_type = ContentType.objects.get(app_label='ldt', model='content')
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
        # content_type_list.append(content_type)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
    return content_type_list
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66