OpenSlides/openslides/utils/utils.py

28 lines
917 B
Python
Raw Normal View History

2014-04-27 21:01:23 +02:00
import roman
2012-07-10 13:19:12 +02:00
from django.contrib.auth.models import Permission
2011-07-31 10:46:29 +02:00
2012-04-14 14:31:09 +02:00
def delete_default_permissions(**kwargs):
2012-07-10 13:19:12 +02:00
"""
Deletes the permissions, django creates by default for the admin.
"""
# TODO: Find a way not to create the permissions in the first place.
# Meta.default_permissions does not work, because django will
# nevertheless create permissions for its own models like "group"
2011-07-31 10:46:29 +02:00
for p in Permission.objects.all():
if (p.codename.startswith('add') or
p.codename.startswith('delete') or
p.codename.startswith('change')):
2011-07-31 10:46:29 +02:00
p.delete()
2011-09-02 20:46:24 +02:00
2012-02-09 02:29:38 +01:00
def to_roman(number):
2014-04-27 21:01:23 +02:00
"""
Converts an arabic number within range from 1 to 4999 to the corresponding roman number.
Returns None on error conditions.
"""
try:
return roman.toRoman(number)
except (roman.NotIntegerError, roman.OutOfRangeError):
return None