From nobody Mon Sep 16 19:08:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1540949961502667.1893997724029; Tue, 30 Oct 2018 18:39:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 57B88356D3; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 440D219495; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3620D180B5B7; Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9V1TAsH012191 for ; Tue, 30 Oct 2018 21:29:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0745D6590E; Wed, 31 Oct 2018 01:29:10 +0000 (UTC) Received: from magic.redhat.com (ovpn-12-37.pek2.redhat.com [10.72.12.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FD225D9D6; Wed, 31 Oct 2018 01:29:08 +0000 (UTC) From: Fam Zheng To: patchew-devel@redhat.com Date: Wed, 31 Oct 2018 09:28:54 +0800 Message-Id: <20181031012856.30125-5-famz@redhat.com> In-Reply-To: <20181031012856.30125-1-famz@redhat.com> References: <20181031012856.30125-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 4/6] Make default group creation a migration X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 31 Oct 2018 01:39:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The ready hook isn't the right point to use DB. Signed-off-by: Fam Zheng --- api/apps.py | 14 ++---------- .../0037_populate_default_groups.py | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 api/migrations/0037_populate_default_groups.py diff --git a/api/apps.py b/api/apps.py index c7fc162..1210091 100644 --- a/api/apps.py +++ b/api/apps.py @@ -13,19 +13,9 @@ from django.apps import AppConfig import mod =20 -_default_groups =3D ['maintainers', 'testers', 'importers'] - -def create_default_groups(): - from django.contrib.auth.models import Group - for grp in _default_groups: - Group.objects.get_or_create(name=3Dgrp) - class ApiConfig(AppConfig): name =3D 'api' verbose_name =3D "Patchew Core" def ready(self): - try: - mod.load_modules() - create_default_groups() - except Exception as e: - print("Error while loading modules:", e) + from mod import load_modules + load_modules() diff --git a/api/migrations/0037_populate_default_groups.py b/api/migration= s/0037_populate_default_groups.py new file mode 100644 index 0000000..c0befa6 --- /dev/null +++ b/api/migrations/0037_populate_default_groups.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations +from django.db.models import Count +import json + + +def populate_default_groups(apps, schema_editor): + from django.contrib.auth.models import Group + for grp in ['maintainers', 'testers', 'importers']: + Group.objects.get_or_create(name=3Dgrp) + +class Migration(migrations.Migration): + + dependencies =3D [ + ('api', '0036_populate_message_tags'), + ] + + operations =3D [ + migrations.RunPython(populate_default_groups), + ] --=20 2.17.2 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel