def export_rising(self): user = App.get_user_info(self) if not user: return HttpResponseRedirect("/admin/maxlead_site/login/") type = self.GET.get('type', 'Ours') viewRange = self.GET.get('viewRange', '') res = Dashboard._get_rising(self, user, type, viewRange, param=self.GET) fields = [ 'SKU', 'Asin', 'Reviews', 'Brand', 'Growth', 'Score', 'Score Change', 'Created' ] data_fields = [ 'sku', 'asin', 'total_review', 'brand', 'total_review2', 'rvw_score', 'rvw_score2', 'created' ] return get_excel_file(self, res, fields, data_fields)
def export_dash_reviews(self): user = App.get_user_info(self) if not user: return HttpResponseRedirect("/admin/maxlead_site/login/") revBgn = self.GET.get('revBgn', '') revEnd = self.GET.get('revEnd', '') viewRange = self.GET.get('viewRange', '') asins = Dashboard._get_asins(self,user,user_id=viewRange) review_max = Reviews.objects.filter(asin__in=asins).aggregate(Max('created')) if review_max and review_max['created__max']: reviews = Reviews.objects.filter(created__icontains=review_max['created__max'],score__lte=3, asin__in=asins).order_by('-review_date') if revBgn: reviews = reviews.filter(review_date__gte=revBgn) if revEnd: reviews = reviews.filter(review_date__lte=revEnd) data = [] for val in reviews: re = { 'title': val.title, 'variation': val.variation, 'asin': val.asin, 'name': val.name, 'score': val.score, 'is_vp': val.is_vp, 'review_date': val.review_date.strftime("%Y-%m-%d"), 'content': val.content, 'review_link': val.review_link, 'created': val.created.strftime("%Y-%m-%d"), } data.append(re) fields = [ 'Title', 'Variation', 'Asin', 'Name', 'Score', 'VP', 'Review Date', 'Content', 'Review Link', 'Created' ] data_fields = [ 'title', 'variation', 'asin', 'name', 'score', 'is_vp', 'review_date', 'content', 'review_link', 'created' ] return get_excel_file(self, data, fields, data_fields)
def export_qa(self): user = App.get_user_info(self) if not user: return HttpResponseRedirect("/admin/maxlead_site/login/") asin = self.GET.get('qa_asin', '') qa_max = Questions.objects.filter(asin=asin).aggregate(Max('created')) if not qa_max or not qa_max['created__max']: qa_max = Questions.objects.aggregate(Max('created')) question = Questions.objects.filter( asin=asin, created__icontains=qa_max['created__max'].strftime("%Y-%m-%d")) if not question: return HttpResponseRedirect("") data = [] for q in question: answer = Answers.objects.filter(question_id=q.id) if answer: for val in answer: re = { 'question': val.question.question, 'asin': val.question.asin, 'asked': val.question.asked, 'votes': val.question.votes, 'answer': val.answer, 'person': val.person, 'created': val.created.strftime("%Y-%m-%d %H:%M:%S") } data.append(re) else: re = { 'question': q.question, 'asin': q.asin, 'asked': q.asked, 'votes': q.votes, 'answer': '', 'person': '', 'created': q.created.strftime("%Y-%m-%d %H:%M:%S") } data.append(re) fields = [ 'Question', 'Asin', 'Asked', 'Votes', 'Answer', 'Answerer', 'Create Date' ] data_fields = [ 'question', 'asin', 'asked', 'votes', 'answer', 'person', 'created' ] return get_excel_file(self, data, fields, data_fields)
def export_radar(self): user = App.get_user_info(self) if not user: return HttpResponseRedirect("/admin/maxlead_site/login/") viewRange = self.GET.get('viewRange', '') asins = Dashboard._get_asins(self, user, ownership='Others',user_id=viewRange) res = Dashboard._get_activity_radar(self, asins,param=self.GET) if not self.GET.get('actBgn','') and not self.GET.get('actEnd',''): res = res[0:6] data = [] if res: for val in res: re = { 'asin': val.asin, 'title': val.title, 'price': val.price, 'feature': val.feature, 'description': val.description, 'image_date': val.image_date.strftime('%Y-%m-%d'), 'image_names': val.image_thumbs, 'created': val.created, 'changed': val.changed, 'buy_box_res': val.buy_box_res } data.append(re) fields = [ 'Image Thumbs', 'Title', 'Asin', 'Price', 'Changed', 'Feature', 'Description', 'Image Date', 'Buy Box', 'Created' ] data_fields = [ 'image_names', 'title', 'asin', 'price', 'changed', 'feature', 'description', 'image_date', 'buy_box_res', 'created' ] return get_excel_file(self, data, fields, data_fields)
def export_k_rank(self): user = App.get_user_info(self) if not user: return HttpResponseRedirect("/admin/maxlead_site/login/") asin = self.GET.get('asin', '') krStartDate = self.GET.get('krStartDate', datetime.datetime.now().strftime("%Y-%m-1")) krEndDate = self.GET.get('krEndDate', datetime.datetime.now().strftime("%Y-%m-%d")) kwdCat = self.GET.get('kwdCat', '') ranks = CategoryRank.objects.filter(asin=asin, user_asin=asin) if kwdCat: ranks = ranks.filter(cat__icontains=kwdCat) if krStartDate: ranks = ranks.filter(created__gte=krStartDate) if krEndDate: ranks = ranks.filter(created__lte=krEndDate) data = [] for v in ranks: re = { 'asin': v.asin, 'cat': v.cat, 'keywords': v.keywords, 'rank': v.rank, 'is_ad': v.is_ad, 'created': v.created.strftime("%Y-%m-%d %H:%M:%S"), } data.append(re) fields = [ 'Asin', 'Cat', 'Keywords', 'Rank', 'AD', 'Created', ] data_fields = [ 'asin', 'cat', 'keywords', 'rank', 'is_ad', 'created', ] if data: return get_excel_file(self, data, fields, data_fields)
def export_shuttle(self): user = App.get_user_info(self) if not user: return HttpResponseRedirect("/admin/maxlead_site/login/") asin = self.GET.get('shuttle_asin', '') tsStartDate = self.GET.get('tsStartDate', '') tsEndDate = self.GET.get('tsEndDate', '') listing = Listings.objects.filter(asin=asin).order_by('-created') if tsStartDate: listing = listing.filter(created__gte=tsStartDate) if tsEndDate: listing = listing.filter(created__gte=tsEndDate) data = [] for v in listing: re = { 'image_names': v.image_thumbs, 'title': v.title, 'asin': v.asin, 'sku': v.sku, 'description': v.description, 'feature': v.feature, 'buy_box': v.buy_box, 'price': v.price, 'total_review': v.total_review, 'total_qa': v.total_qa, 'rvw_score': v.rvw_score, 'category_rank': v.category_rank, 'inventory': v.inventory, 'last_check': v.user_asin.last_check.strftime("%Y-%m-%d %H:%M:%S"), 'created': v.created.strftime("%Y-%m-%d %H:%M:%S"), 'image_date': v.image_date.strftime("%Y-%m-%d"), } data.append(re) fields = [ 'Image Names', 'Ttile', 'Asin', 'SKU', 'Description', 'Feature', 'Buy Box', 'Price', 'Total Review', 'Total Qa', 'Rvw Score', 'Category Rank', 'Inventory', 'Last Check', 'Created', 'Image Date' ] data_fields = [ 'title', 'asin', 'sku', 'description', 'feature', 'buy_box', 'price', 'total_review', 'total_qa', 'rvw_score', 'category_rank', 'inventory', 'last_check', 'created', 'image_date' ] return get_excel_file(self, data, fields, data_fields)
def tmp_export(request): user = App.get_user_info(request) if not user: return HttpResponseRedirect("/admin/max_stock/login/") keywords = request.GET.get('keywords', '').replace('amp;', '') send_time = request.GET.get('send_time', '') order_status = request.GET.get('order_status', '') list = EmailTemplates.objects.filter(customer_num=user.menu_child_type) if not user.user.is_superuser: list = list.filter(user_id=user.user.id) if keywords: list = list.filter( Q(sku__contains=keywords) | Q(title__contains=keywords) | Q(content__contains=keywords)) if send_time: list = list.filter(send_time=send_time) if order_status: list = list.filter(order_status=order_status) data = [] if list: for val in list: re = { 'sku': val.sku, 'keywords': val.keywords, 'title': val.title, 'content': val.content, 'order_status': val.order_status, 'send_time': val.send_time, 'created': '' } data.append(re) fields = [ 'SKU', 'Keywords', 'Title', 'Content', 'Order Status', 'Send Time', 'Created' ] data_fields = [ 'sku', 'keywords', 'title', 'content', 'order_status', 'send_time', 'created' ] return get_excel_file(request, data, fields, data_fields) else: return HttpResponse('没有数据~~')
def ajax_export(self): user = App.get_user_info(self) if not user: return HttpResponse(json.dumps({ 'code': 0, 'msg': u'用户未登录!' }), content_type='application/json') data = eval(self.POST.get('data')) fields = [ 'Image Thumbs', 'Title', 'Asin', 'Sku', 'Brand', 'Price', 'Total Review', 'Rvw Ecore', 'Category Rank', 'Buy Box', 'Status', 'Review Watcher', 'Listing Watcher', 'Last Check' ] data_fields = [ 'title', 'asin', 'sku', 'brand', 'price', 'total_review', 'rvw_score', 'category_rank', 'buy_box', 'status', 'review_watcher', 'listing_watcher', 'last_check' ] return get_excel_file(self, data, fields, data_fields)
def export_stocks(request): user = App.get_user_info(request) if not user: return HttpResponseRedirect("/admin/max_stock/login/") keywords = request.GET.get('keywords', '').replace('amp;', '') warehouse = request.GET.get('warehouse', '') sel_new = request.GET.get('sel_new', '') stocks = WarehouseStocks.objects.all() if not user.user.is_superuser and not user.stocks_role == 66: skus = SkuUsers.objects.filter(user_id=user.user.id).values_list('sku') stocks = stocks.filter(sku__in=skus) if keywords: stocks = stocks.filter(sku__contains=keywords) if warehouse: stocks = stocks.filter(warehouse=warehouse) if not sel_new: sel_new = 0 stocks = stocks.filter(is_new=sel_new) stocks = stocks.values('sku', 'warehouse').annotate(count=Count('sku'), count2=Count('warehouse')) data = [] if stocks: for val in stocks: qty = WarehouseStocks.objects.filter(sku=val['sku'], warehouse=val['warehouse'], is_new=sel_new) if qty: re = { 'sku': val['sku'], 'warehouse': val['warehouse'], 'qty': qty[0].qty, 'created': qty[0].created.strftime("%Y-%m-%d %H:%M:%S"), } data.append(re) fields = ['SKU', 'Warehouse', 'QTY', 'Created'] data_fields = ['sku', 'warehouse', 'qty', 'created'] return get_excel_file(request, data, fields, data_fields) else: return HttpResponse('没有数据~~')
def export_stemp(request): user = App.get_user_info(request) if not user: return HttpResponseRedirect("/admin/maxlead_site/login/") keywords = request.GET.get('keywords', '') res = SfpTemps.objects.all() if keywords: res = res.filter(Q(sfp_temp__contains=keywords) | Q(warehouse__contains=keywords)) data = [] for val in res: re = { 'sfp_temp':val.sfp_temp, 'warehouse':val.warehouse, 'inactive':val.inactive, 'user':val.user.username, 'created':val.created.strftime("%Y-%m-%d %H:%M:%S") } data.append(re) fields = [ 'SFP Template', 'Warehouse', 'Inactive', 'User', 'Date' ] data_fields = [ 'sfp_temp', 'warehouse', 'inactive', 'user', 'created' ] return get_excel_file(request, data, fields, data_fields)
def export_reviews(self): user = App.get_user_info(self) if not user: return HttpResponseRedirect("/admin/maxlead_site/login/") asin = self.GET.get('review_asin', '') is_vp = self.GET.get('is_vp', '') score = self.GET.get('score', '') rvKwd = self.GET.get('rvKwd', '') end_date = self.GET.get('end_date', '') start_date = self.GET.get('start_date', '') words = self.GET.get('words', '') review_max = Reviews.objects.filter(asin=asin).aggregate( Max('created')) if not review_max or not review_max['created__max']: review_max = Reviews.objects.aggregate(Max('created')) review = Reviews.objects.filter( asin=asin, created__icontains=review_max['created__max'].strftime( "%Y-%m-%d")).all() if is_vp: review = review.filter(is_vp=is_vp) if score and not score == 'positive' and not score == 'critical': review = review.filter(score=score) if score == 'positive': review = review.filter(score__gt=3) if score == 'critical': review = review.filter(score__lte=3) if rvKwd: review = review.filter(content__icontains=rvKwd) if words: review = review.filter(content__icontains=words) if end_date: review = review.filter(review_date__lte=end_date) if start_date: review = review.filter(review_date__gte=start_date) a_max = AsinReviews.objects.filter(aid=asin).aggregate(Max('created')) if not a_max or not a_max['created__max']: a_max = AsinReviews.objects.aggregate(Max('created')) asinreview = AsinReviews.objects.filter( aid=asin, created__icontains=a_max['created__max'].strftime( "%Y-%m-%d")).all() asinreviews = get_review_keywords(review) positive_keywords = '' negative_keywords = '' if asinreviews['positive_keywords']: for val in asinreviews['positive_keywords']: positive_keywords += val['words'] + ',' if asinreviews['negative_keywords']: for val in asinreviews['negative_keywords']: negative_keywords += val['words'] + ',' data = [] for val in review: re = { 'title': val.title, 'variation': val.variation, 'asin': val.asin, 'name': val.name, 'score': val.score, 'avg_score': asinreview[0].avg_score, 'is_vp': val.is_vp, 'review_date': val.review_date.strftime("%Y-%m-%d"), 'content': val.content, 'positive_keywords': positive_keywords, 'negative_keywords': negative_keywords, 'total_review': asinreview[0].total_review, 'review_link': val.review_link, 'created': val.created.strftime("%Y-%m-%d"), } data.append(re) fields = [ 'Title', 'Variation', 'Asin', 'Name', 'Score', 'Avg Score', 'VP', 'Review Date', 'Content', 'Positive Keywords', 'Negative Keywords', 'Total Review', 'Review Link', 'Created' ] data_fields = [ 'title', 'variation', 'asin', 'name', 'score', 'avg_score', 'is_vp', 'review_date', 'content', 'positive_keywords', 'negative_keywords', 'total_review', 'review_link', 'created' ] return get_excel_file(self, data, fields, data_fields)
def export_watcher(self): user = App.get_user_info(self) if not user: return HttpResponse(json.dumps({ 'code': 0, 'msg': '用户未登录' }), content_type='application/json') listBgn = self.GET.get('listBgn', '') listEnd = self.GET.get('listEnd', '') viewRange = self.GET.get('viewRange', '') asins = Dashboard._get_asins(self, user, listing_watcher=1, user_id=viewRange) listing_watchers = [] listing_watchers = ListingWacher.objects.filter(asin__in=asins) if not listEnd and not listBgn: listing_watchers_max = ListingWacher.objects.aggregate( Max('created')) listing_watchers = listing_watchers.filter( created__icontains=listing_watchers_max['created__max']. strftime("%Y-%m-%d")) if listEnd: listing_watchers = listing_watchers.filter(created__lte=listEnd) if listBgn: listing_watchers = listing_watchers.filter(created__gte=listBgn) if listing_watchers: listing_watchers = listing_watchers if not listBgn and not listEnd: listing_watchers = listing_watchers[0:6] data = [] for val in listing_watchers: if val.price: price = val.price else: price = '' if val.fba: fba = 'FBA' else: fba = 'FBM' if val.prime: prime = 'Prime' else: prime = '' if val.shipping: shipping = val.shipping else: shipping = '' if val.winner: winner = 'Buy box winner' else: winner = 'not winner' re = { 'created': val.created.strftime('%Y-%m-%d %H:%M:%S'), 'seller_link': val.seller_link, 'asin': val.asin, 'seller': val.seller, 'price': price, 'fba': fba, 'prime': prime, 'shipping': shipping, 'winner': winner, } data.append(re) fields = [ 'Asin', 'Seller', 'Price', 'FBA', 'Prime', 'Shipping', 'Winner', 'Seller Link', 'Created', ] data_fields = [ 'asin', 'seller', 'price', 'fba', 'prime', 'shipping', 'winner', 'seller_link', 'created', ] return get_excel_file(self, data, fields, data_fields)
def tracking_orders_export(request): user = App.get_user_info(request) if not user: return HttpResponseRedirect("/admin/max_stock/login/") keywords = request.GET.get('keywords', '').replace('amp;', '') billing_date = request.GET.get('billing_date', '') if not billing_date: billing_date = (datetime.datetime.now() + datetime.timedelta(days=-5)).strftime("%Y-%m-%d") if user.user.is_superuser or user.stocks_role == '66': lists = TrackingOrders.objects.all() else: lists = TrackingOrders.objects.filter(user_id=user.user_id) if keywords: lists = lists.filter( Q(order_num__contains=keywords) | Q(tracking_num__contains=keywords)) if billing_date: lists = lists.filter(billing_date__gt=billing_date) data = [] if lists: for val in lists: first_scan_time = '' delivery_time = '' if val.first_scan_time: first_scan_time = val.first_scan_time.strftime( "%Y-%m-%d %H:%M:%S") if val.delivery_time: delivery_time = val.delivery_time.strftime("%Y-%m-%d %H:%M:%S") data.append({ 'order_num': val.order_num, 'tracking_num': val.tracking_num, 'warehouse': val.warehouse, 'account_num': val.account_num, 'description': val.description, 'status': val.status, 'shipment_late': val.shipment_late, 'delivery_late': val.delivery_late, 'billing_date': val.billing_date.strftime('%b.%d'), 'latest_ship_date': val.latest_ship_date, 'latest_delivery_date': val.latest_delivery_date, 'first_scan_time': first_scan_time, 'delivery_time': delivery_time }) fields = [ '发货单时间', '账号', 'OrderNumber', 'WarehouseName', 'Description', 'Tracking Numbers', 'latest-ship-date', 'latest-delivery-date', 'Status', 'First Scan time', 'Delivery time', 'Shipment Late', 'Delivery Late' ] data_fields = [ 'billing_date', 'account_num', 'order_num', 'warehouse', 'description', 'tracking_num', 'latest_ship_date', 'latest_delivery_date', 'status', 'first_scan_time', 'delivery_time', 'shipment_late', 'delivery_late' ] return get_excel_file(request, data, fields, data_fields) else: return HttpResponse('没有数据~~')