Switch to unified view

a/scripts/purge_project.py b/scripts/purge_project.py
1
import sys
1
import sys
2
import logging
2
import logging
3
3
4
from pylons import g, c
4
from pylons import g, c
5
5
6
from ming.orm import session, mapper, MappedClass
6
from ming.orm import session, Mapper
7
7
8
from allura import model as M
8
from allura import model as M
9
9
10
log = logging.getLogger(__name__)
10
log = logging.getLogger(__name__)
11
11
...
...
37
    g.solr.delete(q='project_id_s:%s' % project._id)
37
    g.solr.delete(q='project_id_s:%s' % project._id)
38
    session(project).flush()
38
    session(project).flush()
39
    c.project = project
39
    c.project = project
40
    app_config_ids = [
40
    app_config_ids = [
41
        ac._id for ac in M.AppConfig.query.find(dict(project_id=c.project._id)) ]
41
        ac._id for ac in M.AppConfig.query.find(dict(project_id=c.project._id)) ]
42
    for name, cls in MappedClass._registry.iteritems():
42
    for m in Mapper.all_mappers():
43
        cls = m.mapped_class
43
        if 'project_id' in mapper(cls).property_index:
44
        if 'project_id' in m.property_index:
44
            # Purge the things directly related to the project
45
            # Purge the things directly related to the project
45
            cls.query.remove(
46
            cls.query.remove(
46
                dict(project_id=project._id),
47
                dict(project_id=project._id),
47
            )
48
            )
48
        elif 'app_config_id' in mapper(cls).property_index:
49
        elif 'app_config_id' in m.property_index:
49
            # ... and the things related to its apps
50
            # ... and the things related to its apps
50
            cls.query.remove(
51
            cls.query.remove(
51
                dict(app_config_id={'$in':app_config_ids}),
52
                dict(app_config_id={'$in':app_config_ids}),
52
            )
53
            )
53
        else:
54
        else: