def save_or_update(self, request): '''新增和修改banner ''' banner_id = request.POST.get('banner_id', '') name = request.POST.get('name', '') original = request.POST.get('original', '') thumbnail = request.POST.get('thumbnail', '') background = request.POST.get('background', '') background_image_width = request.POST.get('background_image_width', '') background_image_color = request.POST.get('background_image_color', '') location = request.POST.get('page_url', '') order = request.POST.get('order', '') update_user = '' if 'session_id' in request.COOKIES: session_id = request.COOKIES['session_id'] update_user = self.cache.get(session_id)['username'] if banner_id: ban = Banner.objects.filter(id=banner_id) ban = ban[0] else: ban = Banner() ban.order = 1 ban.is_active = 1 ban.is_preview = 1 ban.name = name ban.original = original ban.thumbnail = thumbnail ban.background = background ban.background_image_width = background_image_width ban.background_image_color = background_image_color ban.location = location ban.update_user = update_user ban.save() return {'statusCode': 1}
def publish_banner(self): '''发布banner图 ''' # 1.复制新的banner草稿到线上banner draft_banner = Banner.objects.filter(is_preview=True,is_active=1) res_json = {'statusCode': 0, 'msg': ''} if draft_banner: # 2.删除老的线上banner old_banner = Banner.objects.filter(is_preview=False) old_banner.delete() for dra in draft_banner: ban = Banner() ban.name = dra.name ban.original = dra.original ban.thumbnail = dra.thumbnail ban.background = dra.background ban.background_image_width = dra.background_image_width ban.background_image_color = dra.background_image_color ban.location = dra.location ban.order = dra.order ban.is_active = 1 ban.update_user = dra.update_user ban.is_preview = False ban.save() res_json['statusCode'] = 1 else: res_json['statusCode'] = 0 res_json['msg'] = '预览数据异常,请检查后重试' return res_json
def init_banner_data(self): '''初始化数据,把banner数据复制一份到预览数据 ''' ban = Banner.objects.filter(is_preview=True) if ban: return {'statusCode':1, 'msg': 'preview data is already exist'} online_banner = Banner.objects.filter(is_preview=False) for dra in online_banner: ban = Banner() ban.name = dra.name ban.original = dra.original ban.thumbnail = dra.thumbnail ban.background = dra.background ban.background_image_width = dra.background_image_width ban.background_image_color = dra.background_image_color ban.location = dra.location ban.order = dra.order ban.is_active = dra.is_active ban.update_user = dra.update_user ban.is_preview = True ban.save() return {'statusCode':1, 'msg': 'success!'}