Пример #1
0
 def form_valid(self, form):
     obj = form.save(commit=False)
     obj.creator = self.request.user
     xml_parse = read_xml_style(obj.file)
     if xml_parse:
         # check if name exists
         name_exist = Style.objects.filter(
             name__iexact=xml_parse['name']).exists()
         if name_exist:
             obj.name = "%s_%s" % (xml_parse['name'].title(),
                                   get_random_string(length=5))
         else:
             obj.name = xml_parse['name'].title()
         style_type = StyleType.objects.filter(
             symbol_type=xml_parse['type']).first()
         if not style_type:
             style_type = StyleType.objects.create(
                 symbol_type=xml_parse['type'],
                 name=xml_parse['type'].title(),
                 description="Automatically created from '"
                             "'an uploaded Style file")
         obj.style_type = style_type
     obj.save()
     resource_notify(obj, self.resource_name)
     msg = _("The Style has been successfully created.")
     messages.success(self.request, msg, 'success', fail_silently=True)
     return HttpResponseRedirect(reverse('style_detail',
                                         kwargs={'pk': obj.id}))
Пример #2
0
 def form_valid(self, form):
     """
     Update the style type according to the style XML file.
     """
     obj = form.save(commit=False)
     xml_parse = read_xml_style(obj.xml_file)
     if xml_parse:
         obj.style_type = StyleType.objects \
             .filter(symbol_type=xml_parse['type']).first()
     obj.require_action = False
     obj.save()
     msg = _("The Style has been successfully updated.")
     messages.success(self.request, msg, 'success', fail_silently=True)
     return HttpResponseRedirect(
         reverse_lazy('style_detail', kwargs={'pk': obj.id}))
Пример #3
0
 def test_read_symbol_marker_file(self):
     read_file = read_xml_style(self.symbol_marker_file)
     style_type = read_file['type']
     style_name = read_file['name']
     self.assertEqual(style_type, "marker")
     self.assertEqual(style_name, "dot  black")
Пример #4
0
 def test_read_symbol_fill_file(self):
     read_file = read_xml_style(self.symbol_fill_file)
     style_type = read_file['type']
     style_name = read_file['name']
     self.assertEqual(style_type, "fill")
     self.assertEqual(style_name, "topo swamp")
Пример #5
0
 def test_read_symbol_line_file(self):
     read_file = read_xml_style(self.symbol_line_file)
     style_type = read_file['type']
     style_name = read_file['name']
     self.assertEqual(style_type, "line")
     self.assertEqual(style_name, "cat trail")
Пример #6
0
 def test_read_text_format_file(self):
     read_file = read_xml_style(self.text_format_file)
     style_type = read_file['type']
     style_name = read_file['name']
     self.assertEqual(style_type, "textformat")
     self.assertEqual(style_name, "Basic Label")
Пример #7
0
 def test_read_symbol3d_file(self):
     read_file = read_xml_style(self.symbol3d_file)
     style_type = read_file['type']
     style_name = read_file['name']
     self.assertEqual(style_type, "symbol3d")
     self.assertEqual(style_name, "Cube")
Пример #8
0
 def test_read_color_ramp_file(self):
     read_file = read_xml_style(self.color_ramp_file)
     style_type = read_file['type']
     style_name = read_file['name']
     self.assertEqual(style_type, "colorramp")
     self.assertEqual(style_name, "Blues")
Пример #9
0
 def test_read_legend_patch_file(self):
     read_file = read_xml_style(self.legend_patch_file)
     style_type = read_file['type']
     style_name = read_file['name']
     self.assertEqual(style_type, "legendpatchshape")
     self.assertEqual(style_name, "Building 3")
Пример #10
0
 def test_read_label_setting_file(self):
     read_file = read_xml_style(self.label_setting_file)
     style_type = read_file['type']
     style_name = read_file['name']
     self.assertEqual(style_type, "labelsetting")
     self.assertEqual(style_name, "Basic Label Setting")