def create_update_project(sender, instance, **kwargs): """ if the project is being created: * creates and sets the unique project_id * creates and sets a unique title_slug elif the title has changed: * creates and sets a unique slug to title_slug """ if not instance.id: instance.project_id = unique_random_string(sender, 'project_id', 15) instance.title_slug = unique_slug( sender, 'title_slug', instance.title) elif sender.objects.get(id=instance.id).title != instance.title: instance.title_slug = unique_slug( sender, 'title_slug', instance.title)
def user_created(sender, instance, created, **kwargs): """ sets the pybbm user permissions and creates the profile Person only if the User has been just created """ if created: try: add_post_permission = Permission.objects.get_by_natural_key( 'add_post', 'pybb', 'post') add_topic_permission = Permission.objects.get_by_natural_key( 'add_topic', 'pybb', 'topic') except ObjectDoesNotExist: pass else: instance.user_permissions.add(add_post_permission, add_topic_permission) instance.save() from common.models import Person person_id = unique_random_string(Person, 'person_id', 16) Person(user=instance, person_id=person_id).save()