def get_organisations(self, user): if Profile.is_admin(user): return Organisation.objects.all() elif Profile.is_regional_lead(user): return Organisation.objects.filter(location=user.profile.location) else: return Organisation.list_user_organisations(user)
def dispatch(self, request, *args, **kwargs): self.user = request.user self.feedback_required = [] # check if user is tutor if Profile.is_presenter(self.user) and self.allow_presenter: self.validate_presenter_feedback() elif (Profile.is_organiser(self.user) and Organisation.list_user_organisations(self.user).exists()): # if user is from organisation self.validate_organisation_feedback() elif (Profile.is_regional_lead(self.user) or Profile.is_admin(self.user)): pass # don't restrict lead and admin else: msg = """ To request workshop you need to create organisaiton.\n\n Please use organisation tab above to create your organisation""" # return json for ajax request return render(request, 'error.html', {'message': msg}) if self.feedback_required: return self.return_response(request) return super(WorkshopRestrictMixin, self).dispatch(request, *args, **kwargs)
def workshop_list(request): template_name = 'workshops/workshop_list.html' user_profile, created = Profile.objects.get_or_create( user__id=request.user.id) if not user_profile.is_profile_filled: return redirect('profiles:profile-edit', slug=request.user.username) context_dict = {} workshop_list = Workshop.objects.all().order_by('-expected_date') workshop_list = workshop_list.filter( requester__location__id__in=[ x.id for x in request.user.profile.interested_locations.all()] ) context_dict['workshop_list'] = workshop_list context_dict['user'] = request.user # need to improve the part context_dict['is_not_tutor'] = False # as user can be tutor and regional lead hence we need to verify like # this if (Profile.is_regional_lead(request.user) or Profile.is_organiser(request.user) or Profile.is_admin(request.user)): context_dict['is_not_tutor'] = True return render(request, template_name, context_dict)
def get_organisations(self, user): if Profile.is_admin(user): return Organisation.objects.all() elif Profile.is_regional_lead(user): return Organisation.objects.filter(location=user.profile.location) else: return Organisation.list_user_organisations(user)
def get_all_user_info(request): users = User.objects.all() response = HttpResponse(content_type='text/csv') response['Content-Disposition'] = 'attachment; filename="all_users.csv"' writer = csv.writer(response) csv_titles = [ 'User Id', 'First Name', 'Last Name', 'Email', 'Is Active', 'Is Presenter', 'Is POC', 'Is Regional Lead', 'Is Organiser'] writer.writerow(csv_titles) for obj in users: try: row = [ obj.id, obj.first_name, obj.last_name, obj.email, obj.is_active, Profile.is_presenter(obj), Profile.is_coordinator(obj), Profile.is_regional_lead(obj), Profile.is_organiser(obj)] writer.writerow(row) except Exception: pass return response
def dispatch(self, request, *args, **kwargs): self.user = request.user self.feedback_required = [] # check if user is tutor if Profile.is_presenter(self.user) and self.allow_presenter: self.validate_presenter_feedback() elif (Profile.is_organiser(self.user) and Organisation.list_user_organisations(self.user).exists()): # if user is from organisation self.validate_organisation_feedback() elif (Profile.is_regional_lead(self.user) or Profile.is_admin(self.user)): pass # don't restrict lead and admin else: msg = """ To request workshop you need to create organisaiton.\n\n Please use organisation tab above to create your organisation""" # return json for ajax request return render(request, 'error.html', {'message': msg}) if self.feedback_required: return self.return_response(request) return super(WorkshopRestrictMixin, self).dispatch(request, *args, **kwargs)
def workshop_list(request): template_name = 'workshops/workshop_list.html' user_profile, created = Profile.objects.get_or_create( user__id=request.user.id) if not user_profile.is_profile_filled: return redirect('profiles:profile-edit', slug=request.user.username) context_dict = {} workshop_list = Workshop.objects.filter( is_active=True).order_by('-expected_date') workshop_list = workshop_list.filter( requester__location__state__id__in=[ x.id for x in request.user.profile.interested_states.all()] ) location_list = request.GET.getlist("location") if location_list: workshop_list = workshop_list.filter( location__id__in=location_list ) presenter_list = request.GET.getlist("presenter") if presenter_list: workshop_list = workshop_list.filter( presenter__id__in=presenter_list ) workshop_level_list = request.GET.getlist("level") if workshop_level_list: workshop_list = workshop_list.filter( workshop_level__in=workshop_level_list ) workshop_section_list = request.GET.getlist("section") if workshop_section_list: workshop_list = workshop_list.filter( workshop_section__id__in=workshop_section_list ) status_list = request.GET.getlist("status") if status_list: workshop_list = workshop_list.filter( status__in=status_list ) context_dict['workshop_list'] = workshop_list context_dict['user'] = request.user # need to improve the part context_dict['is_not_tutor'] = False # as user can be tutor and regional lead hence we need to verify like # this if (Profile.is_regional_lead(request.user) or Profile.is_organiser(request.user) or Profile.is_admin(request.user)): context_dict['is_not_tutor'] = True context_dict['form'] = WorkshopListForm(user=request.user) return render(request, template_name, context_dict)
def workshop_list(request): template_name = 'workshops/workshop_list.html' user_profile, created = Profile.objects.get_or_create( user__id=request.user.id) if not user_profile.is_profile_filled: return redirect('profiles:profile-edit', slug=request.user.username) context_dict = {} workshop_list = Workshop.objects.all().order_by('-expected_date') workshop_list = workshop_list.filter( requester__location__id__in=[ x.id for x in request.user.profile.interested_locations.all()] ) location_list = request.GET.getlist("location") if location_list: workshop_list = workshop_list.filter( location__id__in=location_list ) presenter_list = request.GET.getlist("presenter") if presenter_list: workshop_list = workshop_list.filter( presenter__id__in=presenter_list ) workshop_level_list = request.GET.getlist("level") if workshop_level_list: workshop_list = workshop_list.filter( workshop_level__in=workshop_level_list ) workshop_section_list = request.GET.getlist("section") if workshop_section_list: workshop_list = workshop_list.filter( workshop_section__id__in=workshop_section_list ) status_list = request.GET.getlist("status") if status_list: workshop_list = workshop_list.filter( status__in=status_list ) context_dict['workshop_list'] = workshop_list context_dict['user'] = request.user # need to improve the part context_dict['is_not_tutor'] = False # as user can be tutor and regional lead hence we need to verify like # this if (Profile.is_regional_lead(request.user) or Profile.is_organiser(request.user) or Profile.is_admin(request.user)): context_dict['is_not_tutor'] = True context_dict['form'] = WorkshopListForm(user=request.user) return render(request, template_name, context_dict)
def create_profile(self, user): django = WorkshopSections.objects.get(name="Django") python3 = WorkshopSections.objects.get(name="Python3") location = Location.objects.all()[0] user_type = UserType.objects.get(slug="admin") profile = Profile(user=user, mobile="8758885872", location=location) profile.usertype.add(user_type) profile.interested_locations.add(location) profile.interested_sections.add(django, python3) profile.save() return profile
def create_profile(self, user): django = WorkshopSections.objects.get(name='Django') python3 = WorkshopSections.objects.get(name='Python3') location = Location.objects.all()[0] user_type = UserType.objects.get(slug='admin') profile = Profile(user=user, mobile='8758885872', location=location) profile.usertype.add(user_type) profile.interested_locations.add(location) profile.interested_sections.add(django, python3) profile.save() return profile
def dispatch(self, request, *args, **kwargs): user = request.user pk = self.kwargs.get(self.pk_url_kwarg, None) workshop = Workshop.objects.get(id=pk) is_admin = Profile.is_admin(user) is_lead = (Profile.is_regional_lead(user) and RegionalLead.is_regional_lead(user, workshop.location)) is_presenter = (Profile.is_organiser(user) and user in workshop.requester.user.all()) if not (is_admin or is_lead or is_presenter): return HttpResponseForbidden("Not sufficent permission") return super(WorkshopAccessMixin, self).dispatch(request, *args, **kwargs)
def dispatch(self, request, *args, **kwargs): user = request.user pk = self.kwargs.get(self.pk_url_kwarg, None) workshop = Workshop.objects.get(id=pk) is_admin = Profile.is_admin(user) is_lead = (Profile.is_regional_lead(user) and RegionalLead.is_regional_lead(user, workshop.location)) is_presenter = (Profile.is_organiser(user) and user in workshop.requester.user.all()) if not (is_admin or is_lead or is_presenter): return HttpResponseForbidden("Not sufficent permission") return super(WorkshopAccessMixin, self).dispatch(request, *args, **kwargs)
def __init__(self, *args, **kwargs): user = kwargs.pop('user') super(WorkshopListForm, self).__init__(*args, **kwargs) self.fields['location'].queryset = self.get_all_locations(user) if Profile.is_admin(user) or Profile.is_regional_lead(user): self.fields['presenter'].queryset = User.objects.filter( profile__usertype__slug="tutor") elif 'poc' in user.profile.get_user_type: self.fields['presenter'].queryset = User.objects.filter( profile__usertype__slug="tutor", profile__location__in=self.get_all_locations(user)) else: del self.fields['presenter'] self.fields['section'].queryset = WorkshopSections.objects.all()
def workshop_details(request, pk): template_name = 'workshops/workshop_detail.html' workshop_obj = get_object_or_404(Workshop, id=pk) show_contact_flag = False display_edit_button = False user = request.user user_is_presenter = [u for u in workshop_obj.presenter.all() if user == u] user_is_requester = [ u for u in workshop_obj.requester.user.all() if user == u ] if (user_is_presenter or user_is_requester or user.is_superuser or ((not user.is_anonymous()) and Profile.is_coordinator(user))): show_contact_flag = True if (user_is_presenter): display_edit_button = True is_admin = True if user.is_superuser else False form = WorkshopVolunteer( initial={ 'number_of_volunteers': workshop_obj.number_of_volunteers or 0 }) context_dict = { 'workshop': workshop_obj, 'show_contact_flag': show_contact_flag, 'display_edit_button': display_edit_button, 'is_admin': is_admin, 'form': form } return render(request, template_name, context_dict)
def workshop_create(request): template_name = 'workshops/workshop_create.html' context_dict = {} if not Organisation.list_user_organisations(request.user).exists(): msg = """ To request workshop you need to create organisaiton.\n\n Please use organisation tab above to create your organisation """ return render(request, 'error.html', {'message': msg}) if request.method == 'GET': form = WorkshopForm(user=request.user) context_dict['form'] = form return render(request, template_name, context_dict) form = WorkshopForm(user=request.user, data=request.POST) if not form.is_valid(): context_dict['form'] = form context_dict['errors'] = form.errors return render(request, template_name, context_dict) workshop = form.save() domain = Site.objects.get_current().domain context = { 'workshop': workshop, 'date': workshop.expected_date, 'workshop_url': domain + '/workshop/{}/'.format(workshop.id) } # Collage POC and admin email poc_admin_user = Profile.get_user_with_type( user_type=['Collage POC', 'admin'] ).values_list('email', flat=True) org_user_emails = workshop.requester.user.filter( is_active=True).values_list('email', flat=True) # all presenter if any all_presenter_email = workshop.presenter.values_list( 'email', flat=True) # List of tutor who have shown interest in that location region_interested_member = Profile.objects.filter( interested_locations=workshop.requester.location, usertype__slug='tutor' ).values_list('user__email', flat=True) all_email = [] all_email.extend(org_user_emails) all_email.extend(all_presenter_email) all_email.extend(poc_admin_user) all_email.extend(region_interested_member) all_email = set(all_email) send_tweet(context) subject = '[PythonExpress] Workshop request status.' email_body = loader.get_template( 'email_messages/workshop/create_workshop/message.html').render(context) text_body = loader.get_template( 'email_messages/workshop/create_workshop/message.txt').render(context) send_email_to_list( subject, body=email_body, users_list=all_email, text_body=text_body) success_url = reverse_lazy('workshops:workshop_list') return HttpResponseRedirect(success_url)
def send_mail_to_group(self, context, exclude_emails=None): """ Send email to org/group users. @param context: Is dict of data required by email template. @exclude_emails: Is list of email to be excluded from email update. """ if exclude_emails is None: exclude_emails = [] # Collage POC and admin email poc_admin_user = Profile.get_user_with_type( user_type=['Collage POC', 'admin']).values_list('email', flat=True) # Org user email org_user_emails = self.object.requester.user.filter( is_active=True).values_list('email', flat=True) # all presenter if any all_presenter_email = self.object.presenter.values_list('email', flat=True) # List of tutor who have shown interest in that location region_interested_member = Profile.objects.filter( interested_locations=self.object.requester.location, usertype__slug='tutor').values_list('user__email', flat=True) all_email = [] all_email.extend(org_user_emails) all_email.extend(all_presenter_email) all_email.extend(poc_admin_user) all_email.extend(region_interested_member) all_email = set(all_email) all_email = list(all_email.difference(exclude_emails)) send_mail(all_email, context, self.email_dir)
def __init__(self, *args, **kwargs): user = kwargs.pop('user') super(WorkshopListForm, self).__init__(*args, **kwargs) self.fields['location'].queryset = self.get_all_locations(user) if Profile.is_admin(user) or Profile.is_regional_lead(user): self.fields['presenter'].queryset = User.objects.filter( profile__usertype__slug="tutor" ) elif 'poc' in user.profile.get_user_type: self.fields['presenter'].queryset = User.objects.filter( profile__usertype__slug="tutor", profile__location__in=self.get_all_locations(user) ) else: del self.fields['presenter'] self.fields['section'].queryset = WorkshopSections.objects.all()
def show_accept_volunteer_button(workshop, user): number_of_volunteers = 0 if ( not workshop.number_of_volunteers) else workshop.number_of_volunteers if user.is_authenticated() and Profile.is_volunteer(user) and \ number_of_volunteers - workshop.volunteer.count() >= 1 and \ user not in workshop.volunteer.all() and \ user not in workshop.requester.user.all(): return True return False
def dispatch(self, request, *args, **kwargs): self.user = request.user self.feedback_required = [] # check if user is tutor if Profile.is_presenter(self.user) and self.allow_presenter: self.validate_presenter_feedback() elif (Profile.is_organiser(self.user) and Organisation.list_user_organisations(self.user).exists()): # if user is from organisation self.validate_organisation_feedback() elif (Profile.is_regional_lead(self.user) or Profile.is_admin(self.user)): pass # don't restrict lead and admin else: raise PermissionDenied if self.feedback_required: return self.return_response(request) return super(WorkshopRestrictMixin, self).dispatch(request, *args, **kwargs)
def get_context_data(self, *args, **kwargs): context = super(WorkshopList, self).get_context_data(*args, **kwargs) workshop_list = Workshop.objects.all() if Profile.is_organiser(self.request.user): workshop_list = workshop_list.filter( requester__user=self.request.user) elif Profile.is_presenter(self.request.user): workshop_list = workshop_list.filter( Q(presenter=self.request.user) | Q(requester__location__name__in=Profile.objects.get( user=self.request.user).get_interested_locations)) elif Profile.is_regional_lead(self.request.user): regions = RegionalLead.objects.filter(user=self.request.user) workshop_list = workshop_list.filter( location__id__in=[x.location.id for x in regions]) context['workshop_list'] = workshop_list context['user'] = self.request.user context['is_not_tutor'] = True if Profile.is_regional_lead( self.request.user) else not Profile.is_presenter(self.request.user) return context
def get_context_data(self, *args, **kwargs): context = super( WorkshopList, self).get_context_data(*args, **kwargs) workshop_list = Workshop.objects.all() if Profile.is_organiser(self.request.user): workshop_list = workshop_list.filter( requester__user=self.request.user) elif Profile.is_presenter(self.request.user): workshop_list = workshop_list.filter( Q(presenter=self.request.user) | Q (requester__location__name__in=Profile.objects.get( user=self.request.user).get_interested_locations)) elif Profile.is_regional_lead(self.request.user): regions = RegionalLead.objects.filter(user=self.request.user) workshop_list = workshop_list.filter( location__id__in=[x.location.id for x in regions]) context['workshop_list'] = workshop_list context['user'] = self.request.user context['is_not_tutor'] = True if Profile.is_regional_lead( self.request.user) else not Profile.is_presenter(self.request.user) return context
def dispatch(self, request, *args, **kwargs): self.user = request.user self.feedback_required = [] # check if user is tutor if Profile.is_presenter(self.user) and self.allow_presenter: self.validate_presenter_feedback() elif (Profile.is_organiser(self.user) and Organisation.list_user_organisations(self.user).exists()): # if user is from organisation self.validate_organisation_feedback() elif (Profile.is_regional_lead(self.user) or Profile.is_admin(self.user)): pass # don't restrict lead and admin else: raise PermissionDenied if self.feedback_required: return self.return_response(request) return super(WorkshopRestrictMixin, self).dispatch(request, *args, **kwargs)
def get_context_data(self, *args, **kwargs): context = super( WorkshopList, self).get_context_data(*args, **kwargs) workshop_list = Workshop.objects.all() if Profile.is_organiser(self.request.user): workshop_list = workshop_list.filter( requester__user=self.request.user) elif Profile.is_presenter(self.request.user): workshop_list = workshop_list.filter( Q(presenter=self.request.user) | Q (requester__location__name__in=Profile.objects.get( user=self.request.user).get_interested_locations)) elif Profile.is_regional_lead(self.request.user): regions = RegionalLead.objects.filter(user=self.request.user) workshop_list = workshop_list.filter( location__id__in=[x.location.id for x in regions]) context['workshop_list'] = workshop_list context['user'] = self.request.user # need to improve the part context['is_not_tutor'] = False # as user can be tutor and regional lead hence we need to verify like # this if (Profile.is_regional_lead(self.request.user) or Profile.is_organiser(self.request.user) or Profile.is_admin(self.request.user)): context['is_not_tutor'] = True return context
def get_context_data(self, *args, **kwargs): context = super(WorkshopList, self).get_context_data(*args, **kwargs) workshop_list = Workshop.objects.all().order_by('-expected_date') if Profile.is_organiser(self.request.user): workshop_list = workshop_list.filter( requester__user=self.request.user) elif Profile.is_presenter(self.request.user): workshop_list = workshop_list.filter( Q(presenter=self.request.user) | Q(requester__location__id__in=[ x.id for x in self.request.user.profile.interested_locations.all() ])) elif Profile.is_regional_lead(self.request.user): regions = RegionalLead.objects.filter(leads=self.request.user) workshop_list = workshop_list.filter( location__id__in=[x.location.id for x in regions]) context['workshop_list'] = workshop_list context['user'] = self.request.user # need to improve the part context['is_not_tutor'] = False # as user can be tutor and regional lead hence we need to verify like # this if (Profile.is_regional_lead(self.request.user) or Profile.is_organiser(self.request.user) or Profile.is_admin(self.request.user)): context['is_not_tutor'] = True return context
def get_context_data(self, *args, **kwargs): context = super(OrganisationList, self).get_context_data(*args, **kwargs) if Profile.is_organiser(self.request.user): context["org_created_list"] = self.get_queryset().filter(created_by=self.request.user) context["org_belongs_list"] = ( self.get_queryset().exclude(created_by=self.request.user).filter(user=self.request.user) ) elif Profile.is_regional_lead(self.request.user): regions = RegionalLead.objects.filter(leads=self.request.user) context["regional_org_list"] = self.get_queryset().filter(location__id__in=[x.location.id for x in regions]) context["user"] = self.request.user # need to improve the part # context['is_not_tutor'] = False # as user can be tutor and regional lead hence we need to verify like # this if ( Profile.is_regional_lead(self.request.user) or Profile.is_organiser(self.request.user) or Profile.is_admin(self.request.user) ): context["is_not_tutor"] = True return context
def get_context_data(self, *args, **kwargs): context = super(OrganisationList, self).get_context_data(*args, **kwargs) if Profile.is_organiser(self.request.user): context['org_created_list'] = self.get_queryset().filter( created_by=self.request.user) context['org_belongs_list'] = self.get_queryset().exclude( created_by=self.request.user).filter(user=self.request.user) elif Profile.is_regional_lead(self.request.user): regions = RegionalLead.objects.filter(leads=self.request.user) context['regional_org_list'] = self.get_queryset().filter( location__id__in=[x.location.id for x in regions]) context['user'] = self.request.user # need to improve the part # context['is_not_tutor'] = False # as user can be tutor and regional lead hence we need to verify like # this if (Profile.is_regional_lead(self.request.user) or Profile.is_organiser(self.request.user) or Profile.is_admin(self.request.user)): context['is_not_tutor'] = True return context
def workshop_create(request): template_name = "workshops/workshop_create.html" context_dict = {} if not Organisation.list_user_organisations(request.user).exists(): msg = """ To request workshop you need to create organisaiton.\n\n Please use organisation tab above to create your organisation """ return render(request, "error.html", {"message": msg}) if request.method == "GET": form = WorkshopForm(user=request.user) context_dict["form"] = form return render(request, template_name, context_dict) form = WorkshopForm(user=request.user, data=request.POST) if not form.is_valid(): context_dict["form"] = form context_dict["errors"] = form.errors return render(request, template_name, context_dict) workshop = form.save() domain = Site.objects.get_current().domain context = { "workshop": workshop, "date": workshop.expected_date, "workshop_url": domain + "/workshop/{}/".format(workshop.id), } # Collage POC and admin email poc_admin_user = Profile.get_user_with_type(user_type=["Collage POC", "admin"]).values_list("email", flat=True) org_user_emails = workshop.requester.user.filter(is_active=True).values_list("email", flat=True) # all presenter if any all_presenter_email = workshop.presenter.values_list("email", flat=True) # List of tutor who have shown interest in that location region_interested_member = Profile.objects.filter( interested_locations=workshop.requester.location, usertype__slug="tutor" ).values_list("user__email", flat=True) all_email = [] all_email.extend(org_user_emails) all_email.extend(all_presenter_email) all_email.extend(poc_admin_user) all_email.extend(region_interested_member) all_email = set(all_email) send_tweet(context) subject = "[PythonExpress] Workshop request status." email_body = loader.get_template("email_messages/workshop/create_workshop/message.html").render(context) text_body = loader.get_template("email_messages/workshop/create_workshop/message.txt").render(context) send_email_to_list(subject, body=email_body, users_list=all_email, text_body=text_body) success_url = reverse_lazy("workshops:workshop_list") return HttpResponseRedirect(success_url)
def workshop_details(request, pk): template_name = "workshops/workshop_detail.html" workshop_obj = get_object_or_404(Workshop, id=pk) show_contact_flag = False user = request.user if ( [u for u in workshop_obj.presenter.all() if user == u] or [u for u in workshop_obj.requester.user.all() if user == u] or user.is_superuser or ((not user.is_anonymous) and Profile.is_coordinator(user)) ): show_contact_flag = True context_dict = {"workshop": workshop_obj, "show_contact_flag": show_contact_flag} return render(request, template_name, context_dict)
def workshop_details(request, pk): template_name = 'workshops/workshop_detail.html' workshop_obj = get_object_or_404(Workshop, id=pk) show_contact_flag = False display_edit_button = False user = request.user user_is_presenter = [u for u in workshop_obj.presenter.all() if user == u] user_is_requester = [ u for u in workshop_obj.requester.user.all() if user == u] if (user_is_presenter or user_is_requester or user.is_superuser or ((not user.is_anonymous()) and Profile.is_coordinator(user))): show_contact_flag = True if (user_is_presenter): display_edit_button = True context_dict = { 'workshop': workshop_obj, 'show_contact_flag': show_contact_flag, 'display_edit_button': display_edit_button } return render(request, template_name, context_dict)
def workshop_details(request, pk): template_name = 'workshops/workshop_detail.html' workshop_obj = get_object_or_404(Workshop, id=pk) show_contact_flag = False display_edit_button = False user = request.user user_is_presenter = [u for u in workshop_obj.presenter.all() if user == u] user_is_requester = [ u for u in workshop_obj.requester.user.all() if user == u] if (user_is_presenter or user_is_requester or user.is_superuser or ((not user.is_anonymous()) and Profile.is_coordinator(user))): show_contact_flag = True if (user_is_presenter): display_edit_button = True context_dict = { 'workshop': workshop_obj, 'show_contact_flag': show_contact_flag, 'display_edit_button': display_edit_button } return render(request, template_name, context_dict)
def send_mail(self, user, assigned): """Send email to presenter and org users.""" workshop = self.object email_dir = 'workshops/email/assign_me/' last_presenter = user # Collage POC and admin email poc_admin_user = Profile.get_user_with_type( user_type=['Collage POC', 'admin'] ).values_list('email', flat=True) # Org user email org_user_emails = workshop.requester.user.filter( is_active=True ).values_list('email', flat=True) # all presenter except current assigned presenter all_presenter_email = workshop.presenter.exclude( pk=last_presenter.pk ).values_list( 'email', flat=True ) context = { 'presenter': True, 'assigned': assigned, 'date': workshop.expected_date, 'presenter_name': last_presenter.username, 'workshop_organization': workshop.requester, 'workshop_url': self.request.build_absolute_uri(reverse( 'workshops:workshop_detail', args=[workshop.pk] )) } # Send email to presenter send_mail([last_presenter.email], context, email_dir) # Send email to org users and other presenter(s). context['presenter'] = False all_email = [] all_email.extend(org_user_emails) all_email.extend(all_presenter_email) all_email.extend(poc_admin_user) all_email = list(set(all_email)) send_mail(all_email, context, email_dir)
def send_mail_to_group(self, context, exclude_emails=None): """ Send email to org/group users. @param context: Is dict of data required by email template. @exclude_emails: Is list of email to be excluded from email update. """ if exclude_emails is None: exclude_emails = [] # Collage POC and admin email poc_admin_user = Profile.get_user_with_type( user_type=['Collage POC', 'admin'] ).values_list('email', flat=True) # Org user email org_user_emails = self.object.requester.user.filter( is_active=True ).values_list('email', flat=True) # all presenter if any all_presenter_email = self.object.presenter.values_list( 'email', flat=True ) # List of tutor who have shown interest in that location region_interested_member = Profile.objects.filter( interested_locations=self.object.requester.location, usertype__slug='tutor' ).values_list('user__email', flat=True) all_email = [] all_email.extend(org_user_emails) all_email.extend(all_presenter_email) all_email.extend(poc_admin_user) all_email.extend(region_interested_member) all_email = set(all_email) all_email = list(all_email.difference(exclude_emails)) send_mail(all_email, context, self.email_dir)
def get_context_data(self, *args, **kwargs): context = super(OrganisationList, self).get_context_data( *args, **kwargs) if Profile.is_organiser(self.request.user): context['org_created_list'] = self.get_queryset().filter( created_by=self.request.user) context['org_belongs_list'] = self.get_queryset().exclude( created_by=self.request.user) elif Profile.is_regional_lead(self.request.user): regions = RegionalLead.objects.filter(leads=self.request.user) context['regional_org_list'] = self.get_queryset().filter( location__id__in=[x.location.id for x in regions]) elif Profile.is_presenter(self.request.user): pass context['user'] = self.request.user context['is_not_tutor'] = True if (Profile.is_regional_lead( self.request.user) or Profile.is_organiser( self.request.user)) else not Profile.is_presenter( self.request.user) return context
def get_context_data(self, *args, **kwargs): context = super(OrganisationList, self).get_context_data(*args, **kwargs) print(Profile.is_regional_lead(self.request.user)) if Profile.is_organiser(self.request.user): context['org_created_list'] = self.get_queryset().filter( created_by=self.request.user) context['org_belongs_list'] = self.get_queryset().exclude( created_by=self.request.user) elif Profile.is_regional_lead(self.request.user): print("AM here") regions = RegionalLead.objects.filter(leads=self.request.user) print([x.location.id for x in regions]) context['regional_org_list'] = self.get_queryset().filter( location__id__in=[x.location.id for x in regions]) elif Profile.is_presenter(self.request.user): pass context['user'] = self.request.user context['is_not_tutor'] = True if Profile.is_regional_lead( self.request.user) else not Profile.is_presenter(self.request.user) return context
def get_all_locations(self, user): if Profile.is_admin(user): return Location.objects.all() else: return user.profile.interested_locations.all()
def get_all_states(self, user): if Profile.is_admin(user): return State.objects.all() else: return user.profile.interested_states.all()
def get_all_locations(self, user): if Profile.is_admin(user): return Location.objects.all() else: return user.profile.interested_locations.all()