How to use the regions.models.Region.objects 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
# 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 / pages / views.py View on Github external
def form_valid(self, form):
        from regions.utils import move_to_region

        self.page = self.get_object()
        self.new_region_slug = form.cleaned_data['new_region']
        self.new_region = Region.objects.get(slug__iexact=self.new_region_slug)

        move_to_region(self.new_region, pages=[self.page]) 
        return HttpResponseRedirect(self.get_success_url())
github localwiki / localwiki-backend-server / localwiki / dashboard / views.py View on Github external
def get_filters(self):
        if not self.is_global_dashboard:
            return {'region': Region.objects.get(slug=self.kwargs.get('region'))}
        return {}
github localwiki / localwiki-backend-server / localwiki / activity / feeds.py View on Github external
def __call__(self, request, *args, **kwargs):
        from regions.models import Region
        re_match = region_routing_pattern.match(request.get_full_path())
        if re_match:
            region_slug = re_match.group('region')
            self.region = Region.objects.get(slug=region_slug)

        return super(ActivityFeedSyndication, self).__call__(request, *args, **kwargs)
github localwiki / localwiki-backend-server / localwiki / main / sitemaps.py View on Github external
def items(self):
        return Region.objects.all().exclude(is_active=False)
github localwiki / localwiki-backend-server / localwiki / main_content / views.py View on Github external
def get_context_data(self, *args, **kwargs):
        from pages.models import Page
        from regions.models import Region

        context = super(SplashPageView, self).get_context_data(*args, **kwargs)

        qs = Region.objects.exclude(regionsettings__is_meta_region=True)
        qs = qs.exclude(is_active=False)

        # Exclude ones with empty scores
        qs = qs.exclude(score=None)

        qs = qs.order_by('-score__score', '?')

        # First, all results in their language, then all other results following their language's results:
        language = get_language()
        if language == 'en':
            qs_our_language = qs.filter(
                Q(regionsettings__default_language=language) | Q(regionsettings__default_language__isnull=True)
            )
        else:
            qs_our_language = qs.filter(regionsettings__default_language=language)
        qs_rest = qs.exclude(regionsettings__default_language=language)