コード例 #1
0
ファイル: summary.py プロジェクト: nstallbaumer/detective.io
 def get_topic_or_404(self, request=None):
     try:
         if request is not None:
             topic = utils.get_topic_from_request(request)
             if topic == None:
                 raise Topic.DoesNotExist()
             return topic
         else:
             return Topic.objects.get(
                 ontology_as_mod=self._meta.urlconf_namespace)
     except Topic.DoesNotExist:
         raise Http404()
コード例 #2
0
    def process_request(self, request):
        regex = re.compile(r'api/([a-zA-Z0-9_\-.]+)/([a-zA-Z0-9_\-]+)/')
        urlparts = regex.findall(request.path)

        if urlparts:
            # Get the topic that match to this url.
            topic = get_topic_from_request(request)
            if topic == None:
                raise Http404(Topic.DoesNotExist())
            else:
                # This will automaticly create the API if needed
                # or failed if the topic is unknown
                try:
                    getattr(topics, topic.ontology_as_mod)
                except AttributeError as e:
                    raise Http404(e)

        return None