Skip to content

Commit

Permalink
added giving
Browse files Browse the repository at this point in the history
  • Loading branch information
walosha committed Jan 21, 2023
1 parent 13efc72 commit 7d39275
Show file tree
Hide file tree
Showing 19 changed files with 254 additions and 4 deletions.
7 changes: 5 additions & 2 deletions attendance/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ class Attendance (AuditableModel):
class Meta:
ordering = ('-created_at',)

def __str__(self) -> str:
return self.id
def __str__(self):
return str(self.id)

def count(self):
return self.attendees.count()
12 changes: 12 additions & 0 deletions attendance/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@


class AttendanceSerializer(serializers.ModelSerializer):
count = serializers.IntegerField()

class Meta:
model = Attendance
# fields = ('id', 'title', 'description', 'completed')
# Shortcut for getting all fields
fields = '__all__'
extra_fields = ['count']

def get_field_names(self, declared_fields, info):
expanded_fields = super(AttendanceSerializer, self).get_field_names(
declared_fields, info)

if getattr(self.Meta, 'extra_fields', None):
return expanded_fields + self.Meta.extra_fields
else:
return expanded_fields
3 changes: 2 additions & 1 deletion core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"blog",
"poll",
"message",
"siteinfo"
"siteinfo",
"giving"

]
# AUTH_USER_MODEL = "users.CustomUser"
Expand Down
1 change: 1 addition & 0 deletions core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
path('api/events/', include('event.urls')),
path('api/blogs/', include('blog.urls')),
path('api/siteinfo/', include('siteinfo.urls')),
path('api/giving/', include('giving.urls')),
# Optional UI:
path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
path('api/doc/',
Expand Down
Empty file added giving/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions giving/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.contrib import admin
from .models import Giving

admin.site.register(Giving)
6 changes: 6 additions & 0 deletions giving/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class GivingConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'giving'
2 changes: 2 additions & 0 deletions giving/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
STATUS = (("PENDING", "PENDING"), ("PAID", "PAID"),
("FAILED", "FAILED"))
37 changes: 37 additions & 0 deletions giving/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 4.0.8 on 2023-01-21 23:14

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Giving',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('amount', models.IntegerField()),
('title', models.CharField(max_length=100)),
('status', models.CharField(choices=[('PENDING', 'PENDING'), ('PAID', 'PAID'), ('FAILED', 'FAILED')], default='PENDING', max_length=20)),
('note', models.CharField(max_length=256)),
('phone', models.CharField(blank=True, max_length=11, null=True)),
('fullname', models.CharField(blank=True, max_length=100, null=True)),
('email', models.EmailField(max_length=254, unique=True, verbose_name='email address')),
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='given', to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ('-created_at',),
},
),
]
18 changes: 18 additions & 0 deletions giving/migrations/0002_alter_giving_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.8 on 2023-01-21 23:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('giving', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='giving',
name='email',
field=models.EmailField(max_length=254, verbose_name='email address'),
),
]
Empty file added giving/migrations/__init__.py
Empty file.
27 changes: 27 additions & 0 deletions giving/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from django.db import models
from core.models import AuditableModel
from account.models import CustomUser
from .enums import STATUS
# Create your models here.


class Giving (AuditableModel):

user = models.ForeignKey(
CustomUser, on_delete=models.CASCADE, blank=True, null=True, related_name='given')
amount = models.IntegerField(blank=False)
title = models.CharField(max_length=100, blank=False)
status = models.CharField(max_length=20,
choices=STATUS,
default="PENDING")
note = models.CharField(max_length=256)
phone = models.CharField(
max_length=11, blank=True, null=True)
fullname = models.CharField(max_length=100, blank=True, null=True)
email = models.EmailField('email address') # Here

class Meta:
ordering = ('-created_at',)

def __str__(self) -> str:
return self.title
13 changes: 13 additions & 0 deletions giving/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# django #selenium #webscraping
from rest_framework import serializers
from .models import Giving


class GivingSerializer(serializers.ModelSerializer):

class Meta:
model = Giving
fields = '__all__'
extra_kwargs = {
'user': {'read_only': True},
}
3 changes: 3 additions & 0 deletions giving/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
13 changes: 13 additions & 0 deletions giving/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from rest_framework.routers import DefaultRouter
from django.urls import path, include
from .views import GivingListCreateAPIView, GivingRetrieveAPIView, GivingUpdateAPIView, GivingDestroyAPIView

urlpatterns = [
path('<uuid:pk>/', GivingRetrieveAPIView.as_view(),
name="giving_detail"),
path('<uuid:pk>/', GivingUpdateAPIView.as_view(),
name="giving_update"),
path('<uuid:pk>/', GivingDestroyAPIView.as_view(),
name="giving_delete"),
path('', GivingListCreateAPIView.as_view(), name="giving_list")
]
29 changes: 29 additions & 0 deletions giving/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from .models import Giving
from .serializers import GivingSerializer
from rest_framework import generics


class GivingListCreateAPIView(generics.ListCreateAPIView):
queryset = Giving.objects.all()
serializer_class = GivingSerializer

def perform_create(self, serializer):
if self.request.user.is_authenticated:
serializer.save(user=self.request.user)
else:
serializer.save()


class GivingRetrieveAPIView(generics.RetrieveAPIView):
queryset = Giving.objects.all()
serializer_class = GivingSerializer


class GivingUpdateAPIView(generics.UpdateAPIView):
queryset = Giving.objects.all()
serializer_class = GivingSerializer


class GivingDestroyAPIView(generics.DestroyAPIView):
queryset = Giving.objects.all()
serializer_class = GivingSerializer
2 changes: 1 addition & 1 deletion message/enums.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
QUESTION_TYPES = (("PRAYER_REQUEST", "PRAYER_REQUEST"), ("COUNSELLING", "COUNSELLING"),
("OTHERS", "OTHERS"), ("WHISTLEBLOWING", "WHISTLEBLOWING"), ("SUGGESTION", "SUGGESTION"))
("OTHERS", "OTHERS"), ("WHISTLEBLOWING", "WHISTLEBLOWING"), ("SUGGESTION", "SUGGESTION"), ("TESTIMONY", "TESTIMONY"))
18 changes: 18 additions & 0 deletions message/migrations/0006_alter_message_message_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.8 on 2023-01-21 23:14

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('message', '0005_alter_message_fullname'),
]

operations = [
migrations.AlterField(
model_name='message',
name='message_type',
field=models.CharField(choices=[('PRAYER_REQUEST', 'PRAYER_REQUEST'), ('COUNSELLING', 'COUNSELLING'), ('OTHERS', 'OTHERS'), ('WHISTLEBLOWING', 'WHISTLEBLOWING'), ('SUGGESTION', 'SUGGESTION'), ('TESTIMONY', 'TESTIMONY')], max_length=20),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Generated by Django 4.0.8 on 2023-01-21 23:14

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('siteinfo', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='siteinfo',
name='audio1',
field=models.FileField(blank=True, null=True, upload_to='audio/'),
),
migrations.AlterField(
model_name='siteinfo',
name='audio2',
field=models.FileField(blank=True, null=True, upload_to='audio/'),
),
migrations.AlterField(
model_name='siteinfo',
name='audio3',
field=models.FileField(blank=True, null=True, upload_to='audio/'),
),
migrations.AlterField(
model_name='siteinfo',
name='image2',
field=models.ImageField(blank=True, null=True, upload_to='site/%Y/%m/%d/'),
),
migrations.AlterField(
model_name='siteinfo',
name='image3',
field=models.ImageField(blank=True, null=True, upload_to='site/%Y/%m/%d/'),
),
migrations.AlterField(
model_name='siteinfo',
name='image4',
field=models.ImageField(blank=True, null=True, upload_to='site/%Y/%m/%d/'),
),
migrations.AlterField(
model_name='siteinfo',
name='image5',
field=models.ImageField(blank=True, null=True, upload_to='site/%Y/%m/%d/'),
),
migrations.AlterField(
model_name='siteinfo',
name='video1',
field=models.FileField(blank=True, null=True, upload_to='videos/'),
),
migrations.AlterField(
model_name='siteinfo',
name='video2',
field=models.FileField(blank=True, null=True, upload_to='videos/'),
),
migrations.AlterField(
model_name='siteinfo',
name='video3',
field=models.FileField(blank=True, null=True, upload_to='videos/'),
),
]

0 comments on commit 7d39275

Please sign in to comment.