Пример #1
0
def lookup_url(settings, name, include_server=False, ssl=False):
    """Look up a named URL for the payment module.

    Tries a specific-to-general lookup fallback, returning
    the first positive hit.

    First look for a dictionary named "URL_OVERRIDES" on the settings object.
    Next try prepending the module name to the name
    Last just look up the name
    """
    url = None

    if not url:
        try:
            possible = settings.KEY.value + "_" + name
            url = urlresolvers.reverse(possible)
        except urlresolvers.NoReverseMatch:
            log.debug('No url found for %s', possible)

    if not url:
        try:
            url = urlresolvers.reverse(name)
        except urlresolvers.NoReverseMatch:
            log.error('Could not find any url for %s', name)
            raise

    if include_server:
        if ssl:
            method = "https://"
        else:
            method = "http://"
        site = Site.objects.get_current()
        url = url_join(method, site.domain, url)

    return url
Пример #2
0
def lookup_url(settings, name, include_server=False, ssl=False):
    """Look up a named URL for the payment module.

    Tries a specific-to-general lookup fallback, returning
    the first positive hit.

    First look for a dictionary named "URL_OVERRIDES" on the settings object.
    Next try prepending the module name to the name
    Last just look up the name
    """
    url = None
    
    if not url:
        try:
            possible = settings.KEY.value + "_" + name
            url = urlresolvers.reverse(possible)
        except urlresolvers.NoReverseMatch:
            log.debug('No url found for %s', possible)
    
    if not url:
        try:
            url = urlresolvers.reverse(name)
        except urlresolvers.NoReverseMatch:
            log.error('Could not find any url for %s', name)
            raise
    
    if include_server:
        if ssl:
            method = "https://"
        else:
            method = "http://"
        site = Site.objects.get_current()
        url = url_join(method, site.domain, url)

    return url
Пример #3
0
def check_with_akismet(comment=None, request=None, **kwargs):
    if config_value("PRODUCT", "AKISMET_ENABLE"):
        key = config_value("PRODUCT", "AKISMET_KEY")
        if key:             
            site = Site.objects.get_current()
            shop = urlresolvers.reverse('satchmo_shop_home')
            from akismet import Akismet
            akismet = Akismet(
                key=settings.AKISMET_API_KEY,
                blog_url='http://%s' % url_join(site.domain, shop))
            if akismet.verify_key():
                akismet_data = { 'comment_type': 'comment',
                                 'referrer': request.META.get('HTTP_REFERER', ""),
                                 'user_ip': comment.ip_address,
                                 'user_agent': '' }
                if akismet_api.comment_check(smart_str(comment.comment), data=akismet_data, build_data=True):
                    comment.is_public=False
                    comment.save()
                    log.info("Akismet marked comment #%i as spam", comment.id)
                else:
                    log.debug("Akismet accepted comment #%i", comment.id)
            else:
                log.warn("Akismet key '%s' not accepted by akismet service.", key)
        else:
            log.info("Akismet enabled, but no key found.  Please put in your admin settings.")
Пример #4
0
def admin_site_views(view):
    """Returns a formatted list of sites, rendering for view, if any"""

    configs = Config.objects.all()
    if view:
        path = urlresolvers.reverse(view)
    else:
        path = None

    links = []
    for config in configs:
        paths = ["http://", config.site.domain]
        if path:
            paths.append(path)

        links.append((config.store_name, url_join(paths)))

    ret = {'links': links, 'multihost': is_multihost_enabled()}
    return ret
Пример #5
0
def admin_site_views(view):
    """Returns a formatted list of sites, rendering for view, if any"""

    configs = Config.objects.all()
    if view:
        path = reverse(view)
    else:
        path = None

    links = []
    for config in configs:
        paths = ["http://", config.site.domain]
        if path:
            paths.append(path)

        links.append((config.store_name, url_join(paths)))

    ret = {"links": links, "multihost": is_multihost_enabled()}
    return ret
Пример #6
0
def lookup_url(settings, name, include_server=False, ssl=False):
    """Look up a named URL for the payment module.

    Tries a specific-to-general lookup fallback, returning
    the first positive hit.

    First look for a dictionary named "URL_OVERRIDES" on the settings object.
    Next try prepending the module name to the name
    Last just look up the name
    """
    if name.startswith("http"):
        return name
    url = None

    try:
        namespace = settings.KEY.value.lower()
        possible = "{namespace}:{url_name}".format(namespace=namespace,
                                                   url_name=name)
        url = reverse(possible)
    except NoReverseMatch:
        log.debug("No url found for %s", possible)

    if not url:
        try:
            url = reverse(name)
        except NoReverseMatch as e:
            log.error("Could not find any url for %s", name)
            log.exception(e)
            raise

    if include_server:
        if ssl:
            method = "https://"
        else:
            method = "http://"
        site = Site.objects.get_current()
        url = url_join(method, site.domain, url)

    return url