예제 #1
0
def migrate_sources(request):
    try:
          set_namespace('')
          old_site=db.get(db.Key(request.POST.get('old_site')))
          q=Query(ICalendarSource, namespace='').filter('site = ',old_site)
          old_sources=q.fetch(1000)


          set_namespace(request.POST.get('new_namespace'))
          new_site=db.get(db.Key(request.POST.get('new_site')))

          for old_source in old_sources:

              if old_source.submitted_by:
                  old_source.submitted_by=Profile.all().filter('slug =', old_source.submitted_by.slug).get()                    
              if old_source.approved_by:
                  old_source.approved_by=Profile.all().filter('slug =', old_source.approved_by.slug).get()

              new_source=clone_source(old_source, key_name=old_source.slug)
              new_source.site=new_site
              new_source.put()
              #old_source.delete()
           
           
          taskqueue.add(url='/admin/migrate-events/', params={'new_namespace':request.POST.get('new_namespace'),
                                                              'old_site':old_site.key(),
                                                              'new_site':new_site.key(),
                                                              },)
              

    except Exception,e:
                  logging.error("%s in \n%s"% (traceback.format_exc(),str(request.POST)))
예제 #2
0
def migrate_events(request):
    try:
        if request.method == 'POST':
            set_namespace('')
            logging.warning("namespace: %s" % get_namespace())
            cursor = request.POST.get('cursor')
            old_site = db.get(db.Key(request.POST.get('old_site')))
            logging.warning("old site: %s" % old_site)

            #q=Event.all().filter('site =', old_site)
            q = Query(Event, namespace='').filter('site = ', old_site)
            if cursor:
                q = q.with_cursor(cursor)
            events = q.fetch(1)
            logging.warning(events)
            set_namespace(request.POST.get('new_namespace'))
            new_site = db.get(db.Key(request.POST.get('new_site')))

            if events:
                taskqueue.add(
                    url='/admin/migrate-events/',
                    params={
                        'new_namespace': request.POST.get('new_namespace'),
                        'old_site': old_site.key(),
                        'new_site': new_site.key(),
                        'cursor': q.cursor()
                    },
                )
            for event in events:
                event.site = new_site

                #new_event.site=new_site
                if event.source:
                    event.source = ICalendarSource.all().filter(
                        'slug =', event.source.slug).get()
                if event.submitted_by:
                    event.submitted_by = Profile.all().filter(
                        'slug =', event.submitted_by.slug).get()
                if event.approved_by:
                    event.approved_by = Profile.all().filter(
                        'slug =', event.approved_by.slug).get()
                new_event = clone_event(event, key_name=event.key().name())
                #event.delete()
                new_event.put()

    except Exception, e:
        logging.error("%s in \n%s" %
                      (traceback.format_exc(), str(request.POST)))
예제 #3
0
 def handle(self, *args, **options):
     print("Start creating users")
     User.objects.all().delete()
     Profile.objects.all().delete()
     f = open(path.join(BASE_DIR, "data", "users.json"))
     raw = f.read()
     f.close()
     js = json.loads(raw)
     for i in js:
         p = Profile()
         u = User()
         u.username = i['username']
         u.email = i['username']
         u.set_password(i['password'])
         u.is_active = True
         if i['is_admin']:
             u.is_superuser = True
             u.is_staff = True
         u.save()
         p.user = u
         p.wins = i['wins']
         p.lose = i['lose']
         p.leave = i['leave']
         p.all = i['all']
         p.coins = i['coins']
         p.phone = i['phone']
         p.rating = i['rating']
         p.birthday = i['birthday']
         p.gender = i['gender']
         p.country = i['country']
         p.save()
         print i['username']
예제 #4
0
def migrate_events(request):
    try:
        if request.method == 'POST':
            set_namespace('')
            logging.warning("namespace: %s" % get_namespace())
            cursor=request.POST.get('cursor')
            old_site=db.get(db.Key(request.POST.get('old_site')))
            logging.warning("old site: %s" % old_site)
            
            #q=Event.all().filter('site =', old_site)
            q=Query(Event, namespace='').filter('site = ',old_site)
            if cursor:
                q=q.with_cursor(cursor)
            events= q.fetch(1)                                               
            logging.warning(events)
            set_namespace(request.POST.get('new_namespace'))
            new_site=db.get(db.Key(request.POST.get('new_site')))
            
            if events:
                taskqueue.add(url='/admin/migrate-events/', params={'new_namespace':request.POST.get('new_namespace'),
                                                                    'old_site':old_site.key(),
                                                                    'new_site':new_site.key(),
                                                                    'cursor':q.cursor()
                                                                    },)
            for event in events:   
                    event.site=new_site
                    
                    #new_event.site=new_site
                    if event.source:
                        event.source=ICalendarSource.all().filter('slug =', event.source.slug).get()
                    if event.submitted_by:
                        event.submitted_by=Profile.all().filter('slug =', event.submitted_by.slug).get()                    
                    if event.approved_by:
                        event.approved_by=Profile.all().filter('slug =', event.approved_by.slug).get()
                    new_event= clone_event(event, key_name=event.key().name())
                    #event.delete()
                    new_event.put()

                
    except Exception,e:
            logging.error("%s in \n%s"% (traceback.format_exc(),str(request.POST)))
예제 #5
0
def migrate_sources(request):
    try:
        set_namespace('')
        old_site = db.get(db.Key(request.POST.get('old_site')))
        q = Query(ICalendarSource, namespace='').filter('site = ', old_site)
        old_sources = q.fetch(1000)

        set_namespace(request.POST.get('new_namespace'))
        new_site = db.get(db.Key(request.POST.get('new_site')))

        for old_source in old_sources:

            if old_source.submitted_by:
                old_source.submitted_by = Profile.all().filter(
                    'slug =', old_source.submitted_by.slug).get()
            if old_source.approved_by:
                old_source.approved_by = Profile.all().filter(
                    'slug =', old_source.approved_by.slug).get()

            new_source = clone_source(old_source, key_name=old_source.slug)
            new_source.site = new_site
            new_source.put()
            #old_source.delete()

        taskqueue.add(
            url='/admin/migrate-events/',
            params={
                'new_namespace': request.POST.get('new_namespace'),
                'old_site': old_site.key(),
                'new_site': new_site.key(),
            },
        )

    except Exception, e:
        logging.error("%s in \n%s" %
                      (traceback.format_exc(), str(request.POST)))