11import re
2- from django .conf import settings
32from django .db import models
43from django .contrib .contenttypes import generic
54from django .contrib .contenttypes .models import ContentType
65from django .core .urlresolvers import reverse_lazy
76
87from uuidfield import UUIDField
98
10- from .default_settings import WEB_HOOK_OWNER_MODEL , WEB_HOOK_ACTIONS , WEB_HOOK_OWNER_LOCAL
9+ from .settings import WEB_HOOK_ACTIONS , WEB_HOOK_OWNER_LOCAL , OWNER_MODEL
1110
1211from .signals import webhook_triggered_signal
1312
14- # Load defaults
15- if hasattr (settings , 'WEB_HOOK_OWNER_MODEL' ):
16- WEB_HOOK_OWNER_MODEL = settings .WEB_HOOK_OWNER_MODEL
17-
18- if hasattr (settings , 'WEB_HOOK_ACTIONS' ):
19- WEB_HOOK_ACTIONS = settings .WEB_HOOK_ACTIONS
20-
21- if hasattr (settings , 'WEB_HOOK_OWNER_LOCAL' ):
22- WEB_HOOK_OWNER_LOCAL = settings .WEB_HOOK_OWNER_LOCAL
23-
24- # Work out our dynamic relation
25- app_name = WEB_HOOK_OWNER_MODEL .rsplit ('.' , 1 )[0 ]
26- model_name = WEB_HOOK_OWNER_MODEL .rsplit ('.' , 1 )[1 ]
27- module = __import__ (app_name , fromlist = [model_name ])
28- owner_model = getattr (module , model_name )
29-
3013
3114class WebHook (models .Model ):
3215
@@ -39,12 +22,13 @@ class WebHook(models.Model):
3922 )
4023
4124 id = UUIDField (auto = True , primary_key = True )
42- owner = models .ForeignKey (owner_model , editable = False ) # Editable?
25+ owner = models .ForeignKey (OWNER_MODEL , editable = False ) # Editable?
4326 action = models .CharField (max_length = 1 , choices = ACTIONS , default = 'R' )
4427 triggered = models .DateTimeField ("Time Triggered" , auto_now = True )
4528 method = models .CharField (max_length = 1 , choices = TRIGGER_METHOD , default = 'P' )
4629 auth = models .CharField ("API Key" , max_length = 64 , blank = True ) # Not used for G / H requests
47- filter = models .CharField ("Regex Filter Payload" , max_length = 64 , blank = True , help_text = 'Filter which events apply' ) # Not used for HEAD
30+ filter = models .CharField ("Regex Filter Payload" , max_length = 64 , blank = True ,
31+ help_text = 'Filter which events apply' ) # Not used for HEAD
4832
4933 # Following fields are required for using GenericForeignKey
5034 content_type = models .ForeignKey (ContentType )
@@ -96,4 +80,4 @@ def trigger(self):
9680 action = self .action ,
9781 content_object = self .content_object ,
9882 content_type = self .content_type )
99- self .save () # Update triggered field
83+ self .save () # Update ' triggered' timestamp field
0 commit comments