<commit_before># This file is part of Shoop.
#
# Copyright (c) 2012-2016, Shoop Ltd. All rights reserved.
#
# This source code is licensed under the AGPLv3 license found in the
# LICENSE file in the root directory of this source tree.

from __future__ import unicode_literals

from django.db.transaction import atomic

from shoop.admin.form_part import FormPartsViewMixin, SaveFormPartsMixin
from shoop.admin.modules.services.base_form_part import (
    PaymentMethodBaseFormPart, ShippingMethodBaseFormPart
)
from shoop.admin.modules.services.behavior_form_part import \
    BehaviorComponentFormPart
from shoop.admin.toolbar import get_default_edit_toolbar
from shoop.admin.utils.urls import get_model_url
from shoop.admin.utils.views import CreateOrUpdateView
from shoop.apps.provides import get_provide_objects
from shoop.core.models import PaymentMethod, ShippingMethod


class ServiceEditView(SaveFormPartsMixin, FormPartsViewMixin, CreateOrUpdateView):
    model = None  # Override in subclass
    template_name = "shoop/admin/services/edit.jinja"
    context_object_name = "service"
    base_form_part_classes = []  # Override in subclass
    provide_key = "service_behavior_component_form"

    @atomic
    def form_valid(self, form):
        return self.save_form_parts(form)

    def get_form_parts(self, object):
        form_parts = super(ServiceEditView, self).get_form_parts(object)
        if not object.pk:
            return form_parts
        for form in get_provide_objects(self.provide_key):
            form_parts.append(self._get_behavior_form_part(form, object))
        return form_parts

    def _get_behavior_form_part(self, form, object):
        return BehaviorComponentFormPart(self.request, form, form._meta.model.__name__.lower(), object)

    def get_toolbar(self):
        save_form_id = self.get_save_form_id()
        object = self.get_object()
        delete_url = get_model_url(object, "delete")
        return get_default_edit_toolbar(self, save_form_id, delete_url=(delete_url if object.can_delete() else None))


class ShippingMethodEditView(ServiceEditView):<commit_msg>Admin: In service admin set delete url to None in new mode<commit_after># This file is part of Shoop.
#
# Copyright (c) 2012-2016, Shoop Ltd. All rights reserved.
#
# This source code is licensed under the AGPLv3 license found in the
# LICENSE file in the root directory of this source tree.

from __future__ import unicode_literals

from django.db.transaction import atomic

from shoop.admin.form_part import FormPartsViewMixin, SaveFormPartsMixin
from shoop.admin.modules.services.base_form_part import (
    PaymentMethodBaseFormPart, ShippingMethodBaseFormPart
)
from shoop.admin.modules.services.behavior_form_part import \
    BehaviorComponentFormPart
from shoop.admin.toolbar import get_default_edit_toolbar
from shoop.admin.utils.urls import get_model_url
from shoop.admin.utils.views import CreateOrUpdateView
from shoop.apps.provides import get_provide_objects
from shoop.core.models import PaymentMethod, ShippingMethod


class ServiceEditView(SaveFormPartsMixin, FormPartsViewMixin, CreateOrUpdateView):
    model = None  # Override in subclass
    template_name = "shoop/admin/services/edit.jinja"
    context_object_name = "service"
    base_form_part_classes = []  # Override in subclass
    provide_key = "service_behavior_component_form"

    @atomic
    def form_valid(self, form):
        return self.save_form_parts(form)

    def get_form_parts(self, object):
        form_parts = super(ServiceEditView, self).get_form_parts(object)
        if not object.pk:
            return form_parts
        for form in get_provide_objects(self.provide_key):
            form_parts.append(self._get_behavior_form_part(form, object))
        return form_parts

    def _get_behavior_form_part(self, form, object):
        return BehaviorComponentFormPart(self.request, form, form._meta.model.__name__.lower(), object)

    def get_toolbar(self):
        save_form_id = self.get_save_form_id()
        object = self.get_object()
        delete_url = get_model_url(object, "delete") if object.pk else None
        return get_default_edit_toolbar(self, save_form_id, delete_url=(delete_url if object.can_delete() else None))


class ShippingMethodEditView(ServiceEditView):
{'fraction_non_alphanumeric': 0.07036346691519105, 'fraction_numerical': 0.004193849021435228, 'mean_word_length': 4.468789808917197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7649118', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1242, 'n_words': 318}