Exemple #1
0
    def member_of_names_list(self):
        """Returns a list having names of each member (GSystemType, i.e Page,
        File, etc.), built from 'member_of' field (list of ObjectIds)

        """
        from gsystem_type import GSystemType
        return [GSystemType.get_gst_name_id(gst_id)[0] for gst_id in self.member_of]
Exemple #2
0
    def query_list(group_id, member_of_name, user_id=None, if_gstaff=False, **kwargs):
        from group import Group
        from gsystem_type import GSystemType

        group_name, group_id = Group.get_group_name_id(group_id)
        gst_name, gst_id = GSystemType.get_gst_name_id(member_of_name)
        if if_gstaff:
            query = {
                    '_type': 'GSystem',
                    'status': 'PUBLISHED',
                    'group_set': {'$in': [group_id]},
                    'member_of': {'$in': [gst_id]},
                    'access_policy': {'$in': [u'Public', u'PUBLIC', u'PRIVATE']}
                    }
        else:
            query = {
                    '_type': 'GSystem',
                    'status': 'PUBLISHED',
                    'group_set': {'$in': [group_id]},
                    'member_of': {'$in': [gst_id]},
                    '$or':[
                            {'access_policy': {'$in': [u'Public', u'PUBLIC']}},
                            {'$and': [
                                {'access_policy': u"PRIVATE"},
                                {'created_by': user_id}
                                ]
                            },
                            {'created_by': user_id}
                        ]
                    }
        for each in kwargs:
            query.update({each : kwargs[each]})
        return node_collection.find(query).sort('last_update', -1)
Exemple #3
0
    def member_of_names_list(self):
        """Returns a list having names of each member (GSystemType, i.e Page,
        File, etc.), built from 'member_of' field (list of ObjectIds)

        """
        from gsystem_type import GSystemType
        return [GSystemType.get_gst_name_id(gst_id)[0] for gst_id in self.member_of]
Exemple #4
0
    def query_list(group_id,
                   member_of_name,
                   user_id=None,
                   if_gstaff=False,
                   **kwargs):
        from group import Group
        from gsystem_type import GSystemType

        group_name, group_id = Group.get_group_name_id(group_id)
        gst_name, gst_id = GSystemType.get_gst_name_id(member_of_name)
        if if_gstaff:
            query = {
                '_type': 'GSystem',
                'status': 'PUBLISHED',
                'group_set': {
                    '$in': [group_id]
                },
                'member_of': {
                    '$in': [gst_id]
                },
                'access_policy': {
                    '$in': [u'Public', u'PUBLIC', u'PRIVATE']
                }
            }
        else:
            query = {
                '_type':
                'GSystem',
                'status':
                'PUBLISHED',
                'group_set': {
                    '$in': [group_id]
                },
                'member_of': {
                    '$in': [gst_id]
                },
                '$or': [{
                    'access_policy': {
                        '$in': [u'Public', u'PUBLIC']
                    }
                }, {
                    '$and': [{
                        'access_policy': u"PRIVATE"
                    }, {
                        'created_by': user_id
                    }]
                }, {
                    'created_by': user_id
                }]
            }
        for each in kwargs:
            query.update({each: kwargs[each]})
        return node_collection.find(query).sort('last_update', -1)
Exemple #5
0
    def fill_node_values(self, request=HttpRequest(), **kwargs):

        user_id = kwargs.get('created_by', None)
        # dict to sum both dicts, kwargs and request.POST
        print "inside fill_node_values of node.py"
        values_dict = {}
        if request:
            if request.POST:
                values_dict.update(request.POST.dict())
            if (not user_id) and request.user:
                user_id = request.user.id
        # adding kwargs dict later to give more priority to values passed via kwargs.
        values_dict.update(kwargs)

        # handling storing user id values.
        if user_id:
            if not self['created_by'] and ('created_by' not in values_dict):
                # if `created_by` field is blank i.e: it's new node and add/fill user_id in it.
                # otherwise escape it (for subsequent update/node-modification).
                values_dict.update({'created_by': user_id})
            if 'modified_by' not in values_dict:
                values_dict.update({'modified_by': user_id})
            if 'contributors' not in values_dict:
                values_dict.update(
                    {'contributors': add_to_list(self.contributors, user_id)})

        if 'member_of' in values_dict and not isinstance(
                values_dict['member_of'], ObjectId):
            from gsystem_type import GSystemType
            gst_node = GSystemType.get_gst_name_id(values_dict['member_of'])
            if gst_node:
                values_dict.update({'member_of': ObjectId(gst_node[1])})

        # filter keys from values dict there in node structure.
        node_str = Node.structure
        node_str_keys_set = set(node_str.keys())
        values_dict_keys_set = set(values_dict.keys())

        for each_key in values_dict_keys_set.intersection(node_str_keys_set):
            temp_prev_val = self[each_key]
            # checking for proper casting for each field
            if isinstance(node_str[each_key], type):
                node_str_data_type = node_str[each_key].__name__
            else:
                node_str_data_type = node_str[each_key]
            casted_new_val = cast_to_data_type(values_dict[each_key],
                                               node_str_data_type)
            # check for uniqueness and addition of prev values for dict, list datatype values
            self[each_key] = casted_new_val
        return self
Exemple #6
0
    def fill_node_values(self, request=HttpRequest(), **kwargs):

        user_id = kwargs.get('created_by', None)
        # dict to sum both dicts, kwargs and request.POST
        values_dict = {}
        if request:
            if request.POST:
                values_dict.update(request.POST.dict())
            if (not user_id) and request.user:
                user_id = request.user.id
        # adding kwargs dict later to give more priority to values passed via kwargs.
        values_dict.update(kwargs)

        # handling storing user id values.
        if user_id:
            if not self['created_by'] and ('created_by' not in values_dict):
                # if `created_by` field is blank i.e: it's new node and add/fill user_id in it.
                # otherwise escape it (for subsequent update/node-modification).
                values_dict.update({'created_by': user_id})
            if 'modified_by' not in values_dict:
                values_dict.update({'modified_by': user_id})
            if 'contributors' not in values_dict:
                values_dict.update({'contributors': add_to_list(self.contributors, user_id)})

        if 'member_of' in values_dict  and not isinstance(values_dict['member_of'],ObjectId):
            from gsystem_type import GSystemType
            gst_node = GSystemType.get_gst_name_id(values_dict['member_of'])
            if gst_node:
                values_dict.update({'member_of': ObjectId(gst_node[1])})

        # filter keys from values dict there in node structure.
        node_str = Node.structure
        node_str_keys_set = set(node_str.keys())
        values_dict_keys_set = set(values_dict.keys())

        for each_key in values_dict_keys_set.intersection(node_str_keys_set):
            temp_prev_val = self[each_key]
            # checking for proper casting for each field
            if isinstance(node_str[each_key], type):
                node_str_data_type = node_str[each_key].__name__
            else:
                node_str_data_type = node_str[each_key]
            casted_new_val = cast_to_data_type(values_dict[each_key], node_str_data_type)
            # check for uniqueness and addition of prev values for dict, list datatype values
            self[each_key] = casted_new_val
        return self