Compare commits
4 Commits
23cb231bdc
...
cef423c3d1
Author | SHA1 | Date | |
---|---|---|---|
cef423c3d1 | |||
f9af3cfefe | |||
20096010b4 | |||
7b2f789724 |
@ -0,0 +1,5 @@
|
||||
# This will make sure the app is always imported when
|
||||
# Django starts so that shared_task will use this app.
|
||||
from .celery import app as celery_app
|
||||
|
||||
__all__ = ('celery_app',)
|
23
api/api/celery.py
Normal file
23
api/api/celery.py
Normal file
@ -0,0 +1,23 @@
|
||||
import os
|
||||
|
||||
from celery import Celery
|
||||
|
||||
# Set the default Django settings module for the 'celery' program.
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'api.settings')
|
||||
|
||||
app = Celery('api')
|
||||
|
||||
|
||||
# Using a string here means the worker doesn't have to serialize
|
||||
# the configuration object to child processes.
|
||||
# - namespace='CELERY' means all celery-related configuration keys
|
||||
# should have a `CELERY_` prefix.
|
||||
app.config_from_object('django.conf:settings', namespace='CELERY')
|
||||
|
||||
# Load task modules from all registered Django apps.
|
||||
app.autodiscover_tasks()
|
||||
|
||||
|
||||
@app.task(bind=True)
|
||||
def debug_task(self):
|
||||
print(f'Request: {self.request!r}')
|
@ -171,6 +171,6 @@ JET_THEMES = [
|
||||
}
|
||||
]
|
||||
|
||||
# JET_INDEX_DASHBOARD = 'jet.dashboard.dashboard.DefaultIndexDashboard'
|
||||
JET_APP_INDEX_DASHBOARD = 'dashboard.CustomIndexDashboard'
|
||||
# JET_INDEX_DASHBOARD = 'dashboard.CustomIndexDashboard'
|
||||
JET_INDEX_DASHBOARD = 'jet.dashboard.dashboard.DefaultIndexDashboard'
|
||||
JET_APP_INDEX_DASHBOARD = 'bills.dashboard.CustomIndexDashboard'
|
||||
# JET_INDEX_DASHBOARD = 'bills.dashboard.CustomIndexDashboard'
|
@ -1,9 +1,32 @@
|
||||
from django.contrib import admin
|
||||
import pendulum
|
||||
|
||||
from .models import Bill
|
||||
from.tasks import get_overdue_bills, get_upcoming_bills
|
||||
|
||||
@admin.action(description='Duplicate Bill')
|
||||
def duplicate(modeladmin, request, queryset):
|
||||
for object in queryset:
|
||||
object.id = None
|
||||
# object.name = object.name+'-duplicate' ## This was temporary while I figured out how to massage the date
|
||||
# print(object.due)
|
||||
new_date = (pendulum.parse(str(object.due), exact=True)).add(months=1)
|
||||
# print(new_date)
|
||||
object.due = new_date
|
||||
object.save()
|
||||
|
||||
@admin.action(description='Duplicate Older Bill')
|
||||
def duplicate_old(modeladmin, request, queryset):
|
||||
for object in queryset:
|
||||
object.id = None
|
||||
new_date = (pendulum.parse(str(object.due), exact=True)).subtract(months=1)
|
||||
object.due = new_date
|
||||
object.save()
|
||||
|
||||
@admin.register(Bill)
|
||||
class BillAdmin(admin.ModelAdmin):
|
||||
list_display = ['name', 'due', 'amount']
|
||||
list_filter = ('name', 'type', 'is_paid', 'is_overdue', 'is_missed')
|
||||
search_fields = ['name', 'type', 'amount']
|
||||
search_fields = ['name', 'type', 'amount'
|
||||
]
|
||||
actions = [duplicate, duplicate_old, get_overdue_bills, get_upcoming_bills]
|
@ -2,7 +2,6 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from jet.dashboard import modules
|
||||
from jet.dashboard.dashboard import Dashboard, AppIndexDashboard
|
||||
|
||||
|
||||
class CustomIndexDashboard(Dashboard):
|
||||
columns = 3
|
||||
|
||||
@ -26,7 +25,19 @@ class CustomIndexDashboard(Dashboard):
|
||||
'url': 'irc://irc.freenode.net/django',
|
||||
'external': True,
|
||||
},
|
||||
{
|
||||
'title': _('COME ON'),
|
||||
'url': 'irc://irc.freenode.net/django',
|
||||
'external': True,
|
||||
},
|
||||
],
|
||||
column=0,
|
||||
order=0
|
||||
))
|
||||
|
||||
self.children.append(modules.ModelList(
|
||||
_('Models'),
|
||||
exclude=('auth.*',),
|
||||
column=0,
|
||||
order=0
|
||||
))
|
35
api/bills/tasks.py
Normal file
35
api/bills/tasks.py
Normal file
@ -0,0 +1,35 @@
|
||||
### Celery Tasks!
|
||||
|
||||
from django.core.checks import messages
|
||||
import pendulum
|
||||
from .models import Bill
|
||||
|
||||
from celery import shared_task
|
||||
|
||||
@shared_task
|
||||
def get_overdue_bills(modeladmin, request, queryset):
|
||||
|
||||
try:
|
||||
bills_list = []
|
||||
bill_request = Bill.objects.filter(is_overdue=True)
|
||||
print(bill_request)
|
||||
for bill in bill_request:
|
||||
# print(bill.id)
|
||||
bills_list.append(bill.id)
|
||||
except Bill.DoesNotExist:
|
||||
bills_list = "There are no bills that are overdue!"
|
||||
print("function complete")
|
||||
print(bills_list)
|
||||
return('This is a test')
|
||||
|
||||
@shared_task
|
||||
def get_upcoming_bills(modeladmin, request, queryset):
|
||||
today = pendulum.today().add(days=7)
|
||||
print(today)
|
||||
try:
|
||||
bill_request = Bill.objects.filter(is_paid=False)
|
||||
print(bill_request)
|
||||
except Bill.DoesNotExist:
|
||||
message = 'There are no bill coming due soon that are unpaid.'
|
||||
print(message)
|
||||
return(message)
|
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
Loading…
Reference in New Issue
Block a user