Beispiel #1
0
    def put(self, field_id):
        """
        Update a single field's attributes.

        :param field_id:
        :return: the serialized field
        :rtype: FieldDesc
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        request = self.validate_message(self.request.body,
                                        requests.FieldDesc)

        # enforce difference between /admin/field and /admin/fieldtemplate
        request['is_template'] = False

        response = yield update_field(field_id, request, self.request.language)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(202) # Updated
        self.finish(response)
Beispiel #2
0
    def delete(self, field_id):
        """
        Delete a single field.

        :param field_id:
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        yield delete_field(field_id, False)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(200)
Beispiel #3
0
    def put(self):
        """
        Parameters: None
        Request: ReceiverReceiverDesc
        Response: ReceiverReceiverDesc
        Errors: ReceiverIdNotFound, InvalidInputFormat, InvalidAuthentication, TipIdNotFound
        """
        request = self.validate_message(self.request.body, requests.ReceiverReceiverDesc)

        receiver_status = yield update_receiver_settings(self.current_user.user_id, request, self.request.language)

        # get the updated list of receivers, and update the cache
        public_receivers_list = yield get_public_receiver_list(self.request.language)
        GLApiCache.invalidate("receivers")
        GLApiCache.set("receivers", self.request.language, public_receivers_list)

        self.set_status(200)
        self.finish(receiver_status)
Beispiel #4
0
 def test_get_set_items(self):
     self.assertEqual(GLApiCache.memory_cache_dict, {})
     self.assertIsNone(GLApiCache.get("passante_di_professione", "it"))
     self.assertIsNone(GLApiCache.get("passante_di_professione", "en"))
     GLApiCache.set("passante_di_professione", "it", 'ititit')
     GLApiCache.set("passante_di_professione", "en", 'enenen')
     self.assertTrue(
         "passante_di_professione" in GLApiCache.memory_cache_dict)
     self.assertTrue(
         "it" in GLApiCache.memory_cache_dict['passante_di_professione'])
     self.assertTrue(
         "en" in GLApiCache.memory_cache_dict['passante_di_professione'])
     self.assertEqual(GLApiCache.get("passante_di_professione", "it"),
                      'ititit')
     self.assertEqual(GLApiCache.get("passante_di_professione", "en"),
                      'enenen')
     GLApiCache.invalidate()
     self.assertEqual(GLApiCache.memory_cache_dict, {})
Beispiel #5
0
 def test_set(self):
     self.assertTrue("passante_di_professione" not in GLApiCache.memory_cache_dict)
     pdp_it = yield GLApiCache.get("passante_di_professione", "it", self.mario, "come", "una", "catapulta!")
     self.assertTrue("passante_di_professione" in GLApiCache.memory_cache_dict)
     self.assertTrue(pdp_it == "come una catapulta!")
     yield GLApiCache.set("passante_di_professione", "it", "ma io ho visto tutto!")
     self.assertTrue("passante_di_professione" in GLApiCache.memory_cache_dict)
     pdp_it = yield GLApiCache.get("passante_di_professione", "it", self.mario, "already", "cached")
     self.assertEqual(pdp_it, "ma io ho visto tutto!")
Beispiel #6
0
    def get(self, field_id):
        """
        Get the field identified by field_id

        :param field_id:
        :return: the serialized field
        :rtype: FieldDesc
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        response = yield get_field(field_id, False, self.request.language)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(200)
        self.finish(response)
Beispiel #7
0
    def put(self):
        """
        Parameters: None
        Request: ReceiverReceiverDesc
        Response: ReceiverReceiverDesc
        Errors: ReceiverIdNotFound, InvalidInputFormat, InvalidAuthentication, TipIdNotFound
        """
        request = self.validate_message(self.request.body,
                                        requests.ReceiverReceiverDesc)

        receiver_status = yield update_receiver_settings(
            self.current_user.user_id, request, self.request.language)

        # get the updated list of receivers, and update the cache
        public_receivers_list = yield get_public_receiver_list(
            self.request.language)
        GLApiCache.invalidate('receivers')
        GLApiCache.set('receivers', self.request.language,
                       public_receivers_list)

        self.set_status(200)
        self.finish(receiver_status)
Beispiel #8
0
    def post(self):
        """
        Create a new field.

        :return: the serialized field
        :rtype: FieldDesc
        :raises InvalidInputFormat: if validation fails.
        """
        try:
            tmp = json.loads(self.request.body)
        except ValueError:
            raise errors.InvalidInputFormat("Invalid JSON format")

        if isinstance(tmp, dict) and 'template_id' in tmp:
            request = self.validate_message(self.request.body,
                                            requests.FieldFromTemplateDesc)

            # enforce difference between /admin/field and /admin/fieldtemplate
            request['is_template'] = False
            response = yield create_field_from_template(request, self.request.language)

        else:
            request = self.validate_message(self.request.body,
                                            requests.FieldDesc)

            # enforce difference between /admin/field and /admin/fieldtemplate
            request['is_template'] = False
            response = yield create_field(request, self.request.language)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(201)
        self.finish(response)
 def test_set(self):
     self.assertTrue(
         "passante_di_professione" not in GLApiCache.memory_cache_dict)
     pdp_it = yield GLApiCache.get("passante_di_professione", "it",
                                   self.mario, "come", "una", "catapulta!")
     self.assertTrue(
         "passante_di_professione" in GLApiCache.memory_cache_dict)
     self.assertTrue(pdp_it == "come una catapulta!")
     yield GLApiCache.set("passante_di_professione", "it",
                          "ma io ho visto tutto!")
     self.assertTrue(
         "passante_di_professione" in GLApiCache.memory_cache_dict)
     pdp_it = yield GLApiCache.get("passante_di_professione", "it",
                                   self.mario, "already", "cached")
     self.assertEqual(pdp_it, "ma io ho visto tutto!")
Beispiel #10
0
    def post(self):
        """
        """

        request = self.validate_message(self.request.body,
                                        requests.WizardFirstSetupDesc)

        yield wizard(request, self.request.language)

        # cache must be updated in particular to set wizard_done = True
        public_node_desc = yield anon_serialize_node(self.request.language)
        GLApiCache.invalidate('node')
        GLApiCache.invalidate('contexts')
        GLApiCache.invalidate('receivers')
        GLApiCache.set('node', self.request.language, public_node_desc)
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.set('contexts', self.request.language, public_contexts_list)
        public_receivers_list = yield get_public_receiver_list(self.request.language)
        GLApiCache.set('receivers', self.request.language, public_receivers_list)

        self.set_status(201)  # Created
        self.finish()