
from django.db import migrations


def update_url_to_community(apps, schema_editor):
  people_url = "/people"
  mentor_url = "/directory"
  community_url = "/community"
  SiteRedirectPage = apps.get_model('accelerator', 'SiteRedirectPage')
  for siteredirectpage in SiteRedirectPage.objects.all():
    has_old_url = siteredirectpage.objects.filter(new_url=people_url).filter(new_url=mentor_url)
    if has_old_url.exists():
      has_old_url.update(new_url=community_url)
        
class Migration(migrations.Migration):

    dependencies = [
        ('accelerator', '0073_auto_20210909_1706'),
    ]

    operations = [
        migrations.RunPython(update_url_to_community,
                             migrations.RunPython.noop)
    ]


from django.db import migrations
from django.db.models.query_utils import Q


def update_url_to_community(apps, schema_editor):
  people_url = "/people"
  mentor_url = "/directory"
  community_url = "/community"
  SiteRedirectPage = apps.get_model('accelerator', 'SiteRedirectPage')
  for siteredirectpage in SiteRedirectPage.objects.all():
    has_old_url = siteredirectpage.objects.filter(Q(new_url=people_url)| Q(new_url=mentor_url))
    if has_old_url.exists():
      has_old_url.update(new_url=community_url)
        
class Migration(migrations.Migration):

    dependencies = [
        ('accelerator', '0073_auto_20210909_1706'),
    ]

    operations = [
        migrations.RunPython(update_url_to_community,
                             migrations.RunPython.noop)
    ]

Fix filter for people and mentor urls
[AC-9046] Fix filter for people and mentor urls

  
  from django.db import migrations
+ from django.db.models.query_utils import Q
  
  
  def update_url_to_community(apps, schema_editor):
    people_url = "/people"
    mentor_url = "/directory"
    community_url = "/community"
    SiteRedirectPage = apps.get_model('accelerator', 'SiteRedirectPage')
    for siteredirectpage in SiteRedirectPage.objects.all():
-     has_old_url = siteredirectpage.objects.filter(new_url=people_url).filter(new_url=mentor_url)
+     has_old_url = siteredirectpage.objects.filter(Q(new_url=people_url)| Q(new_url=mentor_url))
      if has_old_url.exists():
        has_old_url.update(new_url=community_url)
          
  class Migration(migrations.Migration):
  
      dependencies = [
          ('accelerator', '0073_auto_20210909_1706'),
      ]
  
      operations = [
          migrations.RunPython(update_url_to_community,
                               migrations.RunPython.noop)
      ]
  
Fix filter for people and mentor urls
## Code Before:

from django.db import migrations


def update_url_to_community(apps, schema_editor):
  people_url = "/people"
  mentor_url = "/directory"
  community_url = "/community"
  SiteRedirectPage = apps.get_model('accelerator', 'SiteRedirectPage')
  for siteredirectpage in SiteRedirectPage.objects.all():
    has_old_url = siteredirectpage.objects.filter(new_url=people_url).filter(new_url=mentor_url)
    if has_old_url.exists():
      has_old_url.update(new_url=community_url)
        
class Migration(migrations.Migration):

    dependencies = [
        ('accelerator', '0073_auto_20210909_1706'),
    ]

    operations = [
        migrations.RunPython(update_url_to_community,
                             migrations.RunPython.noop)
    ]

## Instruction:
Fix filter for people and mentor urls
## Code After:

from django.db import migrations
from django.db.models.query_utils import Q


def update_url_to_community(apps, schema_editor):
  people_url = "/people"
  mentor_url = "/directory"
  community_url = "/community"
  SiteRedirectPage = apps.get_model('accelerator', 'SiteRedirectPage')
  for siteredirectpage in SiteRedirectPage.objects.all():
    has_old_url = siteredirectpage.objects.filter(Q(new_url=people_url)| Q(new_url=mentor_url))
    if has_old_url.exists():
      has_old_url.update(new_url=community_url)
        
class Migration(migrations.Migration):

    dependencies = [
        ('accelerator', '0073_auto_20210909_1706'),
    ]

    operations = [
        migrations.RunPython(update_url_to_community,
                             migrations.RunPython.noop)
    ]
