def createBid(request, *args, **kwargs): if kwargs.get('pk'): initParam = {} app = get_object_or_404(appModels.App, pk=kwargs.get('pk')) initParam['app'] = app initParam['appInfo'] = app.appinfo initBidInfo(request, app=app, initParam=initParam) #For below code using the value #Do something, when the time is app end date. if app.status == 2 and initParam['begin_bid']: initParam['is_callback'] = True if request.method == "POST": biddingForm = forms.BiddingForm(request.POST) #Buyer credit point judge for bidding. min_cp = common.getSystemParam(key='min_cp_for_bid', default=50) cp = creditViews.getUserCreditPoint(user=request.user) if cp == -1 or cp < string.atoi(min_cp): initParam['biddingForm'] = biddingForm initParam['bid_error'] = _( 'You are not allowed to place bid, because your low credit points. But you can buy additional credit points.' ) else: if biddingForm.is_valid(): #From bid_create.html if 'yes' == request.POST.get('bid_create'): bid = biddingForm.save(commit=False) if datetime.datetime.now() > app.end_date: initParam['biddingForm'] = biddingForm initParam['bid_error'] = _( 'The bidding is closed, you can not bid.') elif bid.price >= initParam.get('bid_price'): bid.app = app bid.buyer = request.user bid.status = 1 # userPrivateItem = userSettingModels.UserPrivateItem.objects.filter(key='is_bid_approved') # if userPrivateItem: # is_bid_approved = userSettingModels.UserPrivateSetting.objects.filter(user_id=app.publisher.id, user_private_item_id=userPrivateItem[0]) # #Need be verified by app publisher. # if is_bid_approved and is_bid_approved[0].value == 'True': # bid.status = 3 bid.save() #Send the message to app publisher send_message = request.POST.get('send_message') if send_message and send_message == 'yes': if sendMessage(request, initParam=initParam): notificationViews.sendNewBidEmail(request, bid=bid, app=app) return redirect( reverse('bid:bid_list', kwargs={'pk': app.id})) else: initParam['biddingForm'] = biddingForm initParam['bid_error'] = initParam[ 'message_error'] else: notificationViews.sendNewBidEmail(request, bid=bid, app=app) return redirect( reverse('bid:bid_list', kwargs={'pk': app.id})) else: initParam['biddingForm'] = biddingForm initParam['bid_error'] = _( 'The new bid has been submitted.') #From list_detail.html else: initParam['biddingForm'] = biddingForm initParam['sender'] = request.user initParam['receiver'] = app.publisher transactions = txnModels.Transaction.objects.filter( app_id=app.id).exclude(status=1) if transactions: initParam['transaction'] = transactions[0] #Comment the message # sendMessage(request, initParam=initParam) queryViews.shareSocial(request, initParam=initParam, app=app) return render_to_response('bid/bid_create.html', initParam, context_instance=RequestContext(request)) raise Http404
def createBid(request, *args, **kwargs): if kwargs.get('pk'): initParam = {} app = get_object_or_404(appModels.App, pk=kwargs.get('pk')) initParam['app'] = app initParam['appInfo'] = app.appinfo initBidInfo(request, app=app, initParam=initParam)#For below code using the value #Do something, when the time is app end date. if app.status == 2 and initParam['begin_bid']: initParam['is_callback'] = True if request.method == "POST": biddingForm = forms.BiddingForm(request.POST) #Buyer credit point judge for bidding. min_cp = common.getSystemParam(key='min_cp_for_bid', default=50) cp = creditViews.getUserCreditPoint(user=request.user) if cp == -1 or cp < string.atoi(min_cp): initParam['biddingForm'] = biddingForm initParam['bid_error'] = _('You are not allowed to place bid, because your low credit points. But you can buy additional credit points.') else: if biddingForm.is_valid(): #From bid_create.html if 'yes' == request.POST.get('bid_create'): bid = biddingForm.save(commit=False) if datetime.datetime.now() > app.end_date: initParam['biddingForm'] = biddingForm initParam['bid_error'] = _('The bidding is closed, you can not bid.') elif bid.price >= initParam.get('bid_price'): bid.app = app bid.buyer = request.user bid.status = 1 # userPrivateItem = userSettingModels.UserPrivateItem.objects.filter(key='is_bid_approved') # if userPrivateItem: # is_bid_approved = userSettingModels.UserPrivateSetting.objects.filter(user_id=app.publisher.id, user_private_item_id=userPrivateItem[0]) # #Need be verified by app publisher. # if is_bid_approved and is_bid_approved[0].value == 'True': # bid.status = 3 bid.save() #Send the message to app publisher send_message = request.POST.get('send_message') if send_message and send_message == 'yes': if sendMessage(request, initParam=initParam): notificationViews.sendNewBidEmail(request, bid=bid, app=app) return redirect(reverse('bid:bid_list', kwargs={'pk': app.id})) else: initParam['biddingForm'] = biddingForm initParam['bid_error'] = initParam['message_error'] else: notificationViews.sendNewBidEmail(request, bid=bid, app=app) return redirect(reverse('bid:bid_list', kwargs={'pk': app.id})) else: initParam['biddingForm'] = biddingForm initParam['bid_error'] = _('The new bid has been submitted.') #From list_detail.html else: initParam['biddingForm'] = biddingForm initParam['sender'] = request.user initParam['receiver'] = app.publisher transactions = txnModels.Transaction.objects.filter(app_id=app.id).exclude(status=1) if transactions: initParam['transaction'] = transactions[0] #Comment the message # sendMessage(request, initParam=initParam) queryViews.shareSocial(request, initParam=initParam, app=app) return render_to_response('bid/bid_create.html', initParam, context_instance=RequestContext(request)) raise Http404
def createMessage(request, *args, **kwargs): """User from inbox page, send messages page and app detail page, reply or send message.""" initParam = {} username = kwargs.get("username") user_id = kwargs.get("user_id") type = kwargs.get("type", 1) msg_id = kwargs.get("msg_id") msg_action = kwargs.get("msg_action") if msg_action and (msg_action == "reply" or msg_action == "send"): initParam["msg_action"] = msg_action else: raise Http404 user = get_object_or_404(User, pk=request.user.id, username=request.user.username) receiver = get_object_or_404(User, pk=user_id, username=username) if msg_id: if msg_action == "reply": message = get_object_or_404(messageModels.Message, pk=msg_id, sender_id=receiver.id, receiver_id=user.id) if msg_action == "send": message = get_object_or_404(messageModels.Message, pk=msg_id, sender_id=user.id, receiver_id=receiver.id) initParam["msg_id"] = message.id initParam["sender"] = user initParam["receiver"] = receiver initParam["type"] = type initParam["next"] = request.GET.get("next", None) initParam["page"] = request.GET.get("page", 1) initParam["attachmentForm"] = messageForms.AttachmentForm() attachmentSize = string.atof(common.getSystemParam(key="attachment_size", default=50000000)) initParam["attachmentSize"] = attachmentSize / 1000000 message = messageViews.sendMessage(request, initParam=initParam) if message: messages.info(request, _("Send message successfully.")) # For job, log number of apply the job. if initParam["type"] == "6" and initParam["next"] is not None: offerId = initParam["next"].split("/")[3] offers = offerModels.Offer.objects.filter(pk=offerId, publisher_id=user_id) if offers: offerRecord = offers[0].offerrecord if offerRecord is not None: offerRecord.apply_count += 1 else: offerRecord = offerModels.OfferRecord() offerRecord.offer = offers[0] offerRecord.view_count = 0 offerRecord.apply_count = 1 offerRecord.save() pathList = request.FILES.getlist("path") if pathList: maxNum = common.getSystemParam(key="max_num_attachment", default=50) attachments = messageModels.Attachment.objects.filter(message_id=message.id) if len(pathList) + len(attachments) > string.atoi(maxNum): initParam["attachmentError"] = _("The attachment number can not be more than %(number)s.") % { "number": maxNum[0].value } return render_to_response( "dashboard/create_message.html", initParam, context_instance=RequestContext(request) ) for path in pathList: attachment = messageModels.Attachment(path=path) attachment.name = path.name if path.name.endswith(".txt") and path.content_type == "text/plain": attachment.type = 1 elif path.content_type.startswith("image"): attachment.type = 2 elif path.name.endswith(".pdf") and path.content_type == "application/pdf": attachment.type = 3 elif path.name.endswith(".doc") and path.content_type == "application/msword": attachment.type = 4 elif ( path.name.endswith(".docx") and path.content_type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ): attachment.type = 4 elif path.name.endswith(".xls") and path.content_type == "application/vnd.ms-excel": attachment.type = 4 elif ( path.name.endswith(".xlsx") and path.content_type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ): attachment.type = 4 elif path.name.endswith(".ppt") and path.content_type == "application/vnd.ms-powerpoint": attachment.type = 4 elif ( path.name.endswith(".pptx") and path.content_type == "application/vnd.openxmlformats-officedocument.presentationml.presentation" ): attachment.type = 4 else: initParam["attachmentError"] = _("The file type of %(param)s does not supported.") % { "param": path.name } return render_to_response( "dashboard/create_message.html", initParam, context_instance=RequestContext(request) ) if path.size > attachmentSize: initParam["attachmentError"] = _("The file can not be more than %(number)M.") % { "number": attachmentSize / 000000 } return render_to_response( "dashboard/create_message.html", initParam, context_instance=RequestContext(request) ) attachment.message = message attachment.save() notificationViews.sendNewMessageEmail(request, message=message) return redirect(reverse("dashboard:sent_messages")) return render_to_response("dashboard/create_message.html", initParam, context_instance=RequestContext(request))