def _get_absolute_url(self, path_only=False): """ Return absolute url or url path. """ if self.is_homepage: return get_absolute_url('cubane.cms.page', [''], path_only=path_only) else: slug = normalise_slug(self.slug) if settings.APPEND_SLASH: slug = slug + '/' return get_absolute_url('cubane.cms.page', [slug], path_only=path_only)
def get_mail_order_context(request, order, customer=True, extras=None): context = { 'request': request, 'settings': request.settings, 'CURRENCY': settings.CURRENCY, 'is_customer': customer, 'order': order, 'order_url': make_absolute_url(order.get_absolute_url(), https=True), 'order_products': order.basket.items, 'order_totals': order.basket.totals, 'DOMAIN_NAME': 'http://%s' % settings.DOMAIN_NAME, 'backend_order_url': get_absolute_url('cubane.ishop.orders.edit', args=[order.id], https=True) } if extras: context.update(extras) return context
def password_forgotten(self, request, email): """ Generate a new password for the given user and send the new password by email. """ try: user = User.objects.get(email=email.lower().strip()) password_plaintext = get_pronounceable_password() user.set_password(password_plaintext) user.save() from cubane.cms.views import get_cms cms = get_cms() cubane_send_shop_mail( request, email, '%s | New Password Request' % cms.settings.name, { 'password_reset': True, 'customer': user, 'password_plaintext': password_plaintext, 'login_url': get_absolute_url('shop.account.login', https=True) }) return True except User.DoesNotExist: return False
def _get_absolute_url(self, path_only=False): """ Return absolute url or url path. """ parent = self.page if parent: if parent.is_homepage: parent_slug = '/' else: parent_slug = parent.slug slug = normalise_slug(url_join(parent_slug, self.slug)) if settings.APPEND_SLASH: slug = slug + '/' return get_absolute_url('cubane.cms.page', [slug], path_only=path_only) else: return None
def process_payment(request, gateway, transaction_id): """ Process payment information for the order with the given transaction id. """ # if the payment gateway returns no transaction id, # we consider this as an error. if transaction_id == None: mail_error( 'Payment gateway %s was unable to identify transaction id based on the payment response %s.' % (gateway, request)) return gateway.payment_response(request, PaymentGateway.RESPONSE_ERROR, None, None) # get order based on transaction id order_model = get_order_model() try: order = order_model.objects.get(transaction_id=transaction_id) registration_context = RegistrationContext(order.transaction_id, order.payment_details) except order_model.DoesNotExist: # unable to identify correct order. return HttpResponse('', content_type='text/plain') # let the payment gateway determine the success of the payment # based on the response... payment_status = gateway.payment_accept(request, order, registration_context) # translate payment gateway payment status to system state if payment_status == PaymentGateway.STATUS_PAYMENT_CONFIRMED: if order.preauth: order.approval_status = OrderBase.APPROVAL_STATUS_WAITING else: order.approval_status = OrderBase.APPROVAL_STATUS_NONE order.status = OrderBase.STATUS_PAYMENT_CONFIRMED order.payment_confirmed_at = datetime.datetime.now() order.save() elif payment_status == PaymentGateway.STATUS_PAYMENT_DECLINED: order.status = OrderBase.STATUS_PAYMENT_DECLINED order.save() elif payment_status == PaymentGateway.STATUS_PENDING: order.status = OrderBase.STATUS_PENDING order.save() elif payment_status == PaymentGateway.STATUS_PAYMENT_ERROR: order.status = OrderBase.STATUS_PAYMENT_ERROR order.save() mail_error('Payment error (gateway %s): %s' % (gateway.__class__.__name__, gateway.message)) else: order.status = OrderBase.STATUS_PAYMENT_ERROR order.save() mail_error( 'Received unknown payment response for order %s from gateway %s. Gateway message = %s' % (order.id, gateway.__class__.__name__, gateway.message)) # send out emails and order/shipping notes generate_emails_and_notes(request, order) # send success back to payment gateway (this does not neccessarily # mean that the actual payment was successful)... if order.is_backend_payment: next_url = '%s?pk=%s' % (get_absolute_url('cubane.ishop.orders.edit'), order.pk) else: next_url = get_absolute_url('shop.order.status', args=[order.secret_id]) return gateway.payment_response(request, PaymentGateway.RESPONSE_SUCCESS, order, registration_context, next_url)
def get_response_url(self, request): """ Return the payment response url used for this gateway. """ return get_absolute_url('shop.order.payment_response', args=[self._identifier])
def inventory_import(self, request): """ Shop Inventory Import (CSV). """ # default encoding initial = {'encoding': get_cms_settings().default_encoding} if request.method == 'POST': form = ShopInventoryImportForm(request.POST, request.FILES) else: form = ShopInventoryImportForm(initial=initial) form.configure(request) export_form = ShopInventoryExportForm(initial=initial) export_form.configure(request) if request.method == 'POST' and form.is_valid(): d = form.cleaned_data # create importer and import date importer = ShopInventoryImporter() importer.import_from_stream(request, request.FILES['csvfile'], encoding=d.get('encoding')) # present information what happend during import if importer.has_errors: transaction.rollback() errors = importer.get_formatted_errors() messages.add_message( request, messages.ERROR, ('Import failed due to %s. No data ' + 'has been imported. Please correct all issues ' + 'and try again.') % pluralize(len(errors), 'error', tag='em')) for message in errors: messages.add_message(request, messages.ERROR, message) # redirect to itself if we have errors return HttpResponseRedirect( get_absolute_url( 'cubane.ishop.inventory.inventory_import')) else: # success message, render image processing page messages.add_message( request, messages.SUCCESS, pluralize(importer.num_records_processed, 'record', 'processed successfully', tag='em')) # redirect to itself if we have errors return HttpResponseRedirect( get_absolute_url( 'cubane.ishop.inventory.inventory_import')) return { 'form': form, 'export_form': export_form, 'export_form_action': reverse('cubane.ishop.inventory.inventory_export') }
def old_data_importer(self, request): """ Import Form. """ if request.method == 'POST': form = ShopDataImportForm(request.POST, request.FILES) else: form = ShopDataImportForm() form.configure(request) export_form = ShopInventoryExportForm() export_form.configure(request) if request.method == 'POST' and form.is_valid(): d = form.cleaned_data # load data importer import_classname = settings.CUBANE_SHOP_IMPORT.get( 'importer', 'cubane.ishop.apps.merchant.dataimport.importer.ShopDataImporter' ) import_class = get_class_from_string(import_classname) # create importer and start importing... importer = import_class(import_images=d.get('import_images')) importer.import_from_stream(request, request.FILES['csvfile'], encoding=d.get('encoding')) # present information what happend during import if importer.has_errors: transaction.rollback() errors = importer.get_formatted_errors() messages.add_message( request, messages.ERROR, ('Import failed due to %s. No data ' + 'has been imported. Please correct all issues ' + 'and try again.') % pluralize(len(errors), 'error', tag='em')) for message in errors: messages.add_message(request, messages.ERROR, message) # redirect to itself if we have errors return HttpResponseRedirect( get_absolute_url('cubane.ishop.dataimport.index')) else: # success message, render image processing page messages.add_message( request, messages.SUCCESS, pluralize(importer.num_records_processed, 'record', 'processed successfully', tag='em')) # redirect to itself if we have errors return HttpResponseRedirect( get_absolute_url('cubane.ishop.dataimport.index')) return {'form': form, 'export_form': export_form}