Example #1
0
 def create_detail(self, object_list, bundle):
     if not self.check_contribution_permission(bundle, 'add'):
         raise Unauthorized("Sorry, only staff or contributors can create resource.")
     # check if user can add regarding to his plan
     topic         = get_topic_from_request(bundle.request)
     owner_profile = topic.author.detectiveprofileuser
     if owner_profile.nodes_max() > -1 and owner_profile.nodes_count()[topic.slug] >= owner_profile.nodes_max():
         raise Unauthorized("Sorry, you have to upgrade your plan.")
     return True
Example #2
0
 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()
Example #3
0
 def get_topic(self, bundle=None):
     model = self.get_model()
     topic = None
     # Bundle given
     if bundle != None:
         # The topic may be set by a middleware
         topic = get_topic_from_request(bundle.request)
     # No topic found
     if topic == None:
         # We found the topic according to the current model
         topic = Topic.objects.get(ontology_as_mod=get_model_topic(model))
     return topic
Example #4
0
 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()
Example #5
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
Example #6
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
Example #7
0
 def get_topic_from_bundle(self, bundle):
     topic = get_topic_from_request(bundle.request)
     if topic == None:
         topic = Topic.objects.get(ontology_as_mod=get_model_topic(bundle.obj)).public
     return topic