Spaces:
Running
Running
Upload 167 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +35 -0
- api/__pycache__/models.cpython-39.pyc +0 -0
- api/__pycache__/urls.cpython-39.pyc +0 -0
- api/__pycache__/utils.cpython-39.pyc +0 -0
- api/__pycache__/views.cpython-39.pyc +0 -0
- api/metadata.json +0 -0
- api/migrations/0013_bhagat_profile_image_alter_bhagat_user_type_and_more.py +47 -0
- api/migrations/0014_rename_address_bhagat_streetname_bhagat_city_and_more.py +37 -0
- api/migrations/0015_alter_bhagat_phone.py +17 -0
- api/migrations/__pycache__/0013_bhagat_profile_image_alter_bhagat_user_type_and_more.cpython-39.pyc +0 -0
- api/migrations/__pycache__/0014_rename_address_bhagat_streetname_bhagat_city_and_more.cpython-39.pyc +0 -0
- api/migrations/__pycache__/0015_alter_bhagat_phone.cpython-39.pyc +0 -0
- api/models.py +7 -3
- api/urls.py +9 -1
- api/utils.py +77 -0
- api/views.py +234 -17
- data.json +0 -0
- dataparser.py +14 -0
- db.sqlite3 +0 -0
- downloads/1.jpg +3 -0
- downloads/10.png +0 -0
- downloads/100.png +3 -0
- downloads/101.png +3 -0
- downloads/102.png +3 -0
- downloads/103.png +3 -0
- downloads/104.png +3 -0
- downloads/105.png +3 -0
- downloads/106.png +3 -0
- downloads/107.png +3 -0
- downloads/108.png +3 -0
- downloads/109.jpg +0 -0
- downloads/11.png +3 -0
- downloads/110.jpg +3 -0
- downloads/111.jpg +0 -0
- downloads/112.jpg +3 -0
- downloads/113.jpg +0 -0
- downloads/114.jpg +0 -0
- downloads/115.jpg +0 -0
- downloads/116.jpg +3 -0
- downloads/117.jpg +0 -0
- downloads/118.jpg +0 -0
- downloads/119.jpg +0 -0
- downloads/12.png +0 -0
- downloads/120.jpg +0 -0
- downloads/121.jpg +0 -0
- downloads/122.jpg +0 -0
- downloads/123.jpg +0 -0
- downloads/124.jpg +0 -0
- downloads/125.jpg +3 -0
- downloads/126.jpg +0 -0
.gitattributes
CHANGED
@@ -33,3 +33,38 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
downloads/1.jpg filter=lfs diff=lfs merge=lfs -text
|
37 |
+
downloads/100.png filter=lfs diff=lfs merge=lfs -text
|
38 |
+
downloads/101.png filter=lfs diff=lfs merge=lfs -text
|
39 |
+
downloads/102.png filter=lfs diff=lfs merge=lfs -text
|
40 |
+
downloads/103.png filter=lfs diff=lfs merge=lfs -text
|
41 |
+
downloads/104.png filter=lfs diff=lfs merge=lfs -text
|
42 |
+
downloads/105.png filter=lfs diff=lfs merge=lfs -text
|
43 |
+
downloads/106.png filter=lfs diff=lfs merge=lfs -text
|
44 |
+
downloads/107.png filter=lfs diff=lfs merge=lfs -text
|
45 |
+
downloads/108.png filter=lfs diff=lfs merge=lfs -text
|
46 |
+
downloads/11.png filter=lfs diff=lfs merge=lfs -text
|
47 |
+
downloads/110.jpg filter=lfs diff=lfs merge=lfs -text
|
48 |
+
downloads/112.jpg filter=lfs diff=lfs merge=lfs -text
|
49 |
+
downloads/116.jpg filter=lfs diff=lfs merge=lfs -text
|
50 |
+
downloads/125.jpg filter=lfs diff=lfs merge=lfs -text
|
51 |
+
downloads/127.jpg filter=lfs diff=lfs merge=lfs -text
|
52 |
+
downloads/13.png filter=lfs diff=lfs merge=lfs -text
|
53 |
+
downloads/130.jpg filter=lfs diff=lfs merge=lfs -text
|
54 |
+
downloads/134.jpg filter=lfs diff=lfs merge=lfs -text
|
55 |
+
downloads/136.jpg filter=lfs diff=lfs merge=lfs -text
|
56 |
+
downloads/139.jpg filter=lfs diff=lfs merge=lfs -text
|
57 |
+
downloads/150.jpg filter=lfs diff=lfs merge=lfs -text
|
58 |
+
downloads/151.jpg filter=lfs diff=lfs merge=lfs -text
|
59 |
+
downloads/157.jpg filter=lfs diff=lfs merge=lfs -text
|
60 |
+
downloads/160.jpg filter=lfs diff=lfs merge=lfs -text
|
61 |
+
downloads/166.jpg filter=lfs diff=lfs merge=lfs -text
|
62 |
+
downloads/168.jpg filter=lfs diff=lfs merge=lfs -text
|
63 |
+
downloads/169.jpg filter=lfs diff=lfs merge=lfs -text
|
64 |
+
downloads/173.jpg filter=lfs diff=lfs merge=lfs -text
|
65 |
+
downloads/177.jpg filter=lfs diff=lfs merge=lfs -text
|
66 |
+
downloads/18.png filter=lfs diff=lfs merge=lfs -text
|
67 |
+
downloads/183.jpg filter=lfs diff=lfs merge=lfs -text
|
68 |
+
downloads/186.jpg filter=lfs diff=lfs merge=lfs -text
|
69 |
+
downloads/187.jpg filter=lfs diff=lfs merge=lfs -text
|
70 |
+
downloads/189.jpg filter=lfs diff=lfs merge=lfs -text
|
api/__pycache__/models.cpython-39.pyc
CHANGED
Binary files a/api/__pycache__/models.cpython-39.pyc and b/api/__pycache__/models.cpython-39.pyc differ
|
|
api/__pycache__/urls.cpython-39.pyc
CHANGED
Binary files a/api/__pycache__/urls.cpython-39.pyc and b/api/__pycache__/urls.cpython-39.pyc differ
|
|
api/__pycache__/utils.cpython-39.pyc
ADDED
Binary file (2.21 kB). View file
|
|
api/__pycache__/views.cpython-39.pyc
CHANGED
Binary files a/api/__pycache__/views.cpython-39.pyc and b/api/__pycache__/views.cpython-39.pyc differ
|
|
api/metadata.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
api/migrations/0013_bhagat_profile_image_alter_bhagat_user_type_and_more.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Generated by Django 4.2.16 on 2024-10-18 14:03
|
2 |
+
|
3 |
+
from django.db import migrations, models
|
4 |
+
|
5 |
+
|
6 |
+
class Migration(migrations.Migration):
|
7 |
+
dependencies = [
|
8 |
+
("api", "0012_notification_title"),
|
9 |
+
]
|
10 |
+
|
11 |
+
operations = [
|
12 |
+
migrations.AddField(
|
13 |
+
model_name="bhagat",
|
14 |
+
name="profile_image",
|
15 |
+
field=models.URLField(blank=True),
|
16 |
+
),
|
17 |
+
migrations.AlterField(
|
18 |
+
model_name="bhagat",
|
19 |
+
name="user_type",
|
20 |
+
field=models.CharField(
|
21 |
+
choices=[
|
22 |
+
("superadmin", "Super Admin"),
|
23 |
+
("regionadmin", "Region Admin"),
|
24 |
+
("karyakarta", "Karyakarta"),
|
25 |
+
("user", "User"),
|
26 |
+
],
|
27 |
+
default="user",
|
28 |
+
max_length=20,
|
29 |
+
),
|
30 |
+
),
|
31 |
+
migrations.AlterField(
|
32 |
+
model_name="notification",
|
33 |
+
name="notification_type",
|
34 |
+
field=models.CharField(
|
35 |
+
choices=[
|
36 |
+
("orange", "Shabha"),
|
37 |
+
("green", "Activity"),
|
38 |
+
("blue", "Birthday"),
|
39 |
+
("red", "Important"),
|
40 |
+
("purple", "Gathering"),
|
41 |
+
("yellow", "Festival"),
|
42 |
+
("pink", "Custom"),
|
43 |
+
],
|
44 |
+
max_length=20,
|
45 |
+
),
|
46 |
+
),
|
47 |
+
]
|
api/migrations/0014_rename_address_bhagat_streetname_bhagat_city_and_more.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Generated by Django 4.2.16 on 2024-10-20 12:26
|
2 |
+
|
3 |
+
from django.db import migrations, models
|
4 |
+
|
5 |
+
|
6 |
+
class Migration(migrations.Migration):
|
7 |
+
dependencies = [
|
8 |
+
("api", "0013_bhagat_profile_image_alter_bhagat_user_type_and_more"),
|
9 |
+
]
|
10 |
+
|
11 |
+
operations = [
|
12 |
+
migrations.RenameField(
|
13 |
+
model_name="bhagat",
|
14 |
+
old_name="address",
|
15 |
+
new_name="streetName",
|
16 |
+
),
|
17 |
+
migrations.AddField(
|
18 |
+
model_name="bhagat",
|
19 |
+
name="city",
|
20 |
+
field=models.CharField(max_length=100, null=True),
|
21 |
+
),
|
22 |
+
migrations.AddField(
|
23 |
+
model_name="bhagat",
|
24 |
+
name="country",
|
25 |
+
field=models.CharField(max_length=100, null=True),
|
26 |
+
),
|
27 |
+
migrations.AddField(
|
28 |
+
model_name="bhagat",
|
29 |
+
name="pincode",
|
30 |
+
field=models.CharField(max_length=10, null=True),
|
31 |
+
),
|
32 |
+
migrations.AddField(
|
33 |
+
model_name="bhagat",
|
34 |
+
name="state",
|
35 |
+
field=models.CharField(max_length=100, null=True),
|
36 |
+
),
|
37 |
+
]
|
api/migrations/0015_alter_bhagat_phone.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Generated by Django 4.2.16 on 2024-10-27 14:47
|
2 |
+
|
3 |
+
from django.db import migrations, models
|
4 |
+
|
5 |
+
|
6 |
+
class Migration(migrations.Migration):
|
7 |
+
dependencies = [
|
8 |
+
("api", "0014_rename_address_bhagat_streetname_bhagat_city_and_more"),
|
9 |
+
]
|
10 |
+
|
11 |
+
operations = [
|
12 |
+
migrations.AlterField(
|
13 |
+
model_name="bhagat",
|
14 |
+
name="phone",
|
15 |
+
field=models.CharField(max_length=20, null=True),
|
16 |
+
),
|
17 |
+
]
|
api/migrations/__pycache__/0013_bhagat_profile_image_alter_bhagat_user_type_and_more.cpython-39.pyc
ADDED
Binary file (1.06 kB). View file
|
|
api/migrations/__pycache__/0014_rename_address_bhagat_streetname_bhagat_city_and_more.cpython-39.pyc
ADDED
Binary file (883 Bytes). View file
|
|
api/migrations/__pycache__/0015_alter_bhagat_phone.cpython-39.pyc
ADDED
Binary file (635 Bytes). View file
|
|
api/models.py
CHANGED
@@ -17,12 +17,17 @@ class Bhagat(AbstractUser):
|
|
17 |
('youvak', 'Youvak'),
|
18 |
)
|
19 |
user_type = models.CharField(max_length=20, choices=USER_TYPES, default="user")
|
20 |
-
phone = models.CharField(max_length=
|
21 |
member_type = models.CharField(max_length=20, choices=MEMBER_TYPES, default="youvak")
|
22 |
region = models.ForeignKey('Region', on_delete=models.SET_NULL, null=True)
|
23 |
birthday = models.DateField(default=DateTime.date.today, null=True)
|
24 |
-
|
|
|
|
|
|
|
|
|
25 |
assigned_to = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, related_name='assigned_users')
|
|
|
26 |
|
27 |
def __str__(self):
|
28 |
return self.first_name + ' ' + self.last_name
|
@@ -82,7 +87,6 @@ class Bhajan(models.Model):
|
|
82 |
isGer = models.BooleanField(default=False)
|
83 |
isAudio = models.BooleanField(default=False)
|
84 |
|
85 |
-
|
86 |
def __str__(self):
|
87 |
return self.title
|
88 |
|
|
|
17 |
('youvak', 'Youvak'),
|
18 |
)
|
19 |
user_type = models.CharField(max_length=20, choices=USER_TYPES, default="user")
|
20 |
+
phone = models.CharField(max_length=20, null=True)
|
21 |
member_type = models.CharField(max_length=20, choices=MEMBER_TYPES, default="youvak")
|
22 |
region = models.ForeignKey('Region', on_delete=models.SET_NULL, null=True)
|
23 |
birthday = models.DateField(default=DateTime.date.today, null=True)
|
24 |
+
streetName = models.TextField(null=True)
|
25 |
+
city = models.CharField(max_length=100, null=True)
|
26 |
+
state = models.CharField(max_length=100, null=True)
|
27 |
+
country = models.CharField(max_length=100, null=True)
|
28 |
+
pincode = models.CharField(max_length=10, null=True)
|
29 |
assigned_to = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, related_name='assigned_users')
|
30 |
+
profile_image = models.URLField(blank=True)
|
31 |
|
32 |
def __str__(self):
|
33 |
return self.first_name + ' ' + self.last_name
|
|
|
87 |
isGer = models.BooleanField(default=False)
|
88 |
isAudio = models.BooleanField(default=False)
|
89 |
|
|
|
90 |
def __str__(self):
|
91 |
return self.title
|
92 |
|
api/urls.py
CHANGED
@@ -1,13 +1,21 @@
|
|
1 |
from django.urls import path
|
2 |
from . import views
|
|
|
3 |
|
4 |
urlpatterns = [
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
path('dataEntry/', views.dataEntry, name='dataEntry'),
|
6 |
path('send-notification/', views.send_notification, name='send_notification'),
|
7 |
|
8 |
path('bhajan-category-list/', views.bhajanCategoryList, name='bhajanCategoryList'),
|
9 |
path('bhajan-detail/<int:id>', views.bhajanDetail, name='bhajanDetail'),
|
10 |
path('event-list/', views.eventList, name='eventList'),
|
11 |
-
path('notification
|
12 |
|
|
|
13 |
]
|
|
|
1 |
from django.urls import path
|
2 |
from . import views
|
3 |
+
from rest_framework_simplejwt.views import TokenRefreshView
|
4 |
|
5 |
urlpatterns = [
|
6 |
+
path('login/', views.login, name='login'),
|
7 |
+
path('logout/', views.logout, name='logout'),
|
8 |
+
path('get-user-profile/', views.get_user_profile, name='get_user_profile'),
|
9 |
+
path('profile-updater/', views.profile_updater, name='profile_updater'),
|
10 |
+
path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
|
11 |
+
|
12 |
path('dataEntry/', views.dataEntry, name='dataEntry'),
|
13 |
path('send-notification/', views.send_notification, name='send_notification'),
|
14 |
|
15 |
path('bhajan-category-list/', views.bhajanCategoryList, name='bhajanCategoryList'),
|
16 |
path('bhajan-detail/<int:id>', views.bhajanDetail, name='bhajanDetail'),
|
17 |
path('event-list/', views.eventList, name='eventList'),
|
18 |
+
path('notification/', views.notification, name='notification'),
|
19 |
|
20 |
+
path('bhakto-list/', views.bhaktoList, name='bhaktoList'),
|
21 |
]
|
api/utils.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from rest_framework_simplejwt.tokens import AccessToken
|
2 |
+
from rest_framework_simplejwt.exceptions import TokenError, InvalidToken
|
3 |
+
from django.conf import settings
|
4 |
+
from functools import wraps
|
5 |
+
from rest_framework.response import Response
|
6 |
+
from rest_framework import status
|
7 |
+
from rest_framework_simplejwt.authentication import JWTAuthentication
|
8 |
+
from .models import Bhagat
|
9 |
+
from django.http import JsonResponse
|
10 |
+
|
11 |
+
|
12 |
+
def get_token_from_request(request):
|
13 |
+
"""Extract token from Authorization header"""
|
14 |
+
auth_header = request.META.get('HTTP_AUTHORIZATION', '')
|
15 |
+
if auth_header.startswith('Bearer '):
|
16 |
+
return auth_header.split(' ')[1]
|
17 |
+
return None
|
18 |
+
|
19 |
+
|
20 |
+
def validate_jwt_token(token):
|
21 |
+
"""Validate a JWT token and return the user"""
|
22 |
+
try:
|
23 |
+
if not token:
|
24 |
+
return None
|
25 |
+
|
26 |
+
# Validate token
|
27 |
+
valid_token = AccessToken(token)
|
28 |
+
|
29 |
+
# Get user from token
|
30 |
+
user_id = valid_token.payload.get('user_id')
|
31 |
+
if not user_id:
|
32 |
+
return None
|
33 |
+
|
34 |
+
# Get user from database
|
35 |
+
user = Bhagat.objects.filter(id=user_id).first()
|
36 |
+
return user
|
37 |
+
|
38 |
+
except (TokenError, InvalidToken):
|
39 |
+
return None
|
40 |
+
|
41 |
+
|
42 |
+
def jwt_required(allowed_user_types=None):
|
43 |
+
"""
|
44 |
+
Decorator for views that require JWT authentication
|
45 |
+
Optional: Pass allowed_user_types as a list to restrict access to specific user types
|
46 |
+
"""
|
47 |
+
def decorator(view_func):
|
48 |
+
@wraps(view_func)
|
49 |
+
def wrapped_view(request, *args, **kwargs):
|
50 |
+
# Get token from header
|
51 |
+
token = get_token_from_request(request)
|
52 |
+
if not token:
|
53 |
+
return JsonResponse({
|
54 |
+
"error": "No authentication token provided",
|
55 |
+
"status": "error"
|
56 |
+
})
|
57 |
+
|
58 |
+
# Validate token and get user
|
59 |
+
user = validate_jwt_token(token)
|
60 |
+
if not user:
|
61 |
+
return JsonResponse({
|
62 |
+
"error": "Invalid or expired token",
|
63 |
+
"status": "error"
|
64 |
+
})
|
65 |
+
|
66 |
+
# Check user type if specified
|
67 |
+
if allowed_user_types and user.user_type not in allowed_user_types:
|
68 |
+
return JsonResponse({
|
69 |
+
"error": "Unauthorized access",
|
70 |
+
"status": "error"
|
71 |
+
})
|
72 |
+
|
73 |
+
# Add user to request
|
74 |
+
request.user = user
|
75 |
+
return view_func(request, *args, **kwargs)
|
76 |
+
return wrapped_view
|
77 |
+
return decorator
|
api/views.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from django.shortcuts import render, get_object_or_404, redirect
|
2 |
from django.contrib.auth.decorators import login_required, user_passes_test
|
3 |
from django.http import JsonResponse, HttpResponse
|
@@ -5,6 +6,21 @@ from django.views.decorators.http import require_POST
|
|
5 |
from django.utils import timezone
|
6 |
import json
|
7 |
from .models import Bhagat, Event, Attendance, Notification, Region, BhajanCategory, Bhajan
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
|
10 |
def is_superadmin(user):
|
@@ -18,6 +34,7 @@ def is_regionadmin(user):
|
|
18 |
def is_monitor(user):
|
19 |
return user.user_type == 'monitor'
|
20 |
|
|
|
21 |
def dataEntry(request):
|
22 |
# with open("./api/bhajanData.json", "r",encoding="utf-8") as f:
|
23 |
# data = json.load(f)["Prasang"]
|
@@ -37,6 +54,7 @@ def dataEntry(request):
|
|
37 |
# print(bhajan['title'])
|
38 |
return HttpResponse("Data Entry Page")
|
39 |
|
|
|
40 |
def bhajanCategoryList(request):
|
41 |
categories = BhajanCategory.objects.all()
|
42 |
bhajans = Bhajan.objects.all()
|
@@ -64,7 +82,8 @@ def bhajanCategoryList(request):
|
|
64 |
audioBase = "https://huggingface.co/spaces/thejagstudio/MusicStore/resolve/main/Bhajan Audio/"
|
65 |
return JsonResponse({"categories": categoryArr, "bhajans": bhajanArr, "lyricsBase": lyricsBase, "audioBase": audioBase})
|
66 |
|
67 |
-
|
|
|
68 |
bhajan = Bhajan.objects.get(bhajanId=id)
|
69 |
if bhajan is None:
|
70 |
return JsonResponse({"error": "Bhajan not found"})
|
@@ -93,36 +112,38 @@ def eventList(request):
|
|
93 |
# convert date to Sept 26,2024 | 8:30 - 9:30
|
94 |
dateFormatted = event.date.strftime("%b %d, %Y") + " | " + event.date.strftime("%I:%M %p") + " - " + event.time.strftime("%I:%M %p")
|
95 |
eventArr.append({
|
96 |
-
"title":event.title,
|
97 |
-
"description":event.description,
|
98 |
"date": dateFormatted,
|
99 |
-
"day":int(event.date.strftime("%d")),
|
100 |
-
"month":int(event.date.strftime("%m")),
|
101 |
-
"year":int(event.date.strftime("%Y")),
|
102 |
-
"created_by":event.created_by.__str__(),
|
103 |
-
"region":event.region.name,
|
104 |
-
"is_approved":event.is_approved,
|
105 |
-
"color":event.color
|
106 |
})
|
107 |
return JsonResponse({"events": eventArr})
|
108 |
|
109 |
-
|
|
|
110 |
notifications = Notification.objects.all()
|
111 |
notificationArr = []
|
112 |
for notification in notifications:
|
113 |
notificationArr.append({
|
114 |
-
"sender":notification.sender.__str__(),
|
115 |
"category": notification.sender.user_type,
|
116 |
-
"title":notification.title,
|
117 |
-
"content":notification.content,
|
118 |
-
"timestamp":notification.timestamp.strftime("%b %d, %Y | %I:%M %p"),
|
119 |
-
"notification_type":notification.notification_type
|
120 |
})
|
121 |
return JsonResponse({"notifications": notificationArr})
|
122 |
|
123 |
|
124 |
-
|
125 |
@user_passes_test(is_superadmin)
|
|
|
|
|
126 |
def send_notification(request):
|
127 |
if request.method == 'POST':
|
128 |
content = request.POST.get('content')
|
@@ -150,3 +171,199 @@ def birthday_notifications():
|
|
150 |
notification_type='birthday'
|
151 |
)
|
152 |
notification.recipients.set(Bhagat.objects.all())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from django.views.decorators.csrf import csrf_exempt
|
2 |
from django.shortcuts import render, get_object_or_404, redirect
|
3 |
from django.contrib.auth.decorators import login_required, user_passes_test
|
4 |
from django.http import JsonResponse, HttpResponse
|
|
|
6 |
from django.utils import timezone
|
7 |
import json
|
8 |
from .models import Bhagat, Event, Attendance, Notification, Region, BhajanCategory, Bhajan
|
9 |
+
from django.conf import settings
|
10 |
+
import requests
|
11 |
+
|
12 |
+
from rest_framework.decorators import api_view, permission_classes
|
13 |
+
from rest_framework.permissions import AllowAny
|
14 |
+
from rest_framework.response import Response
|
15 |
+
from .utils import jwt_required
|
16 |
+
from rest_framework_simplejwt.tokens import RefreshToken
|
17 |
+
|
18 |
+
|
19 |
+
def gCaptchaVerifer(token):
|
20 |
+
secret_key = settings.RECAPTCHA_SECRET_KEY
|
21 |
+
data = {"response": token, "secret": secret_key}
|
22 |
+
resp = requests.post("https://www.google.com/recaptcha/api/siteverify", data=data)
|
23 |
+
return resp.json()
|
24 |
|
25 |
|
26 |
def is_superadmin(user):
|
|
|
34 |
def is_monitor(user):
|
35 |
return user.user_type == 'monitor'
|
36 |
|
37 |
+
|
38 |
def dataEntry(request):
|
39 |
# with open("./api/bhajanData.json", "r",encoding="utf-8") as f:
|
40 |
# data = json.load(f)["Prasang"]
|
|
|
54 |
# print(bhajan['title'])
|
55 |
return HttpResponse("Data Entry Page")
|
56 |
|
57 |
+
|
58 |
def bhajanCategoryList(request):
|
59 |
categories = BhajanCategory.objects.all()
|
60 |
bhajans = Bhajan.objects.all()
|
|
|
82 |
audioBase = "https://huggingface.co/spaces/thejagstudio/MusicStore/resolve/main/Bhajan Audio/"
|
83 |
return JsonResponse({"categories": categoryArr, "bhajans": bhajanArr, "lyricsBase": lyricsBase, "audioBase": audioBase})
|
84 |
|
85 |
+
|
86 |
+
def bhajanDetail(request, id):
|
87 |
bhajan = Bhajan.objects.get(bhajanId=id)
|
88 |
if bhajan is None:
|
89 |
return JsonResponse({"error": "Bhajan not found"})
|
|
|
112 |
# convert date to Sept 26,2024 | 8:30 - 9:30
|
113 |
dateFormatted = event.date.strftime("%b %d, %Y") + " | " + event.date.strftime("%I:%M %p") + " - " + event.time.strftime("%I:%M %p")
|
114 |
eventArr.append({
|
115 |
+
"title": event.title,
|
116 |
+
"description": event.description,
|
117 |
"date": dateFormatted,
|
118 |
+
"day": int(event.date.strftime("%d")),
|
119 |
+
"month": int(event.date.strftime("%m")),
|
120 |
+
"year": int(event.date.strftime("%Y")),
|
121 |
+
"created_by": event.created_by.__str__(),
|
122 |
+
"region": event.region.name,
|
123 |
+
"is_approved": event.is_approved,
|
124 |
+
"color": event.color
|
125 |
})
|
126 |
return JsonResponse({"events": eventArr})
|
127 |
|
128 |
+
@jwt_required()
|
129 |
+
def notification(request):
|
130 |
notifications = Notification.objects.all()
|
131 |
notificationArr = []
|
132 |
for notification in notifications:
|
133 |
notificationArr.append({
|
134 |
+
"sender": notification.sender.__str__(),
|
135 |
"category": notification.sender.user_type,
|
136 |
+
"title": notification.title,
|
137 |
+
"content": notification.content,
|
138 |
+
"timestamp": notification.timestamp.strftime("%b %d, %Y | %I:%M %p"),
|
139 |
+
"notification_type": notification.notification_type
|
140 |
})
|
141 |
return JsonResponse({"notifications": notificationArr})
|
142 |
|
143 |
|
|
|
144 |
@user_passes_test(is_superadmin)
|
145 |
+
@csrf_exempt
|
146 |
+
@jwt_required()
|
147 |
def send_notification(request):
|
148 |
if request.method == 'POST':
|
149 |
content = request.POST.get('content')
|
|
|
171 |
notification_type='birthday'
|
172 |
)
|
173 |
notification.recipients.set(Bhagat.objects.all())
|
174 |
+
|
175 |
+
|
176 |
+
@csrf_exempt
|
177 |
+
def login(request):
|
178 |
+
if request.method == 'POST':
|
179 |
+
username = request.POST.get('username')
|
180 |
+
password = request.POST.get('password')
|
181 |
+
captcha_response = request.POST.get('captcha_response')
|
182 |
+
|
183 |
+
# Verify captcha
|
184 |
+
result = gCaptchaVerifer(captcha_response)
|
185 |
+
if not result.get("success"):
|
186 |
+
return JsonResponse({
|
187 |
+
"error": "Invalid Captcha",
|
188 |
+
"status": "error"
|
189 |
+
})
|
190 |
+
|
191 |
+
# Authenticate user
|
192 |
+
user = Bhagat.objects.filter(username=username).first()
|
193 |
+
if user is not None and user.check_password(password):
|
194 |
+
# Generate tokens
|
195 |
+
refresh = RefreshToken.for_user(user)
|
196 |
+
|
197 |
+
return JsonResponse({
|
198 |
+
"status": "success",
|
199 |
+
"tokens": {
|
200 |
+
"access_token": str(refresh.access_token),
|
201 |
+
"refresh_token": str(refresh)
|
202 |
+
},
|
203 |
+
"user": {
|
204 |
+
"id": user.id,
|
205 |
+
"username": user.username,
|
206 |
+
"first_name": user.first_name,
|
207 |
+
"last_name": user.last_name,
|
208 |
+
"email": user.email,
|
209 |
+
"phone": user.phone,
|
210 |
+
"region": user.region.name,
|
211 |
+
"user_type": user.user_type,
|
212 |
+
"profile_image": user.profile_image
|
213 |
+
}
|
214 |
+
})
|
215 |
+
|
216 |
+
return JsonResponse({
|
217 |
+
"error": "Invalid credentials",
|
218 |
+
"status": "error"
|
219 |
+
})
|
220 |
+
|
221 |
+
return JsonResponse({
|
222 |
+
"error": "Invalid Method",
|
223 |
+
"status": "error"
|
224 |
+
})
|
225 |
+
|
226 |
+
|
227 |
+
|
228 |
+
@csrf_exempt
|
229 |
+
@jwt_required()
|
230 |
+
def logout(request):
|
231 |
+
if request.method == 'POST':
|
232 |
+
refresh_token = request.POST.get('refresh_token')
|
233 |
+
if not refresh_token:
|
234 |
+
return JsonResponse({
|
235 |
+
'error': 'Refresh token is required',
|
236 |
+
'status': 'error'
|
237 |
+
})
|
238 |
+
else:
|
239 |
+
try:
|
240 |
+
refresh = RefreshToken(refresh_token)
|
241 |
+
refresh.blacklist()
|
242 |
+
return JsonResponse({
|
243 |
+
'status': 'success',
|
244 |
+
'message': 'Successfully logged out'
|
245 |
+
})
|
246 |
+
except TokenError:
|
247 |
+
return JsonResponse({
|
248 |
+
"error": "Invalid token",
|
249 |
+
"status": "error"
|
250 |
+
})
|
251 |
+
return JsonResponse({
|
252 |
+
"status": "error",
|
253 |
+
"error": "Invalid Method"
|
254 |
+
})
|
255 |
+
|
256 |
+
|
257 |
+
@jwt_required()
|
258 |
+
def get_user_profile(request):
|
259 |
+
try:
|
260 |
+
user = request.user
|
261 |
+
return JsonResponse({
|
262 |
+
"status": "success",
|
263 |
+
"user": {
|
264 |
+
"id": user.id,
|
265 |
+
"username": user.username,
|
266 |
+
"first_name": user.first_name,
|
267 |
+
"last_name": user.last_name,
|
268 |
+
"email": user.email,
|
269 |
+
"phone": user.phone,
|
270 |
+
"region": user.region.name,
|
271 |
+
"user_type": user.user_type,
|
272 |
+
"profile_image": user.profile_image
|
273 |
+
}
|
274 |
+
})
|
275 |
+
except Exception as e:
|
276 |
+
return JsonResponse({
|
277 |
+
"status": "error",
|
278 |
+
"error": str(e)
|
279 |
+
})
|
280 |
+
|
281 |
+
@csrf_exempt
|
282 |
+
@jwt_required()
|
283 |
+
def profile_updater(request):
|
284 |
+
if request.method == 'POST':
|
285 |
+
try:
|
286 |
+
user = request.user
|
287 |
+
first_name = request.POST.get('first_name')
|
288 |
+
if first_name:
|
289 |
+
user.first_name = first_name
|
290 |
+
last_name = request.POST.get('last_name')
|
291 |
+
if last_name:
|
292 |
+
user.last_name = last_name
|
293 |
+
email = request.POST.get('email')
|
294 |
+
if email:
|
295 |
+
user.email = email
|
296 |
+
phone = request.POST.get('phone')
|
297 |
+
if phone:
|
298 |
+
user.phone = phone
|
299 |
+
region_name = request.POST.get('region')
|
300 |
+
if region_name:
|
301 |
+
user.region = Region.objects.get(name=region_name)
|
302 |
+
birth_date = request.POST.get('birth_date')
|
303 |
+
if birth_date:
|
304 |
+
user.birthday = birth_date
|
305 |
+
street_name = request.POST.get('street_name')
|
306 |
+
if street_name:
|
307 |
+
user.streetName = street_name
|
308 |
+
pincode = request.POST.get('pincode')
|
309 |
+
if pincode:
|
310 |
+
user.pincode = pincode
|
311 |
+
city = request.POST.get('city')
|
312 |
+
if city:
|
313 |
+
user.city = city
|
314 |
+
state = request.POST.get('state')
|
315 |
+
if state:
|
316 |
+
user.state = state
|
317 |
+
country = request.POST.get('country')
|
318 |
+
if country:
|
319 |
+
user.country = country
|
320 |
+
profile_image = request.POST.get('profile_image')
|
321 |
+
if profile_image:
|
322 |
+
user.profile_image = profile_image
|
323 |
+
user.save()
|
324 |
+
return JsonResponse({
|
325 |
+
"status": "success",
|
326 |
+
"message": "Profile updated successfully"
|
327 |
+
})
|
328 |
+
except Exception as e:
|
329 |
+
return JsonResponse({
|
330 |
+
"status": "error",
|
331 |
+
"error": str(e)
|
332 |
+
})
|
333 |
+
else:
|
334 |
+
user = request.user
|
335 |
+
data= {
|
336 |
+
"first_name": user.first_name,
|
337 |
+
"last_name": user.last_name,
|
338 |
+
"email": user.email,
|
339 |
+
"phone": user.phone,
|
340 |
+
"region": user.region.name,
|
341 |
+
"birth_date": user.birthday,
|
342 |
+
"street_name": user.streetName,
|
343 |
+
"pincode": user.pincode,
|
344 |
+
"city": user.city,
|
345 |
+
"state": user.state,
|
346 |
+
"country": user.country,
|
347 |
+
"profile_image": user.profile_image
|
348 |
+
}
|
349 |
+
return JsonResponse({
|
350 |
+
"status": "success",
|
351 |
+
"user": data
|
352 |
+
})
|
353 |
+
|
354 |
+
|
355 |
+
@jwt_required()
|
356 |
+
def bhaktoList(request):
|
357 |
+
current_user = request.user
|
358 |
+
bhaktos = Bhagat.objects.filter(assigned_to=current_user).all()
|
359 |
+
bhaktoArr = []
|
360 |
+
for bhakto in bhaktos:
|
361 |
+
bhaktoArr.append({
|
362 |
+
"id": bhakto.id,
|
363 |
+
"first_name": bhakto.first_name,
|
364 |
+
"last_name": bhakto.last_name,
|
365 |
+
"region": bhakto.region.name,
|
366 |
+
"user_type": bhakto.user_type,
|
367 |
+
"profile_image": bhakto.profile_image
|
368 |
+
})
|
369 |
+
return JsonResponse({"bhaktos": bhaktoArr})
|
data.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
dataparser.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
+
with open("./api/metadata.json", "r") as f:
|
4 |
+
data = json.load(f)
|
5 |
+
|
6 |
+
|
7 |
+
keys = ['url', 'title', 'album', 'artist', 'year', 'duration', 'albumArtist', 'thumbnail']
|
8 |
+
category = []
|
9 |
+
for i in range(len(data)):
|
10 |
+
if 8 != len(data[i].keys()):
|
11 |
+
print(data[i])
|
12 |
+
# data[i]["thumbnail"] = False
|
13 |
+
# with open("./api/metadata.json", "w") as f:
|
14 |
+
# json.dump(data, f, indent=4)
|
db.sqlite3
CHANGED
Binary files a/db.sqlite3 and b/db.sqlite3 differ
|
|
downloads/1.jpg
ADDED
![]() |
Git LFS Details
|
downloads/10.png
ADDED
![]() |
downloads/100.png
ADDED
![]() |
Git LFS Details
|
downloads/101.png
ADDED
![]() |
Git LFS Details
|
downloads/102.png
ADDED
![]() |
Git LFS Details
|
downloads/103.png
ADDED
![]() |
Git LFS Details
|
downloads/104.png
ADDED
![]() |
Git LFS Details
|
downloads/105.png
ADDED
![]() |
Git LFS Details
|
downloads/106.png
ADDED
![]() |
Git LFS Details
|
downloads/107.png
ADDED
![]() |
Git LFS Details
|
downloads/108.png
ADDED
![]() |
Git LFS Details
|
downloads/109.jpg
ADDED
![]() |
downloads/11.png
ADDED
![]() |
Git LFS Details
|
downloads/110.jpg
ADDED
![]() |
Git LFS Details
|
downloads/111.jpg
ADDED
![]() |
downloads/112.jpg
ADDED
![]() |
Git LFS Details
|
downloads/113.jpg
ADDED
![]() |
downloads/114.jpg
ADDED
![]() |
downloads/115.jpg
ADDED
![]() |
downloads/116.jpg
ADDED
![]() |
Git LFS Details
|
downloads/117.jpg
ADDED
![]() |
downloads/118.jpg
ADDED
![]() |
downloads/119.jpg
ADDED
![]() |
downloads/12.png
ADDED
![]() |
downloads/120.jpg
ADDED
![]() |
downloads/121.jpg
ADDED
![]() |
downloads/122.jpg
ADDED
![]() |
downloads/123.jpg
ADDED
![]() |
downloads/124.jpg
ADDED
![]() |
downloads/125.jpg
ADDED
![]() |
Git LFS Details
|
downloads/126.jpg
ADDED
![]() |