-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmodels.py
132 lines (97 loc) · 4.34 KB
/
models.py
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from django.db import models
from django.core.validators import MinValueValidator
from django.conf import settings
from django.db.models.signals import pre_delete
from django.dispatch.dispatcher import receiver
from django.utils.translation import ugettext as _
from cms.models import CMSPlugin
from django_bigbluebutton.bbb_api import getMeetings, createMeeting, endMeeting
from random import randrange
def delete_meeting_in_bigbluebutton(sender, instance, *args, **kwargs):
endMeeting(instance.unique_id, instance.moderator_pw,
settings.BBB_URL, settings.BBB_SECRET)
class Meeting(models.Model):
def get_unique_id():
if Meeting.objects.all().count() == 0:
return randrange(100000, 1000000)
else:
return Meeting.objects.latest('id').unique_id + 1
name = models.CharField(_('name'),
help_text=_('The name of the meeting.'),
max_length=50)
unique_id = models.IntegerField(
_('Unique number'),
help_text=_('The meeting number which need to be unique.'),
unique=True, default=get_unique_id)
date = models.DateTimeField(
_("Schedule on"),
help_text=_("The date and time the meeting will be."))
attendee_pw = models.CharField(
_('Attendee password'),
help_text=_('The password which will sent to attendees.'),
max_length=50, blank=True) # True because bbb will generate one if empty
moderator_pw = models.CharField(
_('Moderator password'),
help_text=_("The password for meeting's moderator."),
max_length=50, blank=True) # True because bbb will generate one if empty
welcome_message = models.CharField(
_('Welcome message'),
help_text=_('Message which displayed on the chat window.'),
max_length=200, blank=True)
logout_url = models.URLField(
_('Logout URL'),
help_text=_('URL to which users will be redirected.'),
default=settings.BBB_LOGOUT_URL)
def __str__(self):
return self.name
def save(self, *args, **kwargs):
createMeeting(self.name, self.unique_id, self.welcome_message,
self.moderator_pw, self.attendee_pw, self.logout_url,
settings.BBB_URL, settings.BBB_SECRET)
if self.moderator_pw == '' or self.attendee_pw == '':
list_meetings = getMeetings(settings.BBB_URL, settings.BBB_SECRET)
meetings = []
if list_meetings is not None:
if list_meetings['meetings'] is not None:
meetings = list(list_meetings['meetings'].values())
for meeting in meetings:
if int(meeting.get('meetingID')) == self.unique_id:
self.moderator_pw = meeting.get('moderatorPW')
self.attendee_pw = meeting.get('attendeePW')
super(Meeting, self).save(*args, **kwargs)
pre_delete.connect(delete_meeting_in_bigbluebutton, sender=Meeting)
class RegisteredUser(models.Model):
mail = models.EmailField(
_('Mail address'),
help_text=_('Mail where informations will be sent.')
)
last_name = models.CharField(_('Last name'),
help_text=_('Attendee last name.'),
max_length=50)
first_name = models.CharField(_('First name'),
help_text=_('Attendee first name.'),
max_length=50)
company = models.CharField(_('Company name'),
help_text=_('Attendee company name.'),
max_length=50)
phone_number = models.CharField(_('Phone number'),
help_text=_('Attendee phone number.'),
max_length=40)
meetings = models.ManyToManyField(
Meeting,
verbose_name=_('List of meetings that the user is registered.')
)
def __str__(self):
return self.mail
class PreRegisteredUser(models.Model):
mail = models.EmailField(
_('Mail address'),
help_text=_('Mail where informations will be sent.')
)
meetings = models.ManyToManyField(
Meeting,
verbose_name=_('List of meetings that the user is registered.'),
blank=True
)
def __str__(self):
return self.mail