<commit_before># -*- coding: utf-8 -*-
# This file is part of Shoop.
#
# Copyright (c) 2012-2015, 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.conf import settings
from django.utils.translation import ugettext_lazy as _

from shoop.admin.forms.widgets import MediaChoiceWidget
from shoop.admin.utils.views import CreateOrUpdateView
from shoop.admin.toolbar import get_default_edit_toolbar
from shoop.core.models import Shop
from shoop.utils.excs import Problem
from shoop.utils.multilanguage_model_form import MultiLanguageModelForm


class ShopForm(MultiLanguageModelForm):
    class Meta:
        model = Shop
        exclude = ("owner", "options")

    def __init__(self, **kwargs):
        super(ShopForm, self).__init__(**kwargs)
        self.fields["logo"].widget = MediaChoiceWidget(clearable=True)


class ShopEditView(CreateOrUpdateView):
    model = Shop
    form_class = ShopForm
    template_name = "shoop/admin/shops/edit.jinja"
    context_object_name = "shop"

    def get_object(self, queryset=None):
        obj = super(ShopEditView, self).get_object(queryset)
        if not settings.SHOOP_ENABLE_MULTIPLE_SHOPS:
            if not obj.pk and Shop.objects.count() >= 1:
                # This seems like a new object, but there already is (at least) one shop...
                raise Problem(_(u"Only one shop permitted."))

        return obj

    def get_toolbar(self):
        save_form_id = self.get_save_form_id()<commit_msg>ShopEditView: Add form errors as messages<commit_after># -*- coding: utf-8 -*-
# This file is part of Shoop.
#
# Copyright (c) 2012-2015, 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.conf import settings
from django.utils.translation import ugettext_lazy as _

from shoop.admin.forms.widgets import MediaChoiceWidget
from shoop.admin.utils.views import CreateOrUpdateView
from shoop.admin.toolbar import get_default_edit_toolbar
from shoop.core.models import Shop
from shoop.utils.excs import Problem
from shoop.utils.multilanguage_model_form import MultiLanguageModelForm


class ShopForm(MultiLanguageModelForm):
    class Meta:
        model = Shop
        exclude = ("owner", "options")

    def __init__(self, **kwargs):
        super(ShopForm, self).__init__(**kwargs)
        self.fields["logo"].widget = MediaChoiceWidget(clearable=True)


class ShopEditView(CreateOrUpdateView):
    model = Shop
    form_class = ShopForm
    template_name = "shoop/admin/shops/edit.jinja"
    context_object_name = "shop"
    add_form_errors_as_messages = True

    def get_object(self, queryset=None):
        obj = super(ShopEditView, self).get_object(queryset)
        if not settings.SHOOP_ENABLE_MULTIPLE_SHOPS:
            if not obj.pk and Shop.objects.count() >= 1:
                # This seems like a new object, but there already is (at least) one shop...
                raise Problem(_(u"Only one shop permitted."))

        return obj

    def get_toolbar(self):
        save_form_id = self.get_save_form_id()
{'fraction_non_alphanumeric': 0.08421690396849439, 'fraction_numerical': 0.006664647076643442, 'mean_word_length': 3.567081604426003, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3385755', 'n_tokens_mistral': 992, 'n_tokens_neox': 951, 'n_words': 290}