Browse Source

Allow to customize the ip allocation message

Alexandre Aubin 6 years ago
parent
commit
1d5ae72f40
3 changed files with 10 additions and 6 deletions
  1. 1 0
      README.md
  2. 5 6
      coin/configuration/models.py
  3. 4 0
      coin/settings_base.py

+ 1 - 0
README.md

@@ -349,6 +349,7 @@ List of available settings in your `settings_local.py` file.
 - `HANDLE_BALANCE`: Allows to handle money balances for members (False default)
 - `INVOICES_INCLUDE_CONFIG_COMMENTS`: Add comment related to a subscription configuration when generating invoices
 - `MEMBER_CAN_EDIT_VPN_CONF`: Allow members to edit some part of their vpn configuration
+- `IP_ALLOCATION_MESSAGE`: Template string that will be used to log IP allocation in the corresponding coin.subnets logging system
 - `DEBUG` : Enable debug for development **do not use in production** : display
    stracktraces and enable [django-debug-toolbar](https://django-debug-toolbar.readthedocs.io).
 

+ 5 - 6
coin/configuration/models.py

@@ -9,6 +9,7 @@ from coin.offers.models import OfferSubscription
 from django.db.models.signals import post_save, post_delete
 from django.core.exceptions import ObjectDoesNotExist
 from django.dispatch import receiver
+from django.conf import settings
 
 from coin.resources.models import IPSubnet
 
@@ -139,21 +140,19 @@ def subnet_event(sender, **kwargs):
             config.subnet_event()
 
         offer = config.offersubscription.offer.name
-        subref = config.offersubscription.get_subscription_reference()
+        ref = config.offersubscription.get_subscription_reference()
         member = config.offersubscription.member
         ip = subnet.inet
 
         if kwargs['signal_type'] == "save":
-            msg = "Allocating IP %s to member %s (%s - %s %s) (for offer %s, %s)"
+            msg = "[Allocating IP] " + settings.IP_ALLOCATION_MESSAGE
         elif kwargs['signal_type'] == "delete":
-            msg = "Deallocating IP %s from member %s (%s - %s %s) (was offer %s, %s)"
+            msg = "[Deallocating IP] " + settings.IP_ALLOCATION_MESSAGE
         else:
             # Does not happens
             msg = ""
 
-        subnet_log.info(msg % (ip, str(member.pk),
-                        member.username, member.first_name, member.last_name,
-                        offer, subref))
+        subnet_log.info(msg.format(ip=ip, member=member, offer=offer, ref=ref))
 
     except ObjectDoesNotExist:
         pass

+ 4 - 0
coin/settings_base.py

@@ -302,3 +302,7 @@ HANDLE_BALANCE = False
 
 # Add subscription comments in invoice items
 INVOICES_INCLUDE_CONFIG_COMMENTS = True
+
+# String template used for the IP allocation log (c.f. coin.subnet loggers
+# This will get prefixed by [Allocating IP] or [Desallocating IP]
+IP_ALLOCATION_MESSAGE = "{ip} to {member.pk} ({member.username} - {member.first_name} {member.last_name}) (for offer {offer}, {ref})"