def save(self, user): pm = PM(sender=user, subject=self.cleaned_data['subject'], body=self.cleaned_data['body']) pm.save() for user in self.cleaned_data['recipients_user']: recip = Recipient(recipient=user, message=pm) recip.save() return pm
def copy(mailout, user): recipients = mailout.recipient_set.all() new_mailout = Mailout(subject=mailout.subject, body=mailout.body, organisation=mailout.organisation, created_by=user) new_mailout.save() for r in recipients: new_recipient = Recipient(mailout=new_mailout, user=r.user) new_recipient.save() return new_mailout.pk
def save(self, user): pm = PM( sender = user, subject = self.cleaned_data['subject'], body = self.cleaned_data['body'] ) pm.save() for user in self.cleaned_data['recipients_user']: recip = Recipient(recipient=user, message=pm) recip.save() return pm
def createRecipients(): try: if not request.json: abort(400) else: recipient = Recipient(request.json['recipients'], request.json['feeds_id']) session.add(recipient) session.commit() return jsonify(recipient.serialize()) except Exception as e: return (str(e))
def on_post(self, req, resp): """Handles POST requests""" payload = json.loads(req.stream.read()) logger.debug('Recieved {} '.format(payload)) try: r = Recipient(payload) r.validate() key = rs.add(r) logger.debug('Added recipient at {}'.format(key)) except InvalidUKMobileNumberException, e: logger.error(e) raise falcon.HTTPBadRequest( 'You need to supply a valid UK mobile number.', 'See docs for more details.')
def add(self, recipient_emails): '''Adds all the recipient in the given list to the database. Arguments: recipient_emails {list} -- The list of recipient emails. ''' self.__logger.info(f'Adding {len(recipient_emails)} recipients.') for email in recipient_emails: Recipient.create( email=email.strip(), date_added=datetime.today().strftime('%Y-%m-%d') )
def videos(): videos1 = [] videos2 = [] #<a href="{% url recipient video1r.slug %}">{{ video1r.name }}</a></p> #<p>How ProcrasDonate Works</p> pd = Recipient.get_or_none(slug='PD') if pd: if pd.promotional_video: videos2.append({'video': pd.promotional_video, 'caption': 'ProcrasDonate: Early Presentation'}) videos2.append({'video': "%sswf/LaptopIntro.swf" % settings.MEDIA_URL, 'caption': 'ProcrasDonate Intro'}) for ch in Recipient.objects.filter(is_visible=True, tax_exempt_status=True): if ch.promotional_video: videos1.append({'video': ch.promotional_video, 'caption': '<a href="%s">%s</a>' % (reverse('recipient', args=(ch.slug, )), ch.name)}) if ch.pd_experience_video: videos2.append({'video': ch.pd_experience_video, 'caption': '<a href="%s">%s\'s Experience with ProcrasDonate</a>' % (reverse('recipient', args=(ch.slug, )), ch.name)}) video1 = None video2 = None if videos1: video1 = videos1[randint(0, len(videos1)-1)] if videos2: video2 = videos2[randint(0, len(videos2)-1)] return {'video1': video1, 'video2': video2}
def new(users, user, organisation_id=None): """Make and return a new mailout to be sent to the given list of users.""" if not user.is_staff: organisation_id = user.get_profile().representativeprofile.organisation.id organisation = None if organisation_id: organisation = Organisation.objects.get(pk=organisation_id) mailout = Mailout(created_by=user, organisation=organisation) mailout.save() for u in users: r = Recipient(user=u) r.mailout = mailout r.save() return mailout
def create_recipients(user_uid, machine_id, switch_id): recipient = Recipient() recipient.name = request.form['name'] recipient.email = request.form['email'] recipient.phone = request.form['phone'] recipient.user_id = user_uid recipient.tele_id = machine_id recipient.switch_id = switch_id db.session.add(recipient) db.session.commit() print(switch_id) return redirect(f'/recipient/{switch_id}/{user_uid}/{machine_id}')
def new(users, user, organisation_id=None): """Make and return a new mailout to be sent to the given list of users.""" if not user.is_staff: organisation_id = user.get_profile( ).representativeprofile.organisation.id organisation = None if organisation_id: organisation = Organisation.objects.get(pk=organisation_id) mailout = Mailout(created_by=user, organisation=organisation) mailout.save() for u in users: r = Recipient(user=u) r.mailout = mailout r.save() return mailout
def post(self, notif_id): try: result_dict = {'status': 'success'} notif = Notifier.get_by_id(int(notif_id)) phone_number = self.request.get('phone_number') name = self.request.get('name') email = self.request.get('email') phone_type = self.request.get('phoneType') recipient_id = self.request.get('recipient_id', '') if recipient_id != '': recipient = Recipient.get_by_id(int(recipient_id)) recipient.phone_number = phone_number recipient.phone_type = phone_type recipient.name = name recipient.email = email recipient.notifier = notif else: recipient = Recipient(phone_number=phone_number, name=name, email=email, phone_type=phone_type, notifier=notif) recipient.put() except: result_dict = {'status': 'failure'} self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(result_dict))
def edit_resource(resource_identifier): """edit a resource""" resource = Resource.query.filter_by(identifier=resource_identifier).first() if resource is None: flash(gettext('Resource not found'), 'danger') return redirect(request.referrer) probes_avail = views.get_probes_avail(resource.resource_type, resource) suggestions = json.dumps(Recipient.get_suggestions('email', g.user.username)) return render_template('edit_resource.html', lang=g.current_lang, resource=resource, suggestions=suggestions, probes_avail=probes_avail)
def edit_resource(resource_identifier): """edit a resource""" resource = Resource.query.filter_by(identifier=resource_identifier).first() if resource is None: flash(gettext('Resource not found'), 'danger') return redirect(request.referrer) probes_avail = views.get_probes_avail(resource.resource_type, resource) suggestions = json.dumps( Recipient.get_suggestions('email', g.user.username)) return render_template('edit_resource.html', lang=g.current_lang, resource=resource, suggestions=suggestions, probes_avail=probes_avail)
def create_feeds(): try: if not request.json: abort(400) else: feeds = Feeds(request.json['title'], request.json['author'], request.json['message'], request.json['lg_id'], int(time.time()), request.json['type']) session.add(feeds) session.commit() result = feeds.serialize() if 'recipients' in request.json: session.refresh(feeds) recipient = Recipient(request.json['recipients'], feeds.id) session.add(recipient) session.commit() result.update({'recipients': recipient.recipients}) if 'no_of_likes' in request.json: session.refresh(feeds) likes = Likes(feeds.id, request.json['no_of_likes']) session.add(likes) session.commit() result.update({'no_of_likes': likes.no_of_likes}) # return jsonify({ # "id": feeds.id, # "title": feeds.title, # "author": feeds.author, # "message": feeds.message, # "lg_id": feeds.lg_id, # "datetime": time.strftime('%d-%m-%Y %H:%M', time.localtime(feeds.datetime)), # "type": feeds.type, # "no_of_likes": likes.no_of_likes # }) return jsonify(result) except Exception as e: return (str(e))
def videos(): videos1 = [] videos2 = [] #<a href="{% url recipient video1r.slug %}">{{ video1r.name }}</a></p> #<p>How ProcrasDonate Works</p> pd = Recipient.get_or_none(slug='PD') if pd: if pd.promotional_video: videos2.append({ 'video': pd.promotional_video, 'caption': 'ProcrasDonate: Early Presentation' }) videos2.append({ 'video': "%sswf/LaptopIntro.swf" % settings.MEDIA_URL, 'caption': 'ProcrasDonate Intro' }) for ch in Recipient.objects.filter(is_visible=True, tax_exempt_status=True): if ch.promotional_video: videos1.append({ 'video': ch.promotional_video, 'caption': '<a href="%s">%s</a>' % (reverse('recipient', args=(ch.slug, )), ch.name) }) if ch.pd_experience_video: videos2.append({ 'video': ch.pd_experience_video, 'caption': '<a href="%s">%s\'s Experience with ProcrasDonate</a>' % (reverse('recipient', args=(ch.slug, )), ch.name) }) video1 = None video2 = None if videos1: video1 = videos1[randint(0, len(videos1) - 1)] if videos2: video2 = videos2[randint(0, len(videos2) - 1)] return {'video1': video1, 'video2': video2}
def remove(self, recipient_emails): '''Removes all the recipient in the given list from the database. Arguments: recipient_emails {list} -- The list of recipient emails. ''' self.__logger.info(f'Removing {len(recipient_emails)} recipients.') for email in recipient_emails: recipient = Recipient.get_or_none(Recipient.email == email.strip()) if recipient: recipient.delete_instance() else: self.__logger.warning( f'Recipient {email} was not in the database.' )
def notify_recipients_of_job(self, job, status): """Notifies the recipients of a change in job status. Arguments: job {job} -- The job to notify the recipients of. status {str} -- The job status to notify the recipients. Only two values acceptable, both as constants: EmailUtil.OPENED EmailUtil.CLOSED """ email_body = f''' {status} Title: {job.title} Dept.: {job.dept} Full Posting: {job.site_url} ''' for recipient in Recipient.select(): self.__create_message(job, email_body, recipient.email, status) self.__send_email(recipient.email)
def test_not_correct_type(test_recipient): with pytest.raises(InvalidUKMobileNumberException): bad_recipient = Recipient(dict(number=44123456)) bad_recipient.validate()
def recipient_from_tuple(recipient_tuple): recipient = Recipient() name, email = recipient_tuple recipient.mail = email return recipient
def test_invalid_uk_number(test_recipient): with pytest.raises(InvalidUKMobileNumberException): bad_recipient = Recipient(dict(number='123456')) bad_recipient.validate()
def mailout(request, mailout_id): mailout = get_object_or_404(Mailout, pk=mailout_id) if request.method == "POST": if "delete" in request.POST: if mailout.sent: messages.info( request, "Cannot delete a mailout that has already been sent.") else: mailout.delete() messages.info(request, "Mailout deleted.") return redirect("/mailouts/") elif "send" in request.POST: # Don't save changes in the form. form = forms.MailoutForm(instance=mailout) if mailout.sent: messages.info( request, "Mailout could not be sent because it has already been sent. This could happen if you accidentally click 'send' twice." ) else: logic.send(mailout, request) mailout.sent = datetime.datetime.now() mailout.sent_by = request.user mailout.save() messages.info(request, "Your mailout has been dispatched.") elif "save" in request.POST: form = forms.MailoutForm(request.POST) if mailout.sent: messages.info( request, "Mailout could not be saved because it has already been sent." ) elif form.is_valid(): mailout.subject = form.cleaned_data['subject'] mailout.body = form.cleaned_data['body'] mailout.save() form = forms.MailoutForm(instance=mailout) messages.info( request, "Mailout updated. Check the preview and, if the mailout is ready, click 'send' below the preview to dispatch the mailout." ) else: messages.info( request, "There is a problem with your mailout. Check the error messages below and try again." ) elif "delete_recipient" in request.POST: form = forms.MailoutForm(instance=mailout) if mailout.sent: messages.info( request, "Cannot delete recipient once mailout has been sent.") else: recipient = get_object_or_404( Recipient, pk=int(request.POST['recipient_id'])) recipient.delete() messages.info( request, "%s removed from recipient list" % recipient.user.get_full_name()) elif "new_recipient" in request.POST: form = forms.MailoutForm(instance=mailout) if mailout.sent: messages.info( request, "Cannot add recipient once mailout has been sent.") else: user = get_object_or_404(User, pk=int(request.POST['recipient_id'])) recipient = Recipient(user=user, mailout=mailout) recipient.save() messages.info( request, user.get_full_name() + " added to the recipient list.") else: form = forms.MailoutForm(request.POST, instance=mailout) messages.info(request, "Unrecognised action!") else: form = forms.MailoutForm(instance=mailout) return render_to_response("mailouts/mailout.html", { 'mailout': mailout, 'form': form, }, context_instance=RequestContext(request))