"Fossies" - the Fresh Open Source Software Archive

Member "taiga-back-5.0.6/taiga/hooks/gitlab/migrations/0002_auto_20150703_1102.py" (15 Jan 2020, 1772 Bytes) of package /linux/www/taiga-back-5.0.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "0002_auto_20150703_1102.py" see the Fossies "Dox" file reference documentation.

    1 # -*- coding: utf-8 -*-
    2 from __future__ import unicode_literals
    3 
    4 from django.db import models, migrations
    5 from django.core.files import File
    6 
    7 def update_gitlab_system_user_photo_to_v2(apps, schema_editor):
    8     # We get the model from the versioned app registry;
    9     # if we directly import it, it'll be the wrong version
   10     User = apps.get_model("users", "User")
   11     db_alias = schema_editor.connection.alias
   12 
   13     try:
   14         user = User.objects.using(db_alias).get(username__startswith="gitlab-",
   15                                                 is_active=False,
   16                                                 is_system=True)
   17         f = open("taiga/hooks/gitlab/migrations/logo-v2.png", "rb")
   18         user.photo.save("logo.png", File(f))
   19         user.save()
   20     except User.DoesNotExist:
   21         pass
   22 
   23 def update_gitlab_system_user_photo_to_v1(apps, schema_editor):
   24     # We get the model from the versioned app registry;
   25     # if we directly import it, it'll be the wrong version
   26     User = apps.get_model("users", "User")
   27     db_alias = schema_editor.connection.alias
   28 
   29     try:
   30         user = User.objects.using(db_alias).get(username__startswith="gitlab-",
   31                                                 is_active=False,
   32                                                 is_system=True)
   33         f = open("taiga/hooks/gitlab/migrations/logo.png", "rb")
   34         user.photo.save("logo.png", File(f))
   35         user.save()
   36     except User.DoesNotExist:
   37         pass
   38 
   39 
   40 class Migration(migrations.Migration):
   41 
   42     dependencies = [
   43         ('gitlab', '0001_initial'),
   44         ('users', '0011_user_theme'),
   45     ]
   46 
   47     operations = [
   48         migrations.RunPython(update_gitlab_system_user_photo_to_v2,
   49                              update_gitlab_system_user_photo_to_v1),
   50     ]