示例#1
0
def mail_update_view(request):
    mail = get_object_or_404(Mail.my_mails(request.user),
                             pk=request.POST['mail_id'])
    saved_dues = Due.objects.filter(mail=mail).values_list('id', flat=True)
    edited_dues = []

    dues = request.POST.lists()

    for due in dues:
        if due[0] == 'due-new':
            for dt in due[1]:
                if dt:
                    d = Due(mail=mail, due=dt)
                    d.save()
                    edited_dues.append(d.id)
                else:
                    messages.error(request, 'Please fill out the due date.')
        else:
            try:
                due_id = int(re.sub(r'due-', '', due[0]))
                d = Due.objects.get(mail=mail, pk=due_id)
                d.due = due[1][0]
                d.save()
                edited_dues.append(due_id)
            except:
                pass

    for saved_due in saved_dues:
        if saved_due not in edited_dues:
            d = Due.objects.get(mail=mail, pk=saved_due)
            d.delete()

    return HttpResponseRedirect('/mails/')
示例#2
0
def mail_update_view(request):
    mail = get_object_or_404(Mail.my_mails(request.user), pk=request.POST["mail_id"])
    saved_dues = Due.objects.filter(mail=mail).values_list("id", flat=True)
    edited_dues = []

    dues = request.POST.lists()

    for due in dues:
        if due[0] == "due-new":
            for dt in due[1]:
                if dt:
                    parsed_due_date = dateparser.parse(
                        dt, settings=settings.DATEPARSER_SETTINGS
                    )
                    d = Due(mail=mail, due=parsed_due_date)
                    d.save()
                    edited_dues.append(d.id)
                else:
                    messages.error(request, "Please fill out the due date.")
        else:
            try:
                due_id = int(re.sub(r"due-", "", due[0]))
            except ValueError:
                continue
            d = mail.dues.get(pk=due_id)
            d.due = dateparser.parse(due[1][0], settings=settings.DATEPARSER_SETTINGS)
            d.save()
            edited_dues.append(due_id)

    for saved_due in saved_dues:
        if saved_due not in edited_dues:
            d = Due.objects.get(mail=mail, pk=saved_due)
            d.delete()

    return HttpResponseRedirect("/mails/")
示例#3
0
def mail_delete_view(request):
    mail_id = request.POST.get('id')
    mail = get_object_or_404(Mail.my_mails(request.user), pk=mail_id)

    imap_conn = imaphelper.get_connection()
    imap_mail = imaphelper.IMAPMessage.from_dbid(mail_id, imap_conn)
    mail.delete()
    imap_mail.delete()

    return HttpResponseRedirect("/")
示例#4
0
def download_calendar_view(request, secret):
    username = base64.urlsafe_b64decode(secret.encode('utf-8'))
    user = User.objects.get(username=username)
    dues = Due.objects.filter(mail__in=Mail.my_mails(user))
    cal = Calendar()
    cal.add('prodid', '-//rmd.io Events Calendar//%s//EN' % settings.SITE_URL)
    cal.add('version', '2.0')

    for due in dues:
        event = Event()
        event.add('summary', '%s [rmd.io]' %
                  tools.calendar_clean_subject(due.mail.subject))
        event.add('description', '%s/mails/' % settings.SITE_URL)
        event.add('dtstart', due.due)
        event.add('dtend', due.due)
        cal.add_component(event)

    response = HttpResponse(content=cal.to_ical(), content_type='text/calendar')
    response['Content-Disposition'] = 'attachment; filename=maildelay.ics'

    return response
示例#5
0
def download_calendar_view(request, secret):
    username = base64.urlsafe_b64decode(secret).decode("utf-8")
    user = User.objects.get(username=username)
    dues = Due.objects.filter(mail__in=Mail.my_mails(user))
    cal = Calendar()
    cal.add("prodid", "-//rmd.io Events Calendar//%s//EN" % settings.SITE_URL)
    cal.add("version", "2.0")

    for due in dues:
        event = Event()
        event.add(
            "summary", "%s [rmd.io]" % tools.calendar_clean_subject(due.mail.subject)
        )
        event.add("description", "%s/mails/" % settings.SITE_URL)
        event.add("dtstart", due.due)
        event.add("dtend", due.due)
        cal.add_component(event)

    response = HttpResponse(content=cal.to_ical(), content_type="text/calendar")
    response["Content-Disposition"] = "attachment; filename=maildelay.ics"

    return response
示例#6
0
def mail_delete_confirm_view(request, id):
    mail = get_object_or_404(Mail.my_mails(request.user), pk=id)
    return render(request, 'mails/mail_delete_confirm.html', {'mail': mail})
示例#7
0
def mail_info_view(request, id):
    mail = get_object_or_404(Mail.my_mails(request.user), pk=id)
    return render(request, 'mails/mail_info.html', {'mail': mail})
示例#8
0
 def get_queryset(self):
     if self.request.user.is_authenticated():
         mails = Mail.my_mails(self.request.user)
         return sorted(mails, key=lambda m: m.next_due().due)