Attention une mise à jour du serveur va être effectuée le lundi 17 mai entre 13h et 13h30. Cette mise à jour va générer une interruption du service de quelques minutes.

sample_set_list.py 4.85 KB
Newer Older
1
class SampleSetList():
2
    def __init__(self, type, page=None, step=None):
HERBERT Ryan's avatar
HERBERT Ryan committed
3
        self.type = type
4 5 6 7 8

        limitby = None
        if page is not None and step is not None:
            limitby = (page*step, (page+1)*step+1) # one more element to indicate if another page exists

9
        query_gss = db(
HERBERT Ryan's avatar
HERBERT Ryan committed
10
            (auth.vidjil_accessible_query(PermissionEnum.read.value, db[type]))
11
        ).select(
HERBERT Ryan's avatar
HERBERT Ryan committed
12
            db[type].ALL,
13
            limitby = limitby,
HERBERT Ryan's avatar
HERBERT Ryan committed
14
            orderby = ~db[type].id
15 16
        )

HERBERT Ryan's avatar
HERBERT Ryan committed
17
        step = len(query_gss) if step is None else step
HERBERT Ryan's avatar
HERBERT Ryan committed
18 19 20
        auth.load_permissions(PermissionEnum.admin.value, type)
        auth.load_permissions(PermissionEnum.anon.value, type)
        self.elements = {}
HERBERT Ryan's avatar
HERBERT Ryan committed
21 22
        for i in range(0, min(len(query_gss), step)):
            row = query_gss[i]
HERBERT Ryan's avatar
HERBERT Ryan committed
23 24 25 26 27 28 29 30 31 32 33 34
            self.elements[row.id] = row
            self.elements[row.id].file_count = 0
            self.elements[row.id].size = 0
            self.elements[row.id].conf_list = []
            self.elements[row.id].conf_id_list = [-1]
            self.elements[row.id].most_used_conf = ""
            self.elements[row.id].groups = ""
            self.elements[row.id].group_list = []
            self.elements[row.id].has_permission = auth.can_modify(type, row.id)
            self.elements[row.id].anon_allowed = auth.can_view_info(type, row.id)

        self.element_ids = self.elements.keys()
35 36 37

    def load_creator_names(self):
        query_creator = db(
HERBERT Ryan's avatar
HERBERT Ryan committed
38 39
            (db[self.type].creator == db.auth_user.id)
            & (db[self.type].id.belongs(self.element_ids))
40
        ).select(
HERBERT Ryan's avatar
HERBERT Ryan committed
41
            db[self.type].id, db.auth_user.last_name
42 43
        )
        for i, row in enumerate(query_creator) :
HERBERT Ryan's avatar
HERBERT Ryan committed
44
            self.elements[row[self.type].id].creator = row.auth_user.last_name
45 46 47

    def load_sample_information(self):
        query_sample = db(
HERBERT Ryan's avatar
HERBERT Ryan committed
48
            (db.sample_set_membership.sample_set_id == db[self.type].sample_set_id)
49
            &(db.sequence_file.id == db.sample_set_membership.sequence_file_id)
HERBERT Ryan's avatar
HERBERT Ryan committed
50
            &(db[self.type].id.belongs(self.element_ids))
51
        ).select(
HERBERT Ryan's avatar
HERBERT Ryan committed
52
            db[self.type].id, db.sequence_file.size_file
53
        )
HERBERT Ryan's avatar
HERBERT Ryan committed
54
         
55
        for i, row in enumerate(query_sample) :
HERBERT Ryan's avatar
HERBERT Ryan committed
56 57
            self.elements[row[self.type].id].file_count += 1
            self.elements[row[self.type].id].size += row.sequence_file.size_file
58 59 60

    def load_config_information(self):
        query = db(
HERBERT Ryan's avatar
HERBERT Ryan committed
61
            (db[self.type].sample_set_id == db.fused_file.sample_set_id) &
62 63 64
            (db.fused_file.config_id == db.config.id) &
            (auth.vidjil_accessible_query(PermissionEnum.read_config.value, db.config) |
                auth.vidjil_accessible_query(PermissionEnum.admin_config.value, db.config) ) &
HERBERT Ryan's avatar
HERBERT Ryan committed
65
            (db[self.type].id.belongs(self.element_ids))
66
        ).select(
HERBERT Ryan's avatar
HERBERT Ryan committed
67
            db[self.type].id, db.config.name, db.config.id, db.fused_file.fused_file
68 69 70
        )

        for i, row in enumerate(query) :
HERBERT Ryan's avatar
HERBERT Ryan committed
71
            self.elements[row[self.type].id].conf_list.append(
72
                    {'id': row.config.id, 'name': row.config.name, 'fused_file': row.fused_file.fused_file})
HERBERT Ryan's avatar
HERBERT Ryan committed
73
            self.elements[row[self.type].id].conf_id_list.append(row.config.id)
74

HERBERT Ryan's avatar
HERBERT Ryan committed
75
        for key, row in self.elements.iteritems():
76
            row.most_used_conf = max(set(row.conf_id_list), key=row.conf_id_list.count)
HERBERT Ryan's avatar
HERBERT Ryan committed
77
            row.confs = ", ".join(list(set(map(lambda elem: elem['name'], row.conf_list)))) 
78 79 80

    def load_permitted_groups(self):
        query = db(
HERBERT Ryan's avatar
HERBERT Ryan committed
81 82 83 84 85
            ((db[self.type].id == db.auth_permission.record_id) | (db.auth_permission.record_id == 0)) &
            (db.auth_permission.table_name == self.type) &
            (db.auth_permission.name == PermissionEnum.access.value) &
            (db.auth_group.id == db.auth_permission.group_id)
            & (db[self.type].id.belongs(self.element_ids))
86
        ).select(
HERBERT Ryan's avatar
HERBERT Ryan committed
87
            db[self.type].id, db.auth_group.role
88 89
        )
        for i, row in enumerate(query) :
HERBERT Ryan's avatar
HERBERT Ryan committed
90
            self.elements[row[self.type].id].group_list.append(row.auth_group.role.replace('user_','u'))
91

HERBERT Ryan's avatar
HERBERT Ryan committed
92
        for key, row in self.elements.iteritems():
93 94 95 96 97
            row.groups = ", ".join(filter(lambda g: g != 'admin', set(row.group_list)))

    def load_anon_permissions(self):
        query = db(
            (db.auth_permission.name == "anon") &
HERBERT Ryan's avatar
HERBERT Ryan committed
98 99
            (db.auth_permission.table_name == self.type) &
            (db[self.type].id == db.auth_permission.record_id ) &
100 101 102
            (db.auth_group.id == db.auth_permission.group_id ) &
            (db.auth_membership.user_id == auth.user_id) &
            (db.auth_membership.group_id == db.auth_group.id) &
HERBERT Ryan's avatar
HERBERT Ryan committed
103
            (db[self.type].id.belongs(self.element_ids))
104
        ).select(
HERBERT Ryan's avatar
HERBERT Ryan committed
105
            db[self.type].id
106 107
        )
        for i, row in enumerate(query) :
HERBERT Ryan's avatar
HERBERT Ryan committed
108
            self.elements[row.id].anon_allowed = True
109 110

    def get_values(self):
HERBERT Ryan's avatar
HERBERT Ryan committed
111
        return self.elements.values()
HERBERT Ryan's avatar
HERBERT Ryan committed
112 113 114

    def __len__(self):
        return len(self.element_ids)