0002-maps-duplicate-map-layer-options-57760.patch
combo/apps/maps/models.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import copy |
|
17 | 18 |
import json |
18 | 19 | |
19 | 20 |
import pyproj |
... | ... | |
520 | 521 | |
521 | 522 |
def duplicate_m2m(self, new_cell): |
522 | 523 |
# set layers |
523 |
for layer in self.layers.all(): |
|
524 |
MapLayerOptions.objects.create(map_cell=new_cell, map_layer=layer) |
|
524 |
for options in self.maplayeroptions_set.all(): |
|
525 |
new_options = copy.deepcopy(options) |
|
526 |
new_options.pk = None |
|
527 |
new_options.map_cell = new_cell |
|
528 |
new_options.save() |
|
525 | 529 | |
526 | 530 | |
527 | 531 |
class MapLayerOptions(models.Model): |
tests/test_maps_cells.py | ||
---|---|---|
639 | 639 |
def test_duplicate(layer): |
640 | 640 |
page = Page.objects.create(title='xxx', slug='new', template_name='standard') |
641 | 641 |
cell = Map.objects.create(page=page, placeholder='content', order=0, public=True, title='Map') |
642 |
MapLayerOptions.objects.create(map_cell=cell, map_layer=layer) |
|
642 |
MapLayerOptions.objects.create(map_cell=cell, map_layer=layer, opacity=0.5, properties='a, b')
|
|
643 | 643 | |
644 | 644 |
new_cell = cell.duplicate() |
645 | 645 |
assert list(new_cell.layers.all()) == [layer] |
646 |
options = new_cell.maplayeroptions_set.get() |
|
647 |
assert options.map_layer == layer |
|
648 |
assert options.opacity == 0.5 |
|
649 |
assert options.properties == 'a, b' |
|
646 |
- |