• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

justquick / django-activity-stream / 7009540190

27 Nov 2023 06:58PM UTC coverage: 94.394% (-0.6%) from 95.009%
7009540190

Pull #534

github

web-flow
Merge c0f354781 into a7df85e3a
Pull Request #534: Integrated swappable model support

238 of 302 branches covered (0.0%)

99 of 113 new or added lines in 18 files covered. (87.61%)

2 existing lines in 1 file now uncovered.

1549 of 1641 relevant lines covered (94.39%)

11.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.38
/actstream/settings.py
1
from django.apps import apps
12✔
2
from django.conf import settings
12✔
3
from django.core.exceptions import ImproperlyConfigured
12✔
4

5

6
SETTINGS = getattr(settings, 'ACTSTREAM_SETTINGS', {})
12✔
7

8

9
def import_obj(mod):
12✔
10
    mod_path = mod.split('.')
12✔
11
    try:
12✔
12
        obj = __import__('.'.join(mod_path[:-1]), {}, {}, [mod_path[-1]])
12✔
13
        return getattr(obj, mod_path[-1])
12✔
14
    except:
×
15
        raise ImportError(f'Cannot import: {mod}')
×
16

17

18
def get_action_manager():
12✔
19
    """
20
    Returns the class of the action manager to use from ACTSTREAM_SETTINGS['MANAGER']
21
    """
22
    mod = SETTINGS.get('MANAGER', 'actstream.managers.ActionManager')
12✔
23
    try:
12✔
24
        return import_obj(mod)()
12✔
25
    except ImportError:
×
26
        raise ImproperlyConfigured(f'Cannot import {mod} try fixing ACTSTREAM_SETTINGS[MANAGER] setting.')
×
27

28

29
FETCH_RELATIONS = SETTINGS.get('FETCH_RELATIONS', True)
12✔
30

31
USE_JSONFIELD = SETTINGS.get('USE_JSONFIELD', False)
12✔
32

33
USE_DRF = 'DRF' in SETTINGS
12✔
34

35
DRF_SETTINGS = {
12✔
36
    'ENABLE': False,
37
    'EXPAND_FIELDS': True,
38
    'HYPERLINK_FIELDS': False,
39
    'SERIALIZERS': {},
40
    'MODEL_FIELDS': {},
41
    'VIEWSETS': {},
42
    'PERMISSIONS': ['rest_framework.permissions.IsAuthenticated']
43
}
44

45
if USE_DRF:
12!
46
    DRF_SETTINGS.update(SETTINGS.get('DRF', {}))
12✔
47

48
    for item in ('SERIALIZERS', 'VIEWSETS', 'MODEL_FIELDS'):
12✔
49
        DRF_SETTINGS[item] = {
12✔
50
            label.lower(): obj for label, obj in DRF_SETTINGS[item].items()
51
        }
52

53

54
def get_swappable_model(model):
12✔
55
    model_lookup = getattr(settings, 'ACTSTREAM_%s_MODEL' % model.upper(), 'actstream.%s' % model)
12✔
56
    try:
12✔
57
        return apps.get_model(model_lookup, require_ready=False)
12✔
NEW
58
    except ValueError:
×
NEW
59
        raise ImproperlyConfigured(
×
60
            "%s must be of the form 'app_label.model_name'" % model_lookup
61
        )
NEW
62
    except LookupError:
×
NEW
63
        raise ImproperlyConfigured(
×
64
            "Model '%s' has not been installed" % model_lookup
65
        )
66

67

68
def get_follow_model():
12✔
69
    """Return the Follow model that is active."""
70
    return get_swappable_model('Follow')
12✔
71

72

73
def get_action_model():
12✔
74
    """Return the Action model that is active."""
75
    return get_swappable_model('Action')
12✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc