コード例 #1
0
 def retrieve(self, request, group_id=None):
     group = Group.safe_get(group_id)
     if not group:
         return HTTPResponse({"No such group found !"})
     response = {
         "id":
         str(group.id),
         "title":
         group.title,
         "level_id":
         str(group.level_id.id) if group.level_id else "",
         "level_no":
         group.level_id.level_no,
         "level_title":
         group.level_id.title,
         "admin_id":
         str(group.admin_id.id) if group.admin_id else "",
         "admin_name":
         group.admin_id.get_full_name() if group.admin_id else '',
         "parent_group_id":
         str(group.parent_group_id.id) if group.parent_group_id else "",
         "parent_group_name":
         group.parent_group_id.title if group.parent_group_id else ""
     }
     return HTTPResponse(response)
コード例 #2
0
 def delete(self, request, group_id=None):
     group = Group.safe_get(group_id)
     if not group:
         return HTTPResponse({"No such group found !"})
     group.delete()
     response = {}
     return HTTPResponse(response)
コード例 #3
0
 def delete(self, request, member_id=None):
     member = Member.safe_get(member_id)
     if not member:
         return HTTPResponse({"No such member found !"})
     member.delete()
     response = {}
     return HTTPResponse(response)
コード例 #4
0
 def retrieve(self, request, member_id=None):
     member = Member.safe_get(member_id)
     if not member:
         return HTTPResponse({"No such member found !"})
     response = {
         "id": str(member.id),
         "name": member.get_full_name(),
         "mobile_no": member.mobile_no,
         "dob": member.dob,
         "level_id": str(member.level_id.id) if member.level_id else "",
         "level_no": member.level_id.level_no if member.level_id else "",
         "level_title": member.level_id.title if member.level_id else "",
         "group_id": str(member.group_id.id) if member.group_id else "",
         "group_title": member.group_id.title if member.group_id else ""
     }
     return HTTPResponse(response)
コード例 #5
0
 def list(self, request, *args, **kwargs):
     groups = Group.objects.all()
     response = []
     for group in groups:
         response.append({
             "id": str(group.id),
             "title": group.title,
             "level_title": group.level_id.title
         })
     return HTTPResponse(response)
コード例 #6
0
 def create(self, request, *args, **kwargs):
     data = dict(request.data)
     user = request.user
     level = Level()
     level.title = data.get('title', '')
     level.level_no = data.get('level_no', 0)
     level.created_at = datetime.utcnow()
     level.created_by = user.to_dbref() if user.id else None
     level.save()
     response = {"title": level.title, "level_no": level.level_no}
     return HTTPResponse(response)
コード例 #7
0
 def update(self, request, level_id=None):
     data = request.data
     user = request.user
     level = Level.safe_get(level_id)
     if not level:
         return HTTPResponse({"No such level found !"})
     level.title = data.get('title', level.title)
     level.level_no = data.get('level_no', level.level_no)
     level.updated_at = datetime.utcnow()
     level.updated_by = user.to_dbref() if user.id else None
     level.save()
     return self.retrieve(request, level_id=level_id)
コード例 #8
0
 def update(self, request, group_id=None):
     data = request.data
     group = Group.safe_get(group_id)
     user = request.user
     if not group:
         return HTTPResponse({"No such group found !"})
     level = Level.safe_get(data.get('level_id'))
     admin = Member.safe_get(data.get('admin_id'))
     parent_group = Group.safe_get(data.get('parent_group_id'))
     group.title = data.get('title', group.title)
     if level:
         group.level_id = level.to_dbref()
     if admin:
         group.admin_id = admin.to_dbref()
     if parent_group:
         group.parent_group_id = parent_group.to_dbref()
     group.updated_at = datetime.utcnow()
     group.updated_by = user.to_dbref() if user.id else None
     group.save()
     response = {"id": str(group.id), "title": group.title}
     return HTTPResponse(response)
コード例 #9
0
 def list(self, request, *args, **kwargs):
     group = Group.safe_get(request.query_params.get('group_id', None))
     if group:
         members = Member.objects.filter(group_id=group.id)
     else:
         members = Member.objects.all()
     response = []
     for member in members:
         response.append({
             "id": str(member.id),
             "name": member.get_full_name()
         })
     return HTTPResponse(response)
コード例 #10
0
 def create(self, request, *args, **kwargs):
     data = dict(request.data)
     user = request.user
     level = Level.safe_get(data.get('level_id'))
     admin = Member.safe_get(data.get('admin_id'))
     parent_group = Group.safe_get(data.get('parent_group_id'))
     group = Group()
     group.title = data.get('title', '')
     group.level_id = level.to_dbref() if level else None
     group.admin_id = admin.to_dbref() if admin else None
     group.created_at = datetime.utcnow()
     group.created_by = user.to_dbref() if user.id else None
     group.parent_group_id = parent_group.id if parent_group else None
     group.save()
     response = {"id": str(group.id), "title": group.title}
     return HTTPResponse(response)
コード例 #11
0
 def create(self, request, *args, **kwargs):
     data = dict(request.data)
     user = request.user
     level = Level.safe_get(data.get('level_id'))
     group = Group.safe_get(data.get('group_id'))
     member = Member()
     name = Name(first=data.get('first_name'),
                 middle=data.get('middle_name'),
                 last=data.get('last_name'))
     member.name = name
     member.dob = data.get("dob", None)
     member.mobile_no = data.get("mobile_no", None)
     member.level_id = level.to_dbref() if level else None
     member.group_id = group.to_dbref() if group else None
     member.created_at = datetime.utcnow()
     member.created_by = user.to_dbref() if user.id else None
     member.save()
     response = {"id": str(member.id), "name": member.get_full_name()}
     return HTTPResponse(response)
コード例 #12
0
 def update(self, request, member_id=None):
     data = request.data
     member = Member.safe_get(member_id)
     user = request.user
     if not member:
         return HTTPResponse({"No such member found !"})
     level = Level.safe_get(data.get('level_id'))
     group = Group.safe_get(data.get('group_id'))
     if data.get('first_name', False):
         member.name.first = data.get('first_name')
     if data.get('middle_name', False):
         member.name.middle = data.get('middle_name')
     if data.get('last_name', False):
         member.name.last = data.get('last_name')
     member.mobile_no = data.get('mobile_no', member.mobile_no)
     member.dob = data.get('dob', member.dob)
     if level:
         member.level_id = level.to_dbref()
     if group:
         member.group_id = group.to_dbref()
     member.updated_at = datetime.utcnow()
     member.updated_by = user.to_dbref() if user.id else None
     member.save()
     return self.retrieve(request, member_id=member_id)
コード例 #13
0
 def delete(self, request, level_id=None):
     level = Level.safe_get(level_id)
     if not level:
         return HTTPResponse({"No such level found !"})
     level.delete()
     return HTTPResponse({})
コード例 #14
0
 def retrieve(self, request, level_id=None):
     level = Level.safe_get(level_id)
     if not level:
         return HTTPResponse({"No such level found !"})
     response = {"id": str(level.id), "title": level.title, "level_no": level.level_no}
     return HTTPResponse(response)
コード例 #15
0
 def list(self, request, *args, **kwargs):
     levels = Level.objects.all()
     response = []
     for level in levels:
         response.append({"id": str(level.id), "title": level.title, "level_no": level.level_no})
     return HTTPResponse(response)
コード例 #16
0
 def get_my_profile(self, request):
     user = request.user
     if user.id:
         return self.retrieve(request, member_id=str(user.id))
     else:
         return HTTPResponse({"No such member found!"})