Beispiel #1
0
    def handle(self, *args, **options):
        if not settings.REPANIER_SETTINGS_DEMO:
            self.stdout.write(self.style.ERROR("Command not executed because the site is not in DEMO MODE"))
            exit()
        translation.activate(settings.LANGUAGE_CODE)
        config = Configuration.objects.filter(id=DECIMAL_ONE).first()
        if config is None:
            exit()
        config.bank_account = "BE99 9999 9999 9999"
        config.vat_id = EMPTY_STRING
        config.save()
        config.init_email()
        for customer in Customer.objects.all().order_by('?'):
            customer.anonymize(also_group=True)
            customer.user.set_password("customer")
            customer.user.save()
            print("Customer anonymized : {}".format(customer))
        for staff in Staff.objects.all().order_by('?'):
            staff.anonymize()
            print("Staff anonymized : {}".format(staff))
        coordinator_password = options['coordinator_password'][0]
        coordinator_email = options['coordinator_email'][0].lower()
        coordinator = Staff.get_or_create_any_coordinator()
        coordinator.user.set_password(coordinator_password)
        coordinator.user.email = coordinator_email
        coordinator.user.save()
        for producer in Producer.objects.all().order_by('?'):
            producer.anonymize(also_group=True)
            print("Producer anonymized : {}".format(producer))
        for permanence_role in LUT_PermanenceRole.objects.all().order_by('?'):
            for language in settings.PARLER_LANGUAGES[settings.SITE_ID]:
                language_code = language["code"]
                permanence_role.set_current_language(language_code)
                try:
                    permanence_role.description = EMPTY_STRING
                    permanence_role.save_translations()
                except TranslationDoesNotExist:
                    pass
        BankAccount.objects.filter(customer__isnull=False).order_by('?').update(operation_comment=EMPTY_STRING)

        if options['reset_admin']:
            self.stdout.write(self.style.SUCCESS("Reset admin to admin/admin"))
            for user in User.objects.filter(is_superuser=True):
                str_id = str(user.id)
                user.username = user.email = "{}@repanier.be".format(str_id)
                user.first_name = EMPTY_STRING
                user.last_name = str_id
                user.is_staff = False
                user.is_superuser = False
                user.set_password(None)
                user.save()
            User.objects.create_user(username="******", email="*****@*****.**", password="******",
                                     first_name=EMPTY_STRING, last_name="admin", is_staff=True, is_superuser=True)
        self.stdout.write(self.style.SUCCESS("Successfully anonymized customers, staff and producers"))
Beispiel #2
0
    def init_repanier(cls):
        from repanier.const import DECIMAL_ONE, PERMANENCE_NAME_PERMANENCE, CURRENCY_EUR
        from repanier.models.producer import Producer
        from repanier.models.bankaccount import BankAccount
        from repanier.models.staff import Staff
        from repanier.models.customer import Customer

        # Create the configuration record managed via the admin UI
        config = Configuration.objects.filter(id=DECIMAL_ONE).first()
        if config is not None:
            return config
        group_name = settings.REPANIER_SETTINGS_GROUP_NAME
        site = Site.objects.get_current()
        if site is not None:
            site.name = group_name
            site.domain = group_name
            site.save()
        config = Configuration.objects.create(
            group_name=group_name,
            name=PERMANENCE_NAME_PERMANENCE,
            bank_account="BE99 9999 9999 9999",
            currency=CURRENCY_EUR)
        config.init_email()
        config.save()

        # Create firsts users
        Producer.get_or_create_group()
        customer_buyinggroup = Customer.get_or_create_group()
        very_first_customer = Customer.get_or_create_the_very_first_customer()

        BankAccount.open_account(customer_buyinggroup=customer_buyinggroup,
                                 very_first_customer=very_first_customer)

        coordinator = Staff.get_or_create_any_coordinator()
        Staff.get_or_create_order_responsible()
        Staff.get_or_create_invoice_responsible()
        # Create and publish first web page
        if not coordinator.is_webmaster:
            # This should not be the case...
            return

        from cms.models import StaticPlaceholder
        from cms.constants import X_FRAME_OPTIONS_DENY
        from cms import api
        page = api.create_page(title=_("Home"),
                               soft_root=False,
                               template=settings.CMS_TEMPLATE_HOME,
                               language=settings.LANGUAGE_CODE,
                               published=True,
                               parent=None,
                               xframe_options=X_FRAME_OPTIONS_DENY,
                               in_navigation=True)
        try:
            # New in CMS 3.5
            page.set_as_homepage()
        except:
            pass

        placeholder = page.placeholders.get(slot="home-hero")
        api.add_plugin(placeholder=placeholder,
                       plugin_type='TextPlugin',
                       language=settings.LANGUAGE_CODE,
                       body=settings.CMS_TEMPLATE_HOME_HERO)
        placeholder = page.placeholders.get(slot="home-col-1")
        api.add_plugin(placeholder=placeholder,
                       plugin_type='TextPlugin',
                       language=settings.LANGUAGE_CODE,
                       body=settings.CMS_TEMPLATE_HOME_COL_1)
        placeholder = page.placeholders.get(slot="home-col-2")
        api.add_plugin(placeholder=placeholder,
                       plugin_type='TextPlugin',
                       language=settings.LANGUAGE_CODE,
                       body=settings.CMS_TEMPLATE_HOME_COL_2)
        placeholder = page.placeholders.get(slot="home-col-3")
        api.add_plugin(placeholder=placeholder,
                       plugin_type='TextPlugin',
                       language=settings.LANGUAGE_CODE,
                       body=settings.CMS_TEMPLATE_HOME_COL_3)
        static_placeholder = StaticPlaceholder(code="footer",
                                               # site_id=1
                                               )
        static_placeholder.save()
        api.add_plugin(placeholder=static_placeholder.draft,
                       plugin_type='TextPlugin',
                       language=settings.LANGUAGE_CODE,
                       body='hello world footer')
        static_placeholder.publish(request=None,
                                   language=settings.LANGUAGE_CODE,
                                   force=True)
        api.publish_page(page=page,
                         user=coordinator.user,
                         language=settings.LANGUAGE_CODE)

        return config
Beispiel #3
0
    def init_repanier(cls):
        from repanier.const import DECIMAL_ONE, PERMANENCE_NAME_PERMANENCE, CURRENCY_EUR
        from repanier.models.producer import Producer
        from repanier.models.bankaccount import BankAccount
        from repanier.models.staff import Staff
        from repanier.models.customer import Customer
        from repanier.models.lut import LUT_DepartmentForCustomer

        logger.debug("######## start of init_repanier")

        # Create the configuration record managed via the admin UI
        config = Configuration.objects.filter(id=DECIMAL_ONE).first()
        if config is not None:
            return config
        site = Site.objects.get_current()
        if site is not None:
            site.name = settings.REPANIER_SETTINGS_GROUP_NAME
            site.domain = settings.ALLOWED_HOSTS[0]
            site.save()
        config = Configuration.objects.create(
            group_name=settings.REPANIER_SETTINGS_GROUP_NAME,
            name=PERMANENCE_NAME_PERMANENCE,
            bank_account="BE99 9999 9999 9999",
            currency=CURRENCY_EUR,
        )
        config.init_email()
        config.save()

        # Create firsts users
        Producer.get_or_create_group()
        customer_buyinggroup = Customer.get_or_create_group()
        very_first_customer = Customer.get_or_create_the_very_first_customer()

        BankAccount.open_account(
            customer_buyinggroup=customer_buyinggroup,
            very_first_customer=very_first_customer,
        )
        very_first_customer = Customer.get_or_create_the_very_first_customer()
        coordinator = Staff.get_or_create_any_coordinator()
        Staff.get_or_create_order_responsible()
        Staff.get_or_create_invoice_responsible()
        # Create and publish first web page
        if not coordinator.is_webmaster:
            # This should not be the case...
            return

        from cms.models import StaticPlaceholder
        from cms.constants import X_FRAME_OPTIONS_DENY
        from cms import api

        page = api.create_page(
            title=_("Home"),
            soft_root=False,
            template=settings.CMS_TEMPLATE_HOME,
            language=settings.LANGUAGE_CODE,
            published=True,
            parent=None,
            xframe_options=X_FRAME_OPTIONS_DENY,
            in_navigation=True,
        )
        try:
            # New in CMS 3.5
            page.set_as_homepage()
        except:
            pass

        placeholder = page.placeholders.get(slot="home-hero")
        api.add_plugin(
            placeholder=placeholder,
            plugin_type="TextPlugin",
            language=settings.LANGUAGE_CODE,
            body=settings.CMS_TEMPLATE_HOME_HERO,
        )
        static_placeholder = StaticPlaceholder(
            code="footer",
            # site_id=1
        )
        static_placeholder.save()
        api.add_plugin(
            placeholder=static_placeholder.draft,
            plugin_type="TextPlugin",
            language=settings.LANGUAGE_CODE,
            body="hello world footer",
        )
        static_placeholder.publish(
            request=None, language=settings.LANGUAGE_CODE, force=True
        )
        api.publish_page(
            page=page,
            user=coordinator.customer_responsible.user,
            language=settings.LANGUAGE_CODE,
        )

        if LUT_DepartmentForCustomer.objects.count() == 0:
            # Generate a template of LUT_DepartmentForCustomer
            parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Vegetable"))
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Basket of vegetables"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Salad"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Tomato"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Potato"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Green"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Cabbage"), parent=parent
            )
            parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Fruit"))
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Basket of fruits"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Apple"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Pear"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Plum"), parent=parent
            )
            parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Bakery"))
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Flour"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Bread"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Pastry"), parent=parent
            )
            parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Butchery"))
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Delicatessen"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Chicken"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Pork"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Beef"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Beef and pork"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Veal"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Lamb"), parent=parent
            )
            parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Grocery"))
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Takeaway"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Pasta"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Chocolate"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(short_name=_("Oil"), parent=parent)
            LUT_DepartmentForCustomer.objects.create(short_name=_("Egg"), parent=parent)
            LUT_DepartmentForCustomer.objects.create(short_name=_("Jam"), parent=parent)
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Cookie"), parent=parent
            )
            parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Creamery"))
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Dairy"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Cow cheese"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Goat cheese"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Sheep cheese"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Mixed cheese"), parent=parent
            )
            parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Icecream"))
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Cup of icecream"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Icecream per liter"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Icecream in frisco"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Icecream cake"), parent=parent
            )
            parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Sorbet"))
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Cup of sorbet"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Sorbet per liter"), parent=parent
            )
            parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Drink"))
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Juice"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Coffee"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(short_name=_("Tea"), parent=parent)
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Herbal tea"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Wine"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Aperitif"), parent=parent
            )
            LUT_DepartmentForCustomer.objects.create(
                short_name=_("Liqueurs"), parent=parent
            )
            parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Hygiene"))
            parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Deposit"))
            parent = LUT_DepartmentForCustomer.objects.create(
                short_name=_("Subscription")
            )

        logger.debug("######## end of init_repanier")

        return config
Beispiel #4
0
    def init_repanier(cls):
        from repanier.const import DECIMAL_ONE, PERMANENCE_NAME_PERMANENCE, CURRENCY_EUR
        from repanier.models.producer import Producer
        from repanier.models.bankaccount import BankAccount
        from repanier.models.staff import Staff
        from repanier.models.customer import Customer

        # Create the configuration record managed via the admin UI
        config = Configuration.objects.filter(id=DECIMAL_ONE).first()
        if config is not None:
            return config
        site = Site.objects.get_current()
        if site is not None:
            site.name = settings.REPANIER_SETTINGS_GROUP_NAME
            site.domain = settings.ALLOWED_HOSTS[0]
            site.save()
        config = Configuration.objects.create(
            group_name=settings.REPANIER_SETTINGS_GROUP_NAME,
            name=PERMANENCE_NAME_PERMANENCE,
            bank_account="BE99 9999 9999 9999",
            currency=CURRENCY_EUR
        )
        config.init_email()
        config.save()

        # Create firsts users
        Producer.get_or_create_group()
        customer_buyinggroup = Customer.get_or_create_group()
        very_first_customer = Customer.get_or_create_the_very_first_customer()

        BankAccount.open_account(
            customer_buyinggroup=customer_buyinggroup,
            very_first_customer=very_first_customer
        )

        coordinator = Staff.get_or_create_any_coordinator()
        Staff.get_or_create_order_responsible()
        Staff.get_or_create_invoice_responsible()
        # Create and publish first web page
        if not coordinator.is_webmaster:
            # This should not be the case...
            return

        from cms.models import StaticPlaceholder
        from cms.constants import X_FRAME_OPTIONS_DENY
        from cms import api
        page = api.create_page(
            title=_("Home"),
            soft_root=False,
            template=settings.CMS_TEMPLATE_HOME,
            language=settings.LANGUAGE_CODE,
            published=True,
            parent=None,
            xframe_options=X_FRAME_OPTIONS_DENY,
            in_navigation=True
        )
        try:
            # New in CMS 3.5
            page.set_as_homepage()
        except:
            pass

        placeholder = page.placeholders.get(slot="home-hero")
        api.add_plugin(
            placeholder=placeholder,
            plugin_type='TextPlugin',
            language=settings.LANGUAGE_CODE,
            body=settings.CMS_TEMPLATE_HOME_HERO)
        placeholder = page.placeholders.get(slot="home-col-1")
        api.add_plugin(
            placeholder=placeholder,
            plugin_type='TextPlugin',
            language=settings.LANGUAGE_CODE,
            body=settings.CMS_TEMPLATE_HOME_COL_1)
        placeholder = page.placeholders.get(slot="home-col-2")
        api.add_plugin(
            placeholder=placeholder,
            plugin_type='TextPlugin',
            language=settings.LANGUAGE_CODE,
            body=settings.CMS_TEMPLATE_HOME_COL_2)
        placeholder = page.placeholders.get(slot="home-col-3")
        api.add_plugin(
            placeholder=placeholder,
            plugin_type='TextPlugin',
            language=settings.LANGUAGE_CODE,
            body=settings.CMS_TEMPLATE_HOME_COL_3)
        static_placeholder = StaticPlaceholder(
            code="footer",
            # site_id=1
        )
        static_placeholder.save()
        api.add_plugin(
            placeholder=static_placeholder.draft,
            plugin_type='TextPlugin',
            language=settings.LANGUAGE_CODE,
            body='hello world footer'
        )
        static_placeholder.publish(
            request=None,
            language=settings.LANGUAGE_CODE,
            force=True
        )
        api.publish_page(
            page=page,
            user=coordinator.user,
            language=settings.LANGUAGE_CODE)

        return config