Exemplo n.º 1
0
    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
Exemplo n.º 2
0
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}')
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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))
Exemplo n.º 5
0
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))
Exemplo n.º 6
0
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
Exemplo n.º 7
0
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))
Exemplo n.º 8
0
def recipient_from_tuple(recipient_tuple):
    recipient = Recipient()
    name, email = recipient_tuple
    recipient.mail = email
    return recipient