1+ from django import template
2+ from django .utils .safestring import mark_safe
3+
4+ register = template .Library ()
5+
6+
7+ @register .simple_tag
8+ def hello_world_header ():
9+ """Display hello world message in header if plugin is active"""
10+ try :
11+ from plugins .models import PluginManager
12+ plugin = PluginManager .objects .get (app_name = 'plugins.hello_world' )
13+
14+ if plugin .is_active :
15+ return mark_safe ('''
16+ <div class="alert alert-info text-center mb-0" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border: none; border-radius: 0;">
17+ <i class="fas fa-rocket"></i>
18+ <strong>Hello World Plugin Active!</strong>
19+ This message appears when the Hello World plugin is activated.
20+ <i class="fas fa-star"></i>
21+ </div>
22+ ''' )
23+ return ''
24+ except :
25+ return ''
26+
27+
28+ @register .simple_tag
29+ def plugin_status_badge ():
30+ """Display plugin status badge"""
31+ try :
32+ from plugins .models import PluginManager
33+ plugin = PluginManager .objects .get (app_name = 'plugins.hello_world' )
34+
35+ if plugin .is_active :
36+ return mark_safe ('<span class="badge bg-success">Hello World Plugin: Active</span>' )
37+ else :
38+ return mark_safe ('<span class="badge bg-secondary">Hello World Plugin: Inactive</span>' )
39+ except :
40+ return mark_safe ('<span class="badge bg-danger">Hello World Plugin: Not Found</span>' )
41+
42+
43+ @register .inclusion_tag ('hello_world/plugin_info.html' )
44+ def hello_world_info ():
45+ """Display plugin information"""
46+ try :
47+ from plugins .models import PluginManager
48+ plugin = PluginManager .objects .get (app_name = 'plugins.hello_world' )
49+ return {
50+ 'plugin' : plugin ,
51+ 'is_active' : plugin .is_active
52+ }
53+ except :
54+ return {
55+ 'plugin' : None ,
56+ 'is_active' : False
57+ }
0 commit comments