# Path: OGRgeoConverter/models.py
# class OgrFormat(models.Model):
#     name = models.CharField(
#         max_length=100, unique=True,
#         help_text='Name des Formats, wie er auf der Webseite angezeigt werden soll.')
#     ogr_name = models.CharField(
#         max_length=100,
#         verbose_name='OGR name',
#         help_text='Der von OGR verwendete Name.',
#         choices=get_ogr_formats_tuple())
#     file_extension = models.CharField(
#         max_length=100,
#         help_text='Die Dateiendung des Formats. Beispiel: gpx (ohne Punkt am Anfang!)')
#     output_type = models.CharField(
#         max_length=100,
#         help_text='Ausgabe dieses OGR-Formats in eine Datei (meistens) oder Ordner (z.B. bei ESRI Shapefile).',
#         choices=(('file', 'File'),
#                  ('folder', 'Folder')),
#         default='file')
#     state_all_files = models.BooleanField(
#         verbose_name='List all files, separated by commas.',
#         help_text='Hat einen Einfluss auf den im Terminal ausgeführten Befehl. Ist die Option aktiviert, sieht der Befehl z.B. so aus: ogr2ogr ... "input.itf,model.ili".')
#     is_export_format = models.BooleanField(
#         verbose_name='Show as export format.',
#         help_text='Bestimmt, ob dieses Format auf der Webseite für Besucher als Exportformat sichtbar ist.')
# 
#     def __unicode__(self):
#         return self.name
# 
#     def is_active(self):
#         return self.is_export_format and self.is_writeable()
#     is_active.boolean = True
# 
#     def is_readable(self):
#         supported_formats = ogrinfo.get_supported_formats()
# 
#         for ogr_format in supported_formats:
#             if ogr_format.name == self.ogr_name and ogr_format.read:
#                 return True
# 
#         return False
#     is_readable.boolean = True
# 
#     def is_writeable(self):
#         supported_formats = ogrinfo.get_supported_formats()
# 
#         for ogr_format in supported_formats:
#             if ogr_format.name == self.ogr_name and ogr_format.write:
#                 return True
# 
#         return False
#     is_writeable.boolean = True
# 
#     class Meta:
#         verbose_name = 'OGR format'
#         verbose_name_plural = 'OGR formats'
# 
#     @staticmethod
#     def get_formats_information_dictionary():
#         formats_information = {}
# 
#         for ogr_format in OgrFormat.objects.all():
#             name = ogr_format.name
#             ogr_name = ogr_format.ogr_name
#             extension = ogr_format.file_extension
#             is_folder = ogr_format.output_type == 'folder'
#             state_all_files = ogr_format.state_all_files
#             formats_information[name] = OgrFormatInformation(
#                 name,
#                 ogr_name,
#                 extension,
#                 is_folder,
#                 state_all_files,
#                 [],
#                 [])
# 
#         for additional_ogr_format in AdditionalOgrFormat.objects.all():
#             file_extension = additional_ogr_format.file_extension
#             is_required = additional_ogr_format.required
#             is_multiple = additional_ogr_format.multiple
#             formats_information[
#                 additional_ogr_format.ogr_format.name].additional_files.append(
#                 AdditionalOgrFormatInformation(
#                     file_extension,
#                     is_required,
#                     is_multiple))
# 
#         for additional_shell_parameter in OgrFormatShellParameter.objects.all():
#             prefix = additional_shell_parameter.prefix
#             parameter_name = additional_shell_parameter.parameter_name
#             parameter_value = additional_shell_parameter.parameter_value
#             value_quotation_marks = additional_shell_parameter.value_quotation_marks
#             use_for_reading = additional_shell_parameter.use_for_reading
#             use_for_writing = additional_shell_parameter.use_for_writing
#             formats_information[
#                 additional_shell_parameter.ogr_format.name].additional_parameters.append(
#                 AdditionalShellParameterInformation(
#                     prefix,
#                     parameter_name,
#                     parameter_value,
#                     value_quotation_marks,
#                     use_for_reading,
#                     use_for_writing))
# 
#         return formats_information
# 
#     @staticmethod
#     def get_format_information_by_name(ogr_format):
#         format_dictionary = OgrFormat.get_formats_information_dictionary()
#         if ogr_format in format_dictionary:
#             return format_dictionary[ogr_format]
#         else:
#             return None
# 
#     @staticmethod
#     def get_ogr_name_by_file_extension(file_extension):
#         for ogr_format in OgrFormat.objects.all():
#             if ogr_format.file_extension.lower() == file_extension.lower():
#                 return ogr_format.name
#         return ''
# 
#     @staticmethod
#     def contains_extension(file_extension):
#         return OgrFormat.get_ogr_name_by_file_extension(file_extension) != ''


from django import forms
from OGRgeoConverter.models import OgrFormat


class GeoConverterFilesForm(forms.Form):
    fileupload = forms.FileField(label='File')
    files_ogrformat = forms.ChoiceField(
        widget=forms.Select,
        label='Export format')

    def __init__(self, post=None, files=None):
        forms.Form.__init__(self, post, files)
        self.fields['files_ogrformat'].choices = [
            ('', '--Choose--')] + [
            (c.name, c.name) for c in OgrFormat.objects.all().order_by('name')
            if c.is_active()]
        self.files = files
        self.post = post


class GeoConverterWebservicesForm(forms.Form):
    urlinput = forms.CharField()
    webservices_ogrformat = forms.ChoiceField(
        widget=forms.Select,
        label='Export format')

    def __init__(self, post=None, url=None):
        forms.Form.__init__(self, post, url)
        self.fields['webservices_ogrformat'].choices = [
            ('', '--Choose--')] + [

# Path: OGRgeoConverter/models.py
# class OgrFormat(models.Model):
#     name = models.CharField(
#         max_length=100, unique=True,
#         help_text='Name des Formats, wie er auf der Webseite angezeigt werden soll.')
#     ogr_name = models.CharField(
#         max_length=100,
#         verbose_name='OGR name',
#         help_text='Der von OGR verwendete Name.',
#         choices=get_ogr_formats_tuple())
#     file_extension = models.CharField(
#         max_length=100,
#         help_text='Die Dateiendung des Formats. Beispiel: gpx (ohne Punkt am Anfang!)')
#     output_type = models.CharField(
#         max_length=100,
#         help_text='Ausgabe dieses OGR-Formats in eine Datei (meistens) oder Ordner (z.B. bei ESRI Shapefile).',
#         choices=(('file', 'File'),
#                  ('folder', 'Folder')),
#         default='file')
#     state_all_files = models.BooleanField(
#         verbose_name='List all files, separated by commas.',
#         help_text='Hat einen Einfluss auf den im Terminal ausgeführten Befehl. Ist die Option aktiviert, sieht der Befehl z.B. so aus: ogr2ogr ... "input.itf,model.ili".')
#     is_export_format = models.BooleanField(
#         verbose_name='Show as export format.',
#         help_text='Bestimmt, ob dieses Format auf der Webseite für Besucher als Exportformat sichtbar ist.')
# 
#     def __unicode__(self):
#         return self.name
# 
#     def is_active(self):
#         return self.is_export_format and self.is_writeable()
#     is_active.boolean = True
# 
#     def is_readable(self):
#         supported_formats = ogrinfo.get_supported_formats()
# 
#         for ogr_format in supported_formats:
#             if ogr_format.name == self.ogr_name and ogr_format.read:
#                 return True
# 
#         return False
#     is_readable.boolean = True
# 
#     def is_writeable(self):
#         supported_formats = ogrinfo.get_supported_formats()
# 
#         for ogr_format in supported_formats:
#             if ogr_format.name == self.ogr_name and ogr_format.write:
#                 return True
# 
#         return False
#     is_writeable.boolean = True
# 
#     class Meta:
#         verbose_name = 'OGR format'
#         verbose_name_plural = 'OGR formats'
# 
#     @staticmethod
#     def get_formats_information_dictionary():
#         formats_information = {}
# 
#         for ogr_format in OgrFormat.objects.all():
#             name = ogr_format.name
#             ogr_name = ogr_format.ogr_name
#             extension = ogr_format.file_extension
#             is_folder = ogr_format.output_type == 'folder'
#             state_all_files = ogr_format.state_all_files
#             formats_information[name] = OgrFormatInformation(
#                 name,
#                 ogr_name,
#                 extension,
#                 is_folder,
#                 state_all_files,
#                 [],
#                 [])
# 
#         for additional_ogr_format in AdditionalOgrFormat.objects.all():
#             file_extension = additional_ogr_format.file_extension
#             is_required = additional_ogr_format.required
#             is_multiple = additional_ogr_format.multiple
#             formats_information[
#                 additional_ogr_format.ogr_format.name].additional_files.append(
#                 AdditionalOgrFormatInformation(
#                     file_extension,
#                     is_required,
#                     is_multiple))
# 
#         for additional_shell_parameter in OgrFormatShellParameter.objects.all():
#             prefix = additional_shell_parameter.prefix
#             parameter_name = additional_shell_parameter.parameter_name
#             parameter_value = additional_shell_parameter.parameter_value
#             value_quotation_marks = additional_shell_parameter.value_quotation_marks
#             use_for_reading = additional_shell_parameter.use_for_reading
#             use_for_writing = additional_shell_parameter.use_for_writing
#             formats_information[
#                 additional_shell_parameter.ogr_format.name].additional_parameters.append(
#                 AdditionalShellParameterInformation(
#                     prefix,
#                     parameter_name,
#                     parameter_value,
#                     value_quotation_marks,
#                     use_for_reading,
#                     use_for_writing))
# 
#         return formats_information
# 
#     @staticmethod
#     def get_format_information_by_name(ogr_format):
#         format_dictionary = OgrFormat.get_formats_information_dictionary()
#         if ogr_format in format_dictionary:
#             return format_dictionary[ogr_format]
#         else:
#             return None
# 
#     @staticmethod
#     def get_ogr_name_by_file_extension(file_extension):
#         for ogr_format in OgrFormat.objects.all():
#             if ogr_format.file_extension.lower() == file_extension.lower():
#                 return ogr_format.name
#         return ''
# 
#     @staticmethod
#     def contains_extension(file_extension):
#         return OgrFormat.get_ogr_name_by_file_extension(file_extension) != ''


# Path: OGRgeoConverter/forms.py
from django import forms
from OGRgeoConverter.models import OgrFormat



class GeoConverterFilesForm(forms.Form):
    fileupload = forms.FileField(label='File')
    files_ogrformat = forms.ChoiceField(
        widget=forms.Select,
        label='Export format')

    def __init__(self, post=None, files=None):
        forms.Form.__init__(self, post, files)
        self.fields['files_ogrformat'].choices = [
            ('', '--Choose--')] + [
            (c.name, c.name) for c in OgrFormat.objects.all().order_by('name')
            if c.is_active()]
        self.files = files
        self.post = post


class GeoConverterWebservicesForm(forms.Form):
    urlinput = forms.CharField()
    webservices_ogrformat = forms.ChoiceField(
        widget=forms.Select,
        label='Export format')

    def __init__(self, post=None, url=None):
        forms.Form.__init__(self, post, url)
        self.fields['webservices_ogrformat'].choices = [
            ('', '--Choose--')] + [

            (c.name, c.name) for c in OgrFormat.objects.all().order_by('name')