Exemple #1
0
    def handle(self, *args, **options):
        """
        Run command.
        """
        cms = get_cms()

        # remove any existing test page
        page = cms.get_page_by_slug('testpage')
        if page:
            page.delete()

        # find some image with high-enough res. or create a new test image
        try:
            img = Media.objects.filter(is_image=True, width__gte=200)[0]
        except IndexError:
            # create new test image
            img_path = os.path.join(settings.BASE_PATH, 'backend', 'static',
                                    'cubane', 'backend', 'img', 'logo.png')
            img = cms.create_media_from_file(path, 'Test Image for TestPage')

        # create new test page
        page = cms.create_page({
            'title': 'Test Page',
            'slug': 'testpage',
        })
        page.set_slot_content(
            cms.get_default_slotname(), self.CONTENT % {
                'img_url': img.original_url,
                'img_height': 200 / img.aspect_ratio,
                'img_id': img.pk
            })
        page.save()

        print 'Test page generated.'
        print make_absolute_url(page.get_absolute_url(), force_debug=True)
Exemple #2
0
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
Exemple #3
0
    def send_email(self,
                   request,
                   template,
                   url,
                   subject,
                   message,
                   reason=None):
        """
        Send an email to the customer with the given subject line and message. The email will also contain
        a unique link to prompt the user to perform the desired action, for example to change the password.
        """
        if 'cubane.cms' in settings.INSTALLED_APPS:
            from cubane.cms.views import get_cms
            cms = get_cms()

            if cms.settings.name:
                subject = '%s | %s' % (subject, cms.settings.name)
        else:
            cms = None

        cubane_send_mail_template(
            request, self.user.email, subject, template, {
                'message': message,
                'url': make_absolute_url(url),
                'reason': reason,
                'settings': cms.settings if cms else None
            })
Exemple #4
0
def current_url_with_args(context, **kwargs):
    """
    Return the current URL with all existing query arguments with the given
    query arguments added to the current URL.
    """
    request = value_or_none('request', context)
    if request:
        args = request.GET.copy()
        for k, v in kwargs.iteritems():
            if v is None:
                if k in args:
                    del args[k]
            else:
                args[k] = v

        if args:
            return make_absolute_url('%s?%s' %
                                     (request.path, args.urlencode()))
        else:
            return make_absolute_url(request.path)
    else:
        return ''
Exemple #5
0
    def share(self, request):
        # get media asset
        pk = request.GET.get('pk')
        media = get_object_or_404(Media, pk=pk)

        # create form
        if request.method == 'POST':
            form = MediaShareForm(request.POST)
        else:
            share_filename = media.share_filename
            if not share_filename:
                share_filename = media.filename

            form = MediaShareForm(
                initial={
                    'share_enabled': media.share_enabled,
                    'share_filename': share_filename
                })

        # configure form
        form.configure(request, instance=media, edit=True)

        # validate form
        if request.method == 'POST' and form.is_valid():
            d = form.cleaned_data

            if media.share_enabled != d.get(
                    'share_enabled') or media.share_filename != d.get(
                        'share_filename'):
                previous_instance = request.changelog.get_changes(media)

                media.share_enabled = d.get('share_enabled')
                media.share_filename = d.get('share_filename')
                media.save()

                request.changelog.edit(media, previous_instance)
                request.changelog.commit(
                    'File sharing %s: <em>%s</em>.' %
                    ('enabled' if media.share_enabled else 'disabled',
                     media.caption),
                    media,
                    flash=True)

            return self._redirect(request, 'index')

        return {
            'form': form,
            'media': media,
            'base_url': make_absolute_url(settings.MEDIA_DOWNLOAD_URL)
        }
Exemple #6
0
    def render(self, context):
        # resolve target (none, category or product)
        if self._target == None:
            target = None
        else:
            target = value_or_literal(self._target, context)
            if target == 'None': target = None

        # resolve sep
        request = value_or_none('request', context)
        sep = value_or_literal(self._sep, context)

        # build list of pages based on given target
        items = [('Home', '/')]
        if target == None:
            pass
        elif isinstance(target, str) or isinstance(target, unicode):
            # static page
            items.append((target, make_absolute_url(request.path)))
        elif isinstance(target, get_category_model()):
            # category page
            items.extend([(c.title, c.get_absolute_url()) for c in target.get_path()])
        elif isinstance(target, get_product_model()):
            # product category first...
            if target.primary_category:
                items.extend([(c.title, c.get_absolute_url()) for c in target.primary_category.get_path()])

            # ...then the product itself
            items.append((target.title, target.get_absolute_url()))
        elif isinstance(target, ChildPage):
            # page/child page
            page = target.page
            items.append((page.title, page.get_absolute_url()))
            items.append((target.title, target.get_absolute_url()))
        elif isinstance(target, PageBase):
            # single cms page
            items.append((target.title, target.get_absolute_url()))
        else:
            raise ValueError('Invalid target argument: Must be instance of Category, Product or None.')

        t = get_template('cubane/ishop/elements/breadcrumbs.html')
        d = {
            'items': items,
            'sep': sep,
        }
        with context.push(**d):
            return t.render(context)
Exemple #7
0
 def get_absolute_url(self):
     """
     Return absolute url.
     """
     return make_absolute_url(self.get_fullslug())
Exemple #8
0
 def process_response(self, request, response):
     if settings.SSL and isinstance(response, HttpResponseRedirectBase):
         response['Location'] = make_absolute_url(response['Location'], domain=request.META['HTTP_HOST'])
     return response
Exemple #9
0
def absolute_url(url):
    return make_absolute_url(url)