示例#1
0
def mail_edit(request, mail_id):
    try:
        mail = Mail.objects.get(id=mail_id)
    except mail.DoesNotExist:
        #TODO error handling
        return redirect('mop_mail_index')
    
    if request.method == 'POST':
        if 'send' in request.POST:
            mail.type = Mail.TYPE_SENT
            mail.read = True
        elif 'draft' in request.POST:
            mail.type = Mail.TYPE_DRAFT
            mail.read = False
        
        form = MailForm(data=request.POST, instance=mail)
        print mail.id
        if form.is_valid():
            mail.processed = False
            mail = form.save()
            
            if mail.type == Mail.TYPE_SENT:
                if not mail.requisitionInstance == None:
                    mail.requisitionInstance.used = True
                    mail.requisitionInstance.save()
                if not mail.mopDocumentInstance == None:
                    mail.mopDocumentInstance.used = True
                    mail.mopDocumentInstance.save()
            
            #TODO remove for real game
            analyze_mail()    
            return redirect('mop_index')
        else:
            form.fields["requisitionInstance"].queryset = RequisitionInstance.objects.filter(blank__mop=request.user.mop).filter(used=False).order_by('-modifiedAt')
            form.fields["mopDocumentInstance"].queryset = MopDocumentInstance.objects.filter(mop=request.user.mop)
            form.fields["subject"].choices = Mail.CHOICES_SUBJECT_SENDING
            return render(request, 'mop/mail_compose.html', {'form' : form, 'mail':mail})
        
    else:
        form = MailForm(instance=mail)
        #TODO same with documents at all occurences
        form.fields["requisitionInstance"].queryset = RequisitionInstance.objects.filter(blank__mop=request.user.mop).filter(used=False).order_by('-modifiedAt')
        form.fields["mopDocumentInstance"].queryset = MopDocumentInstance.objects.filter(mop=request.user.mop)
        form.fields["subject"].choices = Mail.CHOICES_SUBJECT_SENDING
        return render(request, 'mop/mail_compose.html', {'form' : form, 'mail':mail})
示例#2
0
def mail_compose(request):
    #TODO Mail needs a sentAt / savedAt value so that trashing email does not change its date
    if request.method == 'POST':
        mail = Mail(mop=request.user.mop, type=Mail.TYPE_SENT)
        if 'send' in request.POST:
            mail.type = Mail.TYPE_SENT
            mail.read = True
        elif 'draft' in request.POST:
            mail.type = Mail.TYPE_DRAFT
            mail.read = False
        form = MailForm(data=request.POST, instance=mail)
        
        if form.is_valid():
            mail.processed = False
            mail = form.save()
            if mail.type == Mail.TYPE_SENT:
                if not mail.requisitionInstance == None:
                    mail.requisitionInstance.used = True
                    mail.requisitionInstance.save()
                if not mail.mopDocumentInstance == None:
                    mail.mopDocumentInstance.used = True
                    mail.mopDocumentInstance.save()
            
            
            #TODO remove for real game
            analyze_mail()    
            return redirect('mop_index')
        else:
            #TODO code duplication between here and the else below
            form.fields["requisitionInstance"].queryset = RequisitionInstance.objects.filter(blank__mop=request.user.mop).filter(used=False).order_by('-modifiedAt')
            form.fields["mopDocumentInstance"].queryset = MopDocumentInstance.objects.filter(mop=request.user.mop).filter(used=False).order_by('-modifiedAt')
            form.fields["subject"].choices = Mail.CHOICES_SUBJECT_SENDING
            return render(request, 'mop/mail_compose.html', {'form' : form,})
        
    else:
        form =  MailForm()
        form.fields["requisitionInstance"].queryset = RequisitionInstance.objects.filter(blank__mop=request.user.mop).filter(used=False).order_by('-modifiedAt')
        form.fields["mopDocumentInstance"].queryset = MopDocumentInstance.objects.filter(mop=request.user.mop).filter(used=False).order_by('-modifiedAt')
        form.fields["subject"].choices = Mail.CHOICES_SUBJECT_SENDING
        return render(request, 'mop/mail_compose.html', {'form' : form,})
示例#3
0
def control(request):
    output = None
    if request.method == 'POST':
        if 'mail' in request.POST:
            output = analyze_mail()
        elif 'performance' in request.POST:
            output = analyze_performance()
        elif 'randomizer' in request.POST:
            output = create_documents()
    return render(request, 'mop/control.html', {'output':output})       


    
    
示例#4
0
 def handle_noargs(self, **options):
     analyze_mail()