def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError('Please specify either centers or subconstituencies.')

        entity = args[0].lower()
        valid_entities = ('centers', 'subconstituencies')
        if entity not in valid_entities:
            raise CommandError('Entity must be either centers or subconstituencies.')

        if entity == 'centers':
            centers = RegistrationCenter.objects.all()

            longest_name = find_longest_string_in_list([reshape(center.name) for center in centers])
        else:
            subconstituencies = SubConstituency.objects.all()

            longest_name = find_longest_string_in_list([reshape(subconstituency.name_arabic) for
                                                       subconstituency in subconstituencies])

        if options['filename']:
            open(options['filename'], 'wb').write(longest_name.encode('utf-8'))
        else:
            self.stdout.write(longest_name)
Exemple #2
0
def load_strings():
    strings_path = os.path.join(settings.PROJECT_ROOT, 'rollgen', 'arabic_strings', 'ar.yml')
    locale_file = codecs.open(strings_path, 'r', encoding='utf-8')
    locale_dict = yaml.load(locale_file)
    out_dict = {}
    for (key, string) in locale_dict.items():
        # reshape, to fix ligatures
        shaped = reshape(string)
        # Newlines have to be converted to <br/> for consumption by reportlab. First I have to
        # ensure that the newline characters are predictable in case they were changed as a result
        # of the file being edited on Windows.
        # The codecs module doc says, "...no automatic conversion of '\n' is done on reading and
        # writing."
        shaped = normalize_newlines(shaped)
        shaped = shaped.replace('\n', '<br/>')
        out_dict[key] = shaped
    return out_dict
Exemple #3
0
def load_strings():
    strings_path = os.path.join(settings.PROJECT_ROOT, 'rollgen',
                                'arabic_strings', 'ar.yml')
    locale_file = codecs.open(strings_path, 'r', encoding='utf-8')
    locale_dict = yaml.load(locale_file)
    out_dict = {}
    for (key, string) in locale_dict.items():
        # reshape, to fix ligatures
        shaped = reshape(string)
        # Newlines have to be converted to <br/> for consumption by reportlab. First I have to
        # ensure that the newline characters are predictable in case they were changed as a result
        # of the file being edited on Windows.
        # The codecs module doc says, "...no automatic conversion of '\n' is done on reading and
        # writing."
        shaped = normalize_newlines(shaped)
        shaped = shaped.replace('\n', '<br/>')
        out_dict[key] = shaped
    return out_dict