예제 #1
0
    def response_change(self, request, obj):
        opts = obj._meta
        verbose_name = opts.verbose_name
        if obj._deferred:
            opts_ = opts.proxy_for_model._meta
            verbose_name = opts_.verbose_name
        return_url = request.GET.get('rtn_url', None)

        if "_saveandsync" in request.POST:
            if obj.review_status == REVIEW_STATUS.APPROVED:
                sync_obj(obj, self.model)
                self.message_user(request, _("The %(name)s \"%(obj)s\" was changed successfully, and successfully synced to production.") \
                        % {'name': force_unicode(verbose_name), 'obj': force_unicode(obj)})
            else:
                self.message_user(request, _("The %(name)s \"%(obj)s\" was changed successfully, can't sync not reviewed %(name)s.") \
                        % {'name': force_unicode(verbose_name), 'obj': force_unicode(obj)})
            return HttpResponseRedirect("../")
        elif "_continue" not in request.POST and "_saveasnew" not in request.POST \
                and "_addanother" not in request.POST and self.has_change_permission(request, None) and return_url:
            msg = _('The %(name)s "%(obj)s" was changed successfully.') % {
                'name': force_unicode(verbose_name),
                'obj': force_unicode(obj)
            }
            self.message_user(request, msg)
            return HttpResponseRedirect(return_url)
        else:
            return super(EntityModelAdmin, self).response_change(request, obj)
예제 #2
0
def sync_region_to_mongo():
    all_phone = PhoneRegion.objects.filter(published=1, sync_status=0)
    try:
        for item in all_phone:
            sync_obj(item, PhoneRegion)
            print item.phone, item.province
    except Exception, e:
        print e
예제 #3
0
def sync_region_to_mongo():
    all_phone = PhoneRegion.objects.filter(published=1,sync_status=0)
    try:
        for item in all_phone:
            sync_obj(item, PhoneRegion)
            print item.phone, item.province
    except Exception,e:
        print e
예제 #4
0
 def sync_selected_items(self, request, queryset):
     n = queryset.count()
     if n:
         for obj in queryset:
             sync_obj(obj, self.model)
         self.message_user(request, _('Successfully synced %(count)d %(items)s.') % {
             'count': n, 'items': model_ngettext(self.opts, n)
         })
예제 #5
0
 def sync_selected_items(self, request, queryset):
     n = queryset.count()
     if n:
         for obj in queryset:
             sync_obj(obj, self.model)
         self.message_user(
             request,
             _('Successfully synced %(count)d %(items)s.') % {
                 'count': n,
                 'items': model_ngettext(self.opts, n)
             })
예제 #6
0
 def response_add(self, request, obj, post_url_continue='../%s/'):
     if "_saveandsync" in request.POST:
         if obj.review_status == REVIEW_STATUS.APPROVED:
             sync_obj(obj, self.model)
             self.message_user(request, _("The %(name)s \"%(obj)s\" was added successfully, and successfully synced to production.") \
                     % {'name': force_unicode(obj._meta.verbose_name), 'obj': force_unicode(obj)})
         else:
             self.message_user(request, _("The %(name)s \"%(obj)s\" was added successfully, can't sync not reviewed %(name)s.") \
                     % {'name': force_unicode(obj._meta.verbose_name), 'obj': force_unicode(obj)})
         return HttpResponseRedirect("../")
     else:
         return super(EntityModelAdmin, self).response_add(request, obj)
예제 #7
0
파일: admin.py 프로젝트: liuliainio/liuli
    def response_change(self, request, obj):
        app = obj.app
        app_category_id = app.category.id
        return_url = '/admin/cateapps/application' + str(app_category_id)

        if "_saveandsync" in request.POST:
            if obj.review_status == REVIEW_STATUS.APPROVED:
                sync_obj(app, Application)
                self.message_user(request, _("The %(name)s \"%(obj)s\" was changed successfully, and successfully synced to production.") %
                    {'name': force_unicode(self.opts.verbose_name), 'obj': force_unicode(app)})
                return HttpResponseRedirect(return_url)
        return super(AppVersionAdmin, self).response_change(request, obj)
예제 #8
0
 def response_add(self, request, obj, post_url_continue='../%s/'):
     if "_saveandsync" in request.POST:
         if obj.review_status == REVIEW_STATUS.APPROVED:
             sync_obj(obj, self.model)
             self.message_user(request, _("The %(name)s \"%(obj)s\" was added successfully, and successfully synced to production.") \
                     % {'name': force_unicode(obj._meta.verbose_name), 'obj': force_unicode(obj)})
         else:
             self.message_user(request, _("The %(name)s \"%(obj)s\" was added successfully, can't sync not reviewed %(name)s.") \
                     % {'name': force_unicode(obj._meta.verbose_name), 'obj': force_unicode(obj)})
         return HttpResponseRedirect("../")
     else:
         return super(EntityModelAdmin, self).response_add(request, obj)
예제 #9
0
def unpublish_app(index, count, id_list):
    apps = find_apps(index, count)
    id_set = make_id_set(id_list)
    for app in apps:
        if app.id in id_set:
            continue
        else:
            print 'unpublished: ', app.id, app.name
            app.published = 0
            online_status = is_app_online(app.id)
            if online_status:
                sync_obj(app, Application)
            else:
                app.save()
예제 #10
0
def unpublish_app(index, count, id_list):
    apps = find_apps(index, count)
    id_set = make_id_set(id_list)
    for app in apps:
        if app.id in id_set:
            continue
        else:
            print 'unpublished: ', app.id, app.name
            app.published = 0
            online_status = is_app_online(app.id)
            if online_status:
                sync_obj(app, Application)
            else:
                app.save()
예제 #11
0
    def response_change(self, request, obj):
        app = obj.app
        app_category_id = app.category.id
        return_url = '/admin/cateapps/application' + str(app_category_id)

        if "_saveandsync" in request.POST:
            if obj.review_status == REVIEW_STATUS.APPROVED:
                sync_obj(app, Application)
                self.message_user(
                    request,
                    _("The %(name)s \"%(obj)s\" was changed successfully, and successfully synced to production."
                      ) % {
                          'name': force_unicode(self.opts.verbose_name),
                          'obj': force_unicode(app)
                      })
                return HttpResponseRedirect(return_url)
        return super(AppVersionAdmin, self).response_change(request, obj)
예제 #12
0
def label_apps(apps):
    error_id_set = set()
    current_app_id = None

    try:
        for i, app in enumerate(apps):
            print '\nlocation:%s' % i
            label_dict = {}
            current_app_id = app.id
            if app.hided == 1:
                continue
            #update msyql
            if app.label:
                label_str = app.label
                label_dict = json.loads(label_str)
                if official_word not in label_dict['others']['tag']:
                    label_dict['others']['tag'].append(official_word)
                    print '[update tag]'
                app.label = json.dumps(label_dict,
                                       ensure_ascii=False).encode('utf-8')
            else:
                print '[add tag]'
                app.label = full_label_encoded

            #update online
            if is_app_online(app.id):
                #update mysql status again
                app.published = 1
                app.sync_status = 1
                sync_obj(app, Application)
                print 'update online: %s' % app.id
            else:
                print '%s not in online' % app.id
            app.save()
            print 'save app: %s' % app.id
    except Exception, e:
        print 'Fail to Sync:%s, %s' % (current_app_id, e)
        if current_app_id:
            error_id_set.add(current_app_id)
예제 #13
0
def label_apps(apps):
    error_id_set = set()
    current_app_id = None

    try:
        for i,app in enumerate(apps):
            print '\nlocation:%s' % i
            label_dict = {}
            current_app_id = app.id
            if app.hided == 1:
                continue
            #update msyql
            if app.label:
                label_str = app.label
                label_dict = json.loads(label_str)
                if official_word not in label_dict['others']['tag']:
                    label_dict['others']['tag'].append(official_word)
                    print '[update tag]'
                app.label = json.dumps(label_dict, ensure_ascii=False).encode('utf-8')
            else:
                print '[add tag]'
                app.label = full_label_encoded

            #update online
            if is_app_online(app.id):
                #update mysql status again
                app.published = 1
                app.sync_status = 1
                sync_obj(app, Application)
                print 'update online: %s' % app.id
            else:
                print '%s not in online' % app.id
            app.save()
            print 'save app: %s' % app.id
    except Exception,e:
        print 'Fail to Sync:%s, %s' % (current_app_id, e)
        if current_app_id:
            error_id_set.add(current_app_id)
예제 #14
0
def get_list(request):
    request_get = request.GET
    method = request_get.get('method', '')
    if method == '':
        return
    try:
        app_item = json.loads(request_get.get('app_list', ''))
    except Exception:
        app_item = ''
    if app_item == '':
        return 'input errr'
    sucess_count = 0
    error_count = 0
    apps = Application.objects.filter(package_name__in=app_item)

    if method == 'getInfo':
        package_info = []
        package_info.append(['', 'id', _('name'), _('current_version_name'), _('category_name'), _('sub_category_name'), _('clicks_count'), \
                _('downloads_count'), _('is_published'), _('sync_status')])
        for app in apps:
            package_info.append([app.package_name, app.id, app.name, app.current_version_name, \
                    app.category.name, app.sub_category_name().name, app.clicks_count, app.downloads_count, \
                    _('true') if app.published else _('false'), _('true') if app.sync_status else _('false')])
        return package_info if package_info else ''
    else:
        risk_app = request_get.get('risk_list', '')
        risk_apps = Application.objects.filter(package_name__in=risk_app)
        apps.update(published=0, sync_status=0)
        for app in apps:
            try:
                sync_obj(app, Application)
            except Exception:
                error_count = error_count + 1
                continue
            sucess_count = sucess_count + 1
        risk_apps.update(review_status=2, tag=2)
        return sucess_count
예제 #15
0
파일: views.py 프로젝트: liuliainio/liuli
def get_list(request):
    request_get = request.GET
    method = request_get.get('method', '')
    if method == '':
        return
    try:
        app_item = json.loads(request_get.get('app_list', ''))
    except Exception:
        app_item = ''
    if app_item == '':
        return 'input errr'
    sucess_count = 0
    error_count = 0
    apps = Application.objects.filter(package_name__in=app_item)

    if method == 'getInfo':
        package_info = []
        package_info.append(['', 'id', _('name'), _('current_version_name'), _('category_name'), _('sub_category_name'), _('clicks_count'), \
                _('downloads_count'), _('is_published'), _('sync_status')])
        for app in apps:
            package_info.append([app.package_name, app.id, app.name, app.current_version_name, \
                    app.category.name, app.sub_category_name().name, app.clicks_count, app.downloads_count, \
                    _('true') if app.published else _('false'), _('true') if app.sync_status else _('false')])
        return package_info if package_info else ''
    else:
        risk_app = request_get.get('risk_list', '')
        risk_apps = Application.objects.filter(package_name__in=risk_app)
        apps.update(published=0, sync_status=0)
        for app in apps:
            try:
                sync_obj(app, Application)
            except Exception:
                error_count = error_count + 1
                continue
            sucess_count = sucess_count + 1
        risk_apps.update(review_status=2, tag=2)
        return sucess_count
예제 #16
0
    def response_change(self, request, obj):
        opts = obj._meta
        verbose_name = opts.verbose_name
        if obj._deferred:
            opts_ = opts.proxy_for_model._meta
            verbose_name = opts_.verbose_name
        return_url = request.GET.get('rtn_url', None)

        if "_saveandsync" in request.POST:
            if obj.review_status == REVIEW_STATUS.APPROVED:
                sync_obj(obj, self.model)
                self.message_user(request, _("The %(name)s \"%(obj)s\" was changed successfully, and successfully synced to production.") \
                        % {'name': force_unicode(verbose_name), 'obj': force_unicode(obj)})
            else:
                self.message_user(request, _("The %(name)s \"%(obj)s\" was changed successfully, can't sync not reviewed %(name)s.") \
                        % {'name': force_unicode(verbose_name), 'obj': force_unicode(obj)})
            return HttpResponseRedirect("../")
        elif "_continue" not in request.POST and "_saveasnew" not in request.POST \
                and "_addanother" not in request.POST and self.has_change_permission(request, None) and return_url:
            msg = _('The %(name)s "%(obj)s" was changed successfully.') % {'name': force_unicode(verbose_name), 'obj': force_unicode(obj)}
            self.message_user(request, msg)
            return HttpResponseRedirect(return_url)
        else:
            return super(EntityModelAdmin, self).response_change(request, obj)