def add_mom(self, data, meet): Validator.validate_mom(meet.close_time, meet.meeting_date, "Minutes of meeting cannot be added") meet.description = data['description'] with transaction.atomic(): meet.save() return Response({'minutes of meeting': meet.description}, status=status.HTTP_201_CREATED)
def register( request, format=None, ): Validator.validate_superuser(request.user, "Cannot Access") data = request.data user_detail_service = UserDetailService() return user_detail_service.create_user(data)
def add_company( request, format=None, ): Validator.validate_superuser(request.user, "Cannot Access") data = request.data company_detail_service = CompanyDetailsService() return company_detail_service.create_company(data)
def meet_history(request,format=None): # get history of meeting user = request.user Validator.validate_company(request.GET.get("comp",None), "Please select a company") Validator.validate_contact(request.GET.get("contact",None), "Please select a person to contact") meetings = External_Meetings.objects.filter(comp_id=request.GET.get("comp", None), contact_id = request.GET.get("contact", None), user = user) return Response({'response' : [{ 'open_time': e.open_time , 'close_time': e.close_time, 'meeting_date': e.meeting_date, 'description' : e.agenda, 'minutes_of_meeting' : e.description} for e in meetings]}, status=status.HTTP_200_OK)
def update_user( request, format=None, ): Validator.validate_superuser(request.user, "Cannot Access") data = request.data # user = request.user user_id = request.GET.get('user_id', None) user = user_details.objects.filter(id=user_id)[0] # if user.usertype == 'Admin': user_detail_service = UserDetailService() return user_detail_service.update_user(data, user)
def __validate_input(self, data): Validator.validate_string(data.get('title'), "Title cannot be empty!") Validator.validate_date(data.get('travel_date'), "Format of date is incorrect", "Date cannot be empty") Validator.validate_date(data.get('return_date'), "Format of date is incorrect", "Date cannot be empty") Validator.validate_string(data.get('travel_from'), "Location field cannot be empty") Validator.validate_string(data.get('travel_to'), "Location field cannot be empty")
def get_users(request, format=None,): Validator.validate_superuser(request.user , "User not authorized to access") user_list = user_details.objects.all() return Response([{ "name" : e.name , "user_id" :e.id, "email": e.email, "mobile": e.mobile , "address": e.address , "zone" : e.zone.split(',') if e.zone is not None else e.zone , "usertype" : e.usertype , "username" : e.username, "is_active" : e.is_active } for e in user_list] , status=status.HTTP_200_OK)
def update_company( request, format=None, ): Validator.validate_superuser(request.user, "Cannot Access") data = request.data # user = request.user comp_id = request.GET.get('comp_id', None) comp = Company_Details.objects.filter(comp_id=comp_id)[0] # user = request.user # if user.usertype == 'Admin': company_detail_service = CompanyDetailsService() return company_detail_service.update_company(data, comp)
def active( request, format=None, ): Validator.validate_superuser(request.user, "Cannot Access") active = request.GET.get('status', None) user_id = request.GET.get('user_id', None) user = user_details.objects.filter(id=user_id)[0] user.is_active = active user.save() return Response({ "user_id": user.id, "is_active": user.is_active }, status=status.HTTP_200_OK)
def __validate_input(self, data, meetings): Validator.validate_string(data.get('title'), "Title cannot be empty!") Validator.validate_date(data.get('meeting_date'), "Format of date is incorrect", "Date cannot be empty") Validator.validate_time(data.get('open_time'), "Time field cannot be empty") Validator.validate_time(data.get('close_time'), "Time field cannot be empty") Validator.validate_date_today(data.get('meeting_date'), "Date cannot be from past") Validator.validate_meeting_type(data.get('meeting_type'), "Meeting Type cannot be empty") Validator.validate_meet(data['open_time'], data['close_time'], meetings, "Time slot already booked") Validator.validate_company(data.get('comp_id'), "Please select a company") Validator.validate_contact(data.get('contact_id'), "Please select a person to contact")
def validate_updated_input(self, data, meetings, meet_id): Validator.validate_string(data.get('title'), "Title cannot be empty!") Validator.validate_date(data.get('meeting_date'), "Format of date is incorrect", "Date cannot be empty") Validator.validate_date_today(data.get('meeting_date'), "Date cannot be from past") Validator.validate_time(data.get('open_time'), "Time field cannot be empty") Validator.validate_time(data.get('close_time'), "Time field cannot be empty") Validator.validate_meeting_type(data.get('meeting_type'), "Meeting Type cannot be empty") Validator.validate_updated_meet(meet_id, data['open_time'], data['close_time'], meetings, "Time slot already booked")
def __validate_input(self, new_user, data): Validator.validate_string(data.get('password'), "Password cannot be empty!") Validator.validate_string(data.get('username'), "Username cannot be empty!") Validator.validate_string(data.get('usertype'), "Usertype cannot be empty!") Validator.validate_zone(data.get('zone'), "Zone cannot be empty!") Validator.validate_string(data.get('name'), "name cannot be empty!") Validator.validate_string(data.get('email'), "Email cannot be empty!") Validator.validate_username(new_user, data.get('username'), "Duplicate Username!") Validator.validate_email(new_user, data.get('email'), "Duplicate Email!")