def approve_account_action(modeladmin, request, queryset): for user_profile in queryset: UserProfile.objects.filter(pk=user_profile.pk).update(approved=True) render_and_send_mail ( "Welcome to our community!", { "site" : user_profile.site, "username" : user_profile.user.username, "vendor" : user_profile.vendor, "buyer" : user_profile.buyer, }, "%s_welcome_to_foodem" % ("vendor" if user_profile.isVendor() else "buyer"), [user_profile.user.email] )
def contactterms(request, termsId): terms = Terms.objects.get(pk=termsId) status = 0 message = "" try: terms = Terms.objects.get(pk=termsId) message = request.POST['message'] mode = "buyer" if request.user.get_profile().isBuyer() else "vendor" sender_name = terms.buyer.name if mode == "buyer" else terms.vendor.name name = terms.vendor.userprofile.company_name if mode == "buyer" \ else terms.buyer.userprofile.company_name render_and_send_mail( "%s has a message for you about a terms request." % sender_name, { "mode" : mode, "message" : message, "sender_name" : sender_name, "terms" : terms, "name" : name, }, "terms_contact", [ terms.vendor.userprofile.user.email if mode == "buyer" \ else terms.buyer.userprofile.user.email ], ) status = 1 except Exception as e: message = ("%s" % e).strip() return HttpResponse( json.dumps({ "status" : status, "message" : message, }), mimetype="application/json" )
def ql_confirm(request, parts, ql_object): o = Order.objects.get( uniqueId = parts[1], buyer = ql_object.user ) error_message = "" try: o.confirm_and_pay() # NOTE: Functionality duplicated in Order.views.ajax_modify() render_and_send_mail( "%s has confirmed Order %s" % (o.buyer.get_profile().buyer.name, o.uniqueId), {"order":o}, "order_confirmed_by_buyer", [o.vendor.userprofile.user.email], ) except Exception as error_message: pass ql_object.delete() return render_to_response( "quick/confirm", { "order" : o, "error_message" : ("%s" % error_message).strip() }, context_instance=RequestContext(request) )
def handle(self, *args, **options): lqis = ListingQueuedImage.objects.filter(processing=False) self.stdout.write('Processing download of %s image%s ...\n' % ( lqis.count(), "s" if lqis.count() != 1 else "" )) results = {} names = {} successes = {} failures = {} for lqi in lqis: # Flag the queued image for processing ListingQueuedImage.objects.filter(pk=lqi.pk).update(processing=True) # Initialize necessities v = lqi.listing.vendor if v.pk not in results.keys(): results[v.pk] = { 'name' : v.name, 'email' : v.email, 'successes' : 0, 'errors' : [] } try: file = urllib.urlretrieve(lqi.url) filename = ("%s.jpg" % ( ".".join( lqi.url .split('?')[0] .split('/')[-1] .split('.')[0:-1] ) or "unnamed-image" )).strip() if lqi.listing.product_image: lqi.listing.product_image.delete() lqi.listing.product_image.save(filename, File(open(file[0]))) lqi.listing.save() lqi.listing.set_product_image() lqi.delete() results[v.pk]['successes'] += 1 except Exception as e: import sys results[v.pk]['errors'].append({ 'listing' : lqi.listing, 'error' : "%s" % smart_text(e) }) for v_pk, context in results.items(): render_and_send_mail( "Results of image downloads for bulk item upload", context, "download_product_images_results", [context['email']] )
def grant_terms(request, buyer_id, net): buyer = Buyer.objects.get(pk=buyer_id) vendor = request.user.get_profile().vendor terms, created = Terms.objects.get_or_create(buyer=buyer, vendor=vendor) if not request.user.get_profile().current_cc: status = 0 message = 'You cannot accept credit terms as payment until you add a credit card to your account' net = 0 elif created or request.POST.get('overwrite','') == '1': oldstatus = None if created else int("%d" % terms.status) oldnet = 0 if created else int("%d" % terms.net) terms.status = 1 terms.net = net terms.save() if oldstatus != terms.status or oldnet != terms.net: # Need to update buyer vendor options to allow terms as payment method # Won't affect anything if the user is in a group, but it's something bvo = buyer.vendor_options(vendor)[0] bvo.allow_credit_terms = True if terms.status == 1 else False bvo.save() render_and_send_mail( "%s has %s credit terms" % ( terms.vendor.name, "approved your" if (terms.status == 1 and oldstatus == 0) else \ "updated your" if (terms.status == 1 and oldstatus == 1) else \ "reinstated your" if (terms.status == 1 and oldstatus == 3) else \ "granted you" if terms.status == 1 else \ "rejected your" if terms.status == 2 else \ "revoked your" if terms.status == 3 else \ "" # Should never happen ), {"terms":terms,"oldstatus":oldstatus}, "terms_change", [terms.buyer.userprofile.user.email] ) status = 1 message = '' net = terms.net elif terms: status = -1 message = '' net = terms.net else: status = 0 message = 'Unable to get or create terms' net = 0 response = { 'status' : status, 'message' : message, 'net' : net, } return HttpResponse(json.dumps(response), mimetype="application/json")
def update_status(request, termsId, status, net=None): try: action_status = 1 message = "" terms = Terms.objects.get(pk=termsId) vendor = request.user.get_profile().vendor affected_orders = 0 if vendor.pk != terms.vendor.pk: raise Exception("Only owner of terms can change the state of the terms") oldstatus = int("%d" % terms.status) oldnet = int("%d" % terms.net) if int(status) in (1,2,3): if int(status) == 1: if not request.user.get_profile().current_cc: raise Exception("You cannot accept credit terms as payment until you add a credit card to your account") if not net: raise Exception("Net days must be provided to approve these terms.") terms.net = net elif int(status) in [2, 3]: affected_orders = Order.objects.filter( vendor = vendor, buyer = terms.buyer, state = IN_PROGRESS, payment_option__in = [0,1] if vendor.require_credit_app_cod else [1] ).filter( Q(in_progress_state=AWAITING_BUYER_CONF) | Q(in_progress_state=AWAITING_VENDOR_CONF) ).count() terms.status = int(status) if request.method == "POST": terms.status_msg = request.POST.get('reason') if int(status) in [2, 3]: terms.allow_early_resubmit = True if ("%s" % request.POST.get('allow_resubmit')) == "1" else False else: terms.allow_early_resubmit = False else: terms.status_msg = '' terms.save() if ( (oldstatus != terms.status or oldnet != terms.net) and ("%s" % request.POST.get('skip_email')) != "1" ): render_and_send_mail( "%s has %s credit terms" % ( terms.vendor.name, "approved your" if (terms.status == 1 and oldstatus == 0) else \ "updated your" if (terms.status == 1 and oldstatus == 1) else \ "reinstated your" if (terms.status == 1 and oldstatus == 3) else \ "granted you" if terms.status == 1 else \ "rejected your" if terms.status == 2 else \ "revoked your" if terms.status == 3 else \ "" # Should never happen ), { "terms" : terms, "oldstatus" : oldstatus, "affected_orders" : affected_orders }, "terms_change", [terms.buyer.userprofile.user.email] ) except Exception as e: action_status = 0 message = "%s" % e response = { 'status' : action_status, 'message' : message, } return HttpResponse(json.dumps(response), mimetype="application/json")
def handle(self, *args, **options): to_email = [] now = datetime.now() day = now.day day_of_week = now.isoweekday() history = mongo_db.upload_reminder_logs.find_one({"date":"%s" % now.date()}) if not history or type(history) != list: history = [] else: history = history.get('history') vendors = Vendor.objects.filter( price_update_notification__in = ['daily','weekly','monthly'], userprofile__site = request.user.userprofile.site, userprofile__approved = True, userprofile__user__is_active = True ) if vendors.count() > 0: self.stdout.write("Sending %s vendor catalog upload reminder%s ...\n" % ( vendors.count(), "s" if vendors.count() != 1 else "" )) for vendor in vendors: n_type = vendor.price_update_notification val = ("%s" % vendor.price_update_value).strip().lower() if n_type == 'daily': if vendor.pk not in history: to_email.append(vendor) elif n_type == 'weekly': if (day_of_week == 1 and val == "monday") \ or (day_of_week == 2 and val == "tuesday") \ or (day_of_week == 3 and val == "wednesday") \ or (day_of_week == 4 and val == "thursday") \ or (day_of_week == 5 and val == "friday") \ or (day_of_week == 6 and val == "saturday") \ or (day_of_week == 7 and val == "sunday"): if vendor.pk not in history: to_email.append(vendor) elif n_type == 'monthly': if ("%s" % day).strip() == val and vendor.pk not in history: to_email.append(vendor) for vendor in to_email: try: render_and_send_mail( "%s price update reminder" % vendor.price_update_notification.title(), { "vendor" : vendor, "quick_link" : QuickLink( user = vendor.userprofile.user, command = "opt-out=%s=price_update_notification" % vendor.userprofile.user.pk ), }, "vendor_price_update_reminder", [vendor.email], ) history.append(vendor.pk) except Exception as e: pass mongo_db.upload_reminder_logs.update( { "date" : "%s" % now.date() }, { "date" : "%s" % now.date(), "history" : history }, True )