def demo(request): """Logs in a demo user""" # Check if it's possible to login if User.objects.filter(login__endswith='@demo.athena').count() > 1000: # Attempt to remove superficial accounts k = User.objects.filter(status=1, login__endswith='@demo.athena') \ .filter(created_on__lt=datetime.now() - timedelta(1)) for x in k: x.delete() if User.objects.filter(login__endswith='@demo.athena').count() > 1000: messages.add_message(request, messages.ERROR, u'Błąd: przeciążenie systemu') return redirect('/') target_login = '******' % (randint(0, 10000000)) su = User(name='Tymczasowe konto DEMO', surname='', login=target_login, number=0) su.save() Group.get_demo_group().students.add(su) request.login(target_login) messages.add_message(request, messages.INFO, u'Zalogowano demonstracyjnie.') return redirect('/')
def start_demo_exam(request, test_id): demogrp = Group.get_demo_group() test = Test.objects.get(id=int(test_id)) if not test.is_demo: return HttpResponse(status=400) # Is the student writing an exam right now? try: tbw = TestBeingWritten.objects.get(written_by=request.user) except TestBeingWritten.DoesNotExist: pass else: messages.add_message(request, messages.ERROR, u'Egzamin już jest pisany!') # Try to automatically detect an exam and term for this one, a demo one try: exam = Exam.objects.get(test=test, group=demogrp) except Exam.DoesNotExist: exam = Exam(test=test, group=demogrp, name=u'DEMO EGZAMIN', owner=demogrp.teacher) exam.save() # Fetch term for this one try: term = exam.term_set.all()[0] except: term = Term(exam=exam, name=u'DEMO TERMIN', term_time=datetime.now(), is_progressing=True) term.save() # Create a TBW for this student now tbw = TestBeingWritten(term=term, written_by=request.user) tbw.save() tbw.set_test_written(TestWritten(test)) return redirect('/test/')