File size: 5,132 Bytes
e744e38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aff4b27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from django.db import models
from django.contrib.auth.models import AbstractUser
import datetime as DateTime
from django.utils.html import mark_safe

class Bhagat(AbstractUser):
    USER_TYPES = (
        ('superadmin', 'Super Admin'),
        ('regionadmin', 'Region Admin'),
        ('karyakarta', 'Karyakarta'),
        ('user', 'User'),
    )
    MEMBER_TYPES = (
        ('ambrish', 'Ambrish'),
        ('sadbhav', 'Sadbhav'),
        ('vip', 'VIP'),
        ('youvak', 'Youvak'),
    )
    user_type = models.CharField(max_length=20, choices=USER_TYPES, default="user")
    phone = models.CharField(max_length=20, null=True)
    member_type = models.CharField(max_length=20, choices=MEMBER_TYPES, default="youvak")
    region = models.ForeignKey('Region', on_delete=models.SET_NULL, null=True)
    birthday = models.DateField(default=DateTime.date.today, null=True)
    streetName = models.TextField(null=True)
    city = models.CharField(max_length=100, null=True)
    state = models.CharField(max_length=100, null=True)
    country = models.CharField(max_length=100, null=True)
    pincode = models.CharField(max_length=10, null=True)
    assigned_to = models.ForeignKey('self', on_delete=models.SET_NULL, null=True, blank=True, related_name='assigned_users')
    profile_image = models.URLField(blank=True)
    
    def __str__(self):
        return self.first_name + ' ' + self.last_name

    def save(self, *args, **kwargs):
        self.set_password(self.password)
        super().save(*args, **kwargs)


class Region(models.Model):
    name = models.CharField(max_length=100)
    
    def __str__(self):
        return self.name


class Event(models.Model):
    COLOR_CHOICES = (("orange","Shabha"), ("green","Activity"), ("blue","Birthday"), ("red","Important"), ("purple","Gathering"), ("yellow","Festival"), ("pink","Special"))
    title = models.CharField(max_length=200)
    description = models.TextField()
    date = models.DateTimeField()
    time = models.TimeField(default='00:00')
    created_by = models.ForeignKey(Bhagat, on_delete=models.CASCADE, related_name='created_events',blank=True,null=True)
    region = models.ForeignKey(Region, on_delete=models.CASCADE, blank=True,null=True)
    is_approved = models.BooleanField(default=False)
    color = models.CharField(max_length=15, default='orange',choices=COLOR_CHOICES)
    
    def __str__(self):
        return self.title


class Attendance(models.Model):
    user = models.ForeignKey(Bhagat, on_delete=models.CASCADE)
    event = models.ForeignKey(Event, on_delete=models.CASCADE)
    status = models.CharField(max_length=20, choices=(('attending', 'Attending'), ('not_attending', 'Not Attending'), ('maybe', 'Maybe')))

class Notification(models.Model):
    sender = models.ForeignKey(Bhagat, on_delete=models.CASCADE, related_name='sent_notifications')
    recipients = models.ManyToManyField(Bhagat, related_name='received_notifications')
    title = models.CharField(max_length=200, blank=True, null=True)
    content = models.TextField()
    timestamp = models.DateTimeField(auto_now_add=True)
    notification_type = models.CharField(max_length=20, choices=(("orange", "Shabha"), ("green", "Activity"), ("blue", "Birthday"), ("red", "Important"), ("purple", "Gathering"), ("yellow", "Festival"), ("pink", "Custom")))

class BhajanCategory(models.Model):
    name = models.CharField(max_length=100)
    link = models.CharField(max_length=100)
    
    def __str__(self):
        return self.name

class Bhajan(models.Model):
    bhajanId = models.IntegerField(blank=True,default=0)
    title = models.CharField(max_length=500,blank=True)
    title_guj = models.CharField(max_length=500,blank=True)
    category = models.ForeignKey(BhajanCategory, on_delete=models.CASCADE)
    lyrics = models.CharField(max_length=50, blank=True)
    audio_url = models.URLField(blank=True)
    isEng = models.BooleanField(default=False)
    isHnd = models.BooleanField(default=False)
    isGer = models.BooleanField(default=False)
    isAudio = models.BooleanField(default=False)
    
    def __str__(self):
        return self.title
    
    def musicPreivew(self):
        if self.isAudio:
            return mark_safe('<audio controls><source src="https://huggingface.co/spaces/thejagstudio/MusicStore/resolve/main/Bhajan Audio/%s" type="audio/mpeg"></audio>' % self.audio_url)
        else:
            return 'No Audio Available'
    
    def lyricsBtn(self):
        # i have four languages in my bhajan so add them all as buttons and show them on click
        languages = [["","GUJ"]]
        if self.isEng:
            languages.append(['E','ENG'])
        if self.isHnd:
            languages.append(['H','HND'])
        if self.isGer:
            languages.append(['G','GER'])
        html = '<ul class="object-tools" style="margin-top:0">'
        for lang in languages:
            html += '<li style="padding-bottom:12px"><a href="https://huggingface.co/spaces/thejagstudio/MusicStore/raw/main/HTML Files/'+lang[0] + self.lyrics+'" target="_blank" class="import_link">'+(lang[1])+'</a></li>'
        html += '</ul>'
        return mark_safe(html)