How to use the regions.models.Region.objects.filter function in regions

To help you get started, we’ve selected a few regions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github localwiki / localwiki-backend-server / localwiki / users / views.py View on Github external
else:
        # Check to see if they've edited a region recently
        edited_pages = Page.versions.filter(version_info__user=user)
        referer = request.META.get('HTTP_REFERER')
        if edited_pages.exists():
            region = edited_pages[0].region
            return Page(name=pagename, region=region)
        # Let's try and guess by the previous URL. Ugh!
        if referer:
            urlparts = urllib_parse.urlparse(referer)
            # Is this host us?
            for host in settings.ALLOWED_HOSTS:
                if urlparts.netloc.endswith(host):
                    pathparts = parts.path.split('/')
                    # Is the path in a region?
                    if len(pathparts) > 1 and Region.objects.filter(slug=pathparts[1]).exists():
                        return Page(name=pagename, region=Region.objects.get(slug=pathparts[1]))

        # Put it in the main region for now :/
        return Page(name=pagename, region=get_main_region())
github localwiki / localwiki-backend-server / localwiki / utils / templatetags / smart_url.py View on Github external
if self.region_linking_to_slug:
            region_linking_to_slug = self.region_linking_to_slug.resolve('context')
        else:
            region_linking_to_slug = None

        # Get the current region, if we're rendering on a region wth a
        # custom domain.
        in_region_with_custom_domain = RegionSettings.objects.filter(domain=cur_hostname)
        if in_region_with_custom_domain:
            cur_region_with_domain  = in_region_with_custom_domain[0]
            cur_region_with_domain = cur_region_with_domain.region

        # Get the region object we're linking to, if possible.
        if region_linking_to_slug:
            region_linking_to = Region.objects.filter(slug=region_linking_to_slug)
            if region_linking_to:
                region_linking_to = region_linking_to[0]

        if in_region_with_custom_domain:
            explicit_link_to_self = region_linking_to and (cur_region_with_domain == region_linking_to)
            if getattr(request, 'host'):
                urlconf = request.host.urlconf

            # We're linking inside of the region, so let's
            # just use the usual URL tag, but with the host
            # specific URLconf.
            if explicit_link_to_self or not region_linking_to:
                return self.render_url_tag(context, urlconf=urlconf, remove_region_slug=True)

            # A link outside the region, so let's render it as absolute.
            return self.render_host_url_tag(context)
github localwiki / localwiki-backend-server / localwiki / pages / cache.py View on Github external
def invalidate_region_tag_views(slug, region):
    from tags.cache import django_invalidate_tag_view, varnish_invalidate_tag_view

    # Clear on the region itself
    varnish_invalidate_tag_view(slug, region)
    django_invalidate_tag_view(slug, region)

    # Clear on nearby regions
    center = region.regionsettings.region_center
    if not center:
        return
    nearby_regions = Region.objects.filter(regionsettings__region_center__dwithin=(center, 0.5))
    for region in nearby_regions:
        varnish_invalidate_tag_view(slug, region)
        django_invalidate_tag_view(slug, region)
github localwiki / localwiki-backend-server / localwiki / region_scores / models.py View on Github external
def _calculate_region_score(region_id):
    from maps.models import MapData
    from pages.models import Page, PageFile

    region = Region.objects.filter(id=region_id)
    if region.exists():
        region = region[0]
    else:
        return

    num_pages = Page.objects.filter(region=region).count()
    num_files = PageFile.objects.filter(region=region).count()
    num_maps = MapData.objects.filter(region=region).count()

    score = int(num_pages*1.5 + num_files*1.3 + num_maps)
    score = normalize_score(score)

    score_obj = RegionScore.objects.filter(region=region)
    if not score_obj.exists():
        score_obj = RegionScore(region=region)
    else: