Esempio n. 1
0
def login(request):
    if request.method == 'POST':
        form = AuthenticationForm(data=request.POST)
        
        username = request.POST.get('username', '')
        password = request.POST.get('password', '')
        user = auth.authenticate(username=username, password=password)
        
        # this is used to check if the user is a cron user or a mop user
        # (also in if-clause
        # TODO: at the moment there is no proper error message when trying to login with a non-cron account
        # TODO: Code is almost identical to CRON-code
        if not user == None and user.is_active and isMop(user):
            auth.login(request, user)
            log_mop(request.user.mop, 'login')
            provlog_add_mop_login(request.user.mop, request.session.session_key)
            
            request.session['has_checked_inbox'] = False
            return HttpResponseRedirect(reverse('mop_index'))
            
        else:
            return render(request, 'mop/login.html', {'form' : form})
        
    else:
        form =  AuthenticationForm()
        return render(request, 'mop/login.html', {'form' : form})
Esempio n. 2
0
def mopmaker(request, missionInstance):
    if request.method == 'POST' and 'proceed' not in request.POST:
        mop_form = MopForm(request.POST, prefix="mop")
        user_form = UserCreationForm(request.POST, prefix="user")
        
        if mop_form.is_valid() and user_form.is_valid():
            #TODO check if all saves work and catch the error if they don't
            new_user = user_form.save()
            player = request.user.cron.player
            mop = mop_form.save(commit=False)
            mop.player = player
            mop.user = new_user
            mop.save()

            missionInstance.makeProgress()
            
            log_mop(mop, 'mop account created')
            provlog_add_mop_register(request.user.cron, mop, request.session.session_key)
            return redirect('cron_mission_debriefing', missionInstance.mission.serial)
        else:
            return render_to_response(   'cron/mopmaker.html',
                                        {"mop_form": mop_form, "user_form": user_form, "user": request.user, 'name':request.user.username, 'missionInstance':missionInstance},
                                        context_instance=RequestContext(request)
                                        )
    
    else:
        mop_form = MopForm(prefix="mop")
        user_form = UserCreationForm(prefix="user")
        return render_to_response(  'cron/mopmaker.html',
                                    {"mop_form": mop_form, "user_form": user_form, "user": request.user, 'name':request.user.username, 'missionInstance':missionInstance},
                                    context_instance=RequestContext(request)
                                )
Esempio n. 3
0
def forms_blank(request):
    
    # Create a blank form for all Forms that the mop user should have at start
    initialRequisitions = Requisition.objects.filter(isInitial=True)
    for initial in initialRequisitions:
        RequisitionBlank.objects.get_or_create(mop=request.user.mop, requisition=initial)
            
    blank_list = RequisitionBlank.objects.filter(mop=request.user.mop).order_by('requisition__category')            
    
    log_mop(request.user.mop, 'blank forms')
    return render(request, 'mop/forms_blank.html', {"blank_list": blank_list})
Esempio n. 4
0
def pool(request):

    randomizedDocument_list = RandomizedDocument.objects.filter(active=True)
    mopDocumentInstance_list = MopDocumentInstance.objects.filter(mop=request.user.mop)
    
        
    for randomizedDocument in randomizedDocument_list:
        for mopDocumentInstance in mopDocumentInstance_list:
            if mopDocumentInstance.randomizedDocument == randomizedDocument:
                randomizedDocument.exists = True
                break
        
 
    log_mop(request.user.mop, 'view pool')   
    return render(request, 'mop/pool.html', {"randomizedDocument_list": randomizedDocument_list})
Esempio n. 5
0
def mail_untrashing(request, mail_id):
    try:
        mail = Mail.objects.get(id=mail_id, mop=request.user.mop, state=Mail.STATE_TRASHED)
    except Mail.DoesNotExist:
        return redirect('mop_index')
    mail.read = True
    mail.state = Mail.STATE_NORMAL
    mail.save()
    
    if not mail == None:
        m ={}
        m['id'] = mail.id
        m['subject'] = mail.subject
        log_mop(request.user.mop, 'untrash mail', json.dumps(m))
    
    return redirect('mop_mail_trash')
Esempio n. 6
0
def mail_view(request, mail_id):
    try:
        mail = Mail.objects.get(id=mail_id, mop=request.user.mop)
        mail.read = True
        mail.save()
    except Mail.DoesNotExist:
        mail = None
    
    request.session['inbox_unread'] = Mail.objects.filter(mop=request.user.mop).filter(state=Mail.STATE_NORMAL).filter(type=Mail.TYPE_RECEIVED).filter(read=False).count()
    
    if not mail == None:
        m ={}
        m['id'] = mail.id
        m['subject'] = mail.subject
        log_mop(request.user.mop, 'view mail', json.dumps(m))
    
    return render(request, 'mop/mail_view.html', {'mail': mail})
Esempio n. 7
0
def mail_deleting(request, mail_id):
    try:
        mail = Mail.objects.get(id=mail_id, mop=request.user.mop, state=Mail.STATE_TRASHED)
    except Mail.DoesNotExist:
        #TODO Error handling
        return redirect('mop_index')
    mail.read = True
    mail.state = Mail.STATE_DELETED
    mail.save()
    
    if not mail == None:
        m ={}
        m['id'] = mail.id
        m['subject'] = mail.subject
        log_mop(request.user.mop, 'delete mail', json.dumps(m))
    
    return redirect('mop_mail_trash')
Esempio n. 8
0
def performance(request):
    badge_list = Badge.objects.filter(mop=request.user.mop).order_by('-modifiedAt')
    
#     taskInstance_list = TaskInstance.objects.filter(mop=request.user.mop).exclude(status=TaskInstance.STATUS_ACTIVE).order_by('modifiedAt')
#     print taskInstance_list
#     
#     #creationDate = request.user.mop.created
#     creationDate = request.user.mop.created - timedelta(weeks=-3)
#     today = now()
#     print creationDate
#     print today
#     nextMonday = timedelta(days=-today.weekday(), weeks=1)
#     lastMonday = today - timedelta(days=today.weekday())
#     print nextMonday
#     print lastMonday
#     weekTrust_list = WeekTrust.objects.filter(mop=request.user.mop).order_by('-year', '-week')
    log_mop(request.user.mop, 'read performance')
    return render(request, 'mop/performance.html', {'badge_list':badge_list})
Esempio n. 9
0
def index(request):

    if not request.user == None and request.user.is_active and isMop(request.user):
        #MAIL MANAGING
        inbox_unread = Mail.objects.filter(mop=request.user.mop).filter(state=Mail.STATE_NORMAL).filter(type=Mail.TYPE_RECEIVED).filter(read=False).count()
        outbox_unread = Mail.objects.filter(mop=request.user.mop).filter(state=Mail.STATE_NORMAL).filter(type=Mail.TYPE_SENT).filter(read=False).count()
        trash_unread = Mail.objects.filter(mop=request.user.mop).filter(state=Mail.STATE_TRASHED).filter(read=False).count()
        draft_unread = Mail.objects.filter(mop=request.user.mop).filter(state=Mail.STATE_NORMAL).filter(type=Mail.TYPE_DRAFT).filter(read=False).count()
        
        request.session['inbox_unread'] = inbox_unread
        
        
        log_mop(request.user.mop, 'index')
        context = {'user': request.user, 'inbox_unread': inbox_unread, 'outbox_unread': outbox_unread, 'trash_unread': trash_unread, 'draft_unread': draft_unread}

        return render(request, 'mop/index.html', context)
    
    else:
        return login(request)
Esempio n. 10
0
def mail_trashing(request, mail_id):
    try:
        mail = Mail.objects.get(id=mail_id, mop=request.user.mop, state=Mail.STATE_NORMAL)
    except Mail.DoesNotExist:
        #TODO Error handling
        return redirect('mop_index')
    mail.state = Mail.STATE_TRASHED
    mail.save()
    
    if not mail == None:
        m ={}
        m['id'] = mail.id
        m['subject'] = mail.subject
        log_mop(request.user.mop, 'trash mail', json.dumps(m))
    
    if mail.type == Mail.TYPE_RECEIVED:
        return redirect('mop_mail_inbox')
    elif mail.type == Mail.TYPE_SENT:
        return redirect('mop_mail_outbox')
    elif mail.type == Mail.TYPE_DRAFT:
        return redirect('mop_mail_draft')
Esempio n. 11
0
def form_fill(request, reqBlank_id):
    #TODO check if user has rights to access the requisition in the first place
    try:
        reqBlank = RequisitionBlank.objects.get(id=reqBlank_id)
    except RequisitionBlank.DoesNotExist:
        reqBlank=None
        
    if request.method == 'POST':
        requisitionInstance = RequisitionInstance(blank=reqBlank)
        form = RequisitionInstanceForm(data=request.POST, instance=requisitionInstance)
        if form.is_valid():
            form.save()
            
            f ={}
            f['form_id'] = reqBlank.requisition.id
            f['form_name'] = reqBlank.requisition.name
            f['instance_id'] = requisitionInstance.id
            f['data'] = form.data
            log_mop(request.user.mop, 'fill form', json.dumps(f))
            provlog_add_mop_sign_form(request.user.mop, requisitionInstance, request.session.session_key)
            return redirect('mop_forms_signed')
    else:
        form = RequisitionInstanceForm()
        return render(request, 'mop/forms_fill.html', {"reqBlank": reqBlank, "form": form}, context_instance=RequestContext(request))
Esempio n. 12
0
def rules(request):
    unit_list = Unit.objects.all()
    requisition_list = Requisition.objects.all().order_by('category')
    log_mop(request.user.mop, 'read rules')
    return render(request, 'mop/rules.html', {"unit_list":unit_list, "requisition_list": requisition_list})
Esempio n. 13
0
def logout_view(request):
    log_mop(request.user.mop, 'logout')
    provlog_add_mop_logout(request.user.mop, request.session.session_key)
    logout(request)
    return redirect('mop_index')
Esempio n. 14
0
def documents(request):
    mopDocumentInstance_list = MopDocumentInstance.objects.filter(mop=request.user.mop).filter(used=False).filter(status=MopDocumentInstance.STATUS_ACTIVE)
    
    log_mop(request.user.mop, 'view documents')
    return render(request, 'mop/documents.html', {"mopDocumentInstance_list": mopDocumentInstance_list})
Esempio n. 15
0
def forms_signed(request):
    requisitionInstance_list = RequisitionInstance.objects.filter(blank__mop=request.user.mop).filter(used=False).order_by("-modifiedAt")
    requisitionInstance_used_list = RequisitionInstance.objects.filter(blank__mop=request.user.mop).filter(used=True).order_by("-modifiedAt")
    
    log_mop(request.user.mop, 'view filled forms')
    return render(request, 'mop/forms_signed.html', {"requisitionInstance_list": requisitionInstance_list, "requisitionInstance_used_list": requisitionInstance_used_list})
Esempio n. 16
0
def mail_inbox(request):
    mail_list = Mail.objects.filter(mop=request.user.mop).filter(state=Mail.STATE_NORMAL).filter(type=Mail.TYPE_RECEIVED).order_by('-createdAt')
    request.session['inbox_unread'] = Mail.objects.filter(mop=request.user.mop).filter(state=Mail.STATE_NORMAL).filter(type=Mail.TYPE_RECEIVED).filter(read=False).count()
    request.session['has_checked_inbox'] = True
    log_mop(request.user.mop, 'view inbox')
    return render(request, 'mop/mail_inbox.html', {"mail_list": mail_list})
Esempio n. 17
0
def mail_draft(request):
    mail_list = Mail.objects.filter(mop=request.user.mop).filter(state=Mail.STATE_NORMAL).filter(type=Mail.TYPE_DRAFT).order_by('-createdAt')
    log_mop(request.user.mop, 'view drafts')
    return render(request, 'mop/mail_draft.html', {"mail_list": mail_list})
Esempio n. 18
0
def mail_trash(request):
    mail_list = Mail.objects.filter(mop=request.user.mop).filter(state=Mail.STATE_TRASHED).order_by('-createdAt')
    log_mop(request.user.mop, 'view trash')
    return render(request, 'mop/mail_trash.html', {"mail_list": mail_list})