Exemple #1
0
def slugify_callback(sender, instance, *args, **kwargs):
	"""
		creates a slugified title that can be used as URL to the Document
		This will be used to identify a document that a user wants to see.
		In case someone creates a document with the same title it is not not defined
		which document might show up. So please try to avoid that ;)
	"""
	if sender not in Document.__subclasses__():
		return

	instance.url_title = slugify(instance.title)
Exemple #2
0
def permission_callback(sender, instance, created, *args, **kwargs):
	"""
		callback that assigns default permissions to the saved object
	"""

	if sender not in Document.__subclasses__() or not created:
		return

	permissions = get_perms_for_model(instance)
	groups = Group.objects.all()
	for group in groups:
		for permission in group.permissions.all():
			if permission in permissions:
				assign_perm(permission.codename, group, instance)
Exemple #3
0
def permission_callback(sender, instance, created, *args, **kwargs):
    """
		callback that assigns default permissions to the saved object
	"""

    if sender not in Document.__subclasses__() or not created:
        return

    permissions = get_perms_for_model(instance)
    groups = Group.objects.all()
    for group in groups:
        for permission in group.permissions.all():
            if permission in permissions:
                assign_perm(permission.codename, group, instance)
Exemple #4
0
def pre_save_document(sender, instance, *args, **kwargs):
    """
		creates a slugified title that can be used as URL to the Document
		This will be used to identify a document that a user wants to see.
		In case someone creates a document with the same title it is not not defined
		which document might show up. So please try to avoid that ;)
	"""
    if sender not in Document.__subclasses__():
        return

    # get the max_length of a slug field as we need to make sure it is no longer than that
    # as slugify is not doing that for us
    for field in Document._meta.fields:
        if field.verbose_name == 'url_title' and instance.url_title == "":
            instance.url_title = slugify(instance.title)[:field.max_length]
            return
Exemple #5
0
def pre_save_document(sender, instance, *args, **kwargs):
	"""
		creates a slugified title that can be used as URL to the Document
		This will be used to identify a document that a user wants to see.
		In case someone creates a document with the same title it is not not defined
		which document might show up. So please try to avoid that ;)
	"""
	if sender not in Document.__subclasses__():
		return

	# get the max_length of a slug field as we need to make sure it is no longer than that
	# as slugify is not doing that for us
	for field in Document._meta.fields:
		if isinstance(field, SlugField) and instance.url_title == "":
			instance.url_title = slugify(instance.title)[:field.max_length]
			return