Esempio n. 1
0
    def update_bookmarks(self, node_token):
        user_id = global_session.session['user_id']
        impersonating = global_session.session['impersonating']
        # only update bookmarks for proper users
        if user_id and not impersonating:
            try:
                session = r.Session()
                result = r.search_single_data("bookmarks",
                                         {"user_id" : user_id,
                                          "_core_id" : node_token.bookmark["_core_id"]},
                                         fields = ['entity_table', '_core_id'],
                                         )

                result["accessed_date"] = util.convert_value(datetime.datetime.now())
                util.load_local_data(r, result)
            except custom_exceptions.SingleResultError:
                result = {"__table": "bookmarks",
                          "_core_id": node_token.bookmark["_core_id"],
                          "user_id": user_id,
                          "entity_table": node_token.bookmark["table_name"],
                          "accessed_date": util.convert_value(datetime.datetime.now())}
                # save
                util.load_local_data(r, result)
                result['title'] = node_token.bookmark.get("title")

        else:
            # anonymous user
            result = {"_core_id": node_token.bookmark["_core_id"],
                      "entity_table": node_token.bookmark["table_name"],
                      "accessed_date": util.convert_value(datetime.datetime.now())}

        # update bookmark output to front-end
        result["title"] = node_token.get_title()
        node_token.bookmark = result
Esempio n. 2
0
    def test_zz_add_local(self):

        assert_raises(formencode.Invalid, load_local_data, self.Donkey, {"__table": "people",
                                      "people.address_line_1" : "poo1010101",
                                      "people.address_line_2" : "poop"})
        try:
            load_local_data(self.Donkey, {"__table": "people",
                                      "people.address_line_1" : "poo1010101",
                                      "people.address_line_2" : "poop"})
        except formencode.Invalid, e:
            print e.error_dict
            assert str(e.error_dict) == """{'people.name': [Invalid(u'Please enter a value',)], 'people.postcode': [Invalid(u'Please enter a value',)]}"""
Esempio n. 3
0
    def set_up_inserts(cls):

        super(cls, test_validation).set_up_inserts()

        load_local_data(cls.Donkey, {"__table": u"sub_sub_category",
                                      "category.category_name": u"a",
                                      "category.category_description": u"this is a",
                                      "category.category_type": u"wee",
                                      "sub_category.sub_category_name": u"ab",
                                      "sub_category.sub_category_description": u"this is ab",
                                      "sub_sub_category.sub_sub_category_name": u"abc",
                                      "sub_sub_category.sub_sub_category_description": u"this is abc"}
                       )
Esempio n. 4
0
    def message(self, message, percent = None):

        row = self.database.search_single_data("_core_job_scheduler", "id = %s" % self.job_id, internal = True)

        row["message"] = u"%s" % message

        if percent:
            row["percent"] = percent

        # FIXME don't like this here
        try:
            util.load_local_data(self.database, row)
        except ConcurrentModificationError:
            pass
Esempio n. 5
0
    def test_import_catagory_data(self):

        load_local_data(self.Donkey, {"__table": u"sub_sub_category",
                                      "category.category_name": u"a",
                                      "category.category_description": u"this is a",
                                      "category.category_type": u"wee",
                                      "sub_category.sub_category_name": u"ab",
                                      "sub_category.sub_category_description": u"this is ab",
                                      "sub_sub_category.sub_sub_category_name": u"abc",
                                      "sub_sub_category.sub_sub_category_description": u"this is abc"}
                       )

        results = self.session.query(self.Donkey.get_class("sub_sub_category")).all()

        print [get_all_local_data(a) for a in results]
Esempio n. 6
0
    def test_lookup_validation(self):

        load_local_data(self.Donkey,
                        {"__table": u"donkey",
                        "donkey.name": u"good",
                        "donkey.donkey_type": u"smooth",
                        })


        assert_raises(formencode.Invalid,
                      load_local_data,
                      self.Donkey,
                      {"__table": u"donkey",
                      "donkey.name": u"z",
                      "donkey.donkey_type": u"pooey",
                      })
Esempio n. 7
0
    def test_many_side_mandatory_validation(self):


        assert_raises(
            fe.Invalid,
            load_local_data,
            self.Donkey,
            {"__table": u"category",
            "category.category_name": u"z",
            "category.category_description": u"this is a",
            "category.category_type": u"wee",
            }
        )

        try:
            load_local_data(self.Donkey,
                            {"__table": u"category",
                            "category.category_name": u"z",
                            "category.category_description": u"this is a",
                            "category.category_type": u"wee",
                            })
        except fe.Invalid, e:
            assert e.msg.strip() == "sub_category: Please enter a value"
Esempio n. 8
0
                                      "people.address_line_1" : "poo1010101",
                                      "people.address_line_2" : "poop"})
        except formencode.Invalid, e:
            print e.error_dict
            assert str(e.error_dict) == """{'people.name': [Invalid(u'Please enter a value',)], 'people.postcode': [Invalid(u'Please enter a value',)]}"""


        assert_raises(formencode.Invalid, load_local_data, self.Donkey, {"__table": "donkey_sponsership",
                                                                         "donkey_sponsership.amount" : 70,
                                      "people.address_line_1" : "poo1010101",
                                      "people.address_line_2" : "poop"})

        try:
            load_local_data(self.Donkey, {"__table": "donkey_sponsership",
                                          "donkey_sponsership.amount" : 70,
                                          "donkey.age" : u"poo",
                                      "people.address_line_1" : u"poo1010101",
                                      "people.address_line_2" : u"poop"})
        except formencode.Invalid, e:
            assert str(e.error_dict) == r"""{'donkey.age': [Invalid(u'Please enter an integer value',), Invalid(u'Please enter an integer value',)], 'people.name': [Invalid(u'Please enter a value',)], 'people.postcode': [Invalid(u'Please enter a value',)]}"""

            assert str(e.error_dict["donkey.age"]) == "[Invalid(u'Please enter an integer value',), Invalid(u'Please enter an integer value',)]"


        load_local_data(self.Donkey, {"__table": u"donkey_sponsership",
                                      "donkey_sponsership.amount" : 711110,
                                      "donkey.age" : 12,
                                      "people.name" : u"fred",
                                      "people.postcode" : u"fred",
                                      "people.address_line_1" : u"poo1010101",
                                      "people.address_line_2" : u"poop"})