BO 1.34
This commit is contained in:
@@ -77,7 +77,8 @@ class CustomerAdmin(admin.ModelAdmin):
|
||||
def get_urls(self):
|
||||
urls = super().get_urls()
|
||||
my_urls = [
|
||||
path('mautic/', self.run_mautic),
|
||||
path('mautic_lang/', self.run_mautic),
|
||||
path('mautic_trial/', self.run_mautic_trial),
|
||||
path('notif/', self.run_notif),
|
||||
]
|
||||
return my_urls + urls
|
||||
@@ -89,7 +90,12 @@ class CustomerAdmin(admin.ModelAdmin):
|
||||
def run_mautic(self, request):
|
||||
mautic = Mautic()
|
||||
mautic.syncLang()
|
||||
return HttpResponseRedirect("../")
|
||||
return HttpResponseRedirect("../")
|
||||
|
||||
def run_mautic_trial(self, request):
|
||||
mautic = Mautic()
|
||||
mautic.syncTrial()
|
||||
return HttpResponseRedirect("../")
|
||||
|
||||
|
||||
admin.site.register(Customer, CustomerAdmin)
|
||||
|
||||
@@ -52,6 +52,40 @@ class Mautic:
|
||||
|
||||
print( "Syncronised customer count: " + str(index))
|
||||
return True
|
||||
|
||||
def syncTrial(self):
|
||||
qs = Customer.objects.raw('SELECT * from customer WHERE trial_date is not null and trial_date_sync is null')
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.info("Syncronising trial date...")
|
||||
|
||||
headers = {
|
||||
'content-type': "application/x-www-form-urlencoded",
|
||||
'cache-control': "no-cache"
|
||||
}
|
||||
index = 0
|
||||
for customer in qs:
|
||||
data = "mauticform[email]=" + customer.email + \
|
||||
"&mauticform[database_id]=" + str(customer.customer_id) + \
|
||||
"&mauticform[trialdate]=" + str(customer.trial_date) + \
|
||||
"&mauticform[formId]=3" + \
|
||||
"&mauticform[formName]=appdatachange"
|
||||
|
||||
print(data)
|
||||
|
||||
form_url = 'https://mautic.aitrainer.app/form/submit?formId=3'
|
||||
response = requests.post(form_url, data=data.encode('utf-8'), headers=headers)
|
||||
print(customer.email + " " +str(response.status_code))
|
||||
|
||||
if response.status_code == 200:
|
||||
with connections["live"].cursor() as cursor:
|
||||
cursor.execute("UPDATE customer SET trial_date_sync = NOW() WHERE customer_id="
|
||||
+ str(customer.customer_id))
|
||||
print(f'customer {customer.customer_id} is updated')
|
||||
|
||||
index = index + 1
|
||||
|
||||
print( "Syncronised customer count: " + str(index))
|
||||
return True
|
||||
|
||||
|
||||
def sync(self):
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from ..automation.notification import NotificationExec
|
||||
from ..automation.mautic import Mautic
|
||||
from django_cron import CronJobBase, Schedule
|
||||
import datetime
|
||||
|
||||
@@ -25,3 +26,16 @@ class NotificationJob(CronJobBase):
|
||||
print(datetime.datetime.now(), " *** END notification ")
|
||||
|
||||
|
||||
class TrialJob(CronJobBase):
|
||||
|
||||
RUN_EVERY_MINS = 60
|
||||
schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
|
||||
code = 'aitrainer_backoffice.controlling.trial_sync' # a unique code
|
||||
|
||||
def do(self):
|
||||
print(datetime.datetime.now(), " *** START trial sync ")
|
||||
mautic = Mautic()
|
||||
mautic.syncTrial()
|
||||
print(datetime.datetime.now(), " *** END trial sync ")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user