Compare commits

...

4 Commits

Author SHA1 Message Date
cef423c3d1 Add latest Bill functions 2022-01-04 18:37:12 -05:00
f9af3cfefe Add Get Overdue Bills 2021-12-14 01:04:49 -05:00
20096010b4 Add Celery Support
This needs to be tested on a linux host - windows not supported
2021-12-13 15:21:44 -05:00
7b2f789724 Install Celery 2021-12-13 14:46:56 -05:00
7 changed files with 102 additions and 5 deletions

View File

@ -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
View 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}')

View File

@ -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'

View File

@ -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]

View File

@ -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
View 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)

Binary file not shown.