Ejemplo n.º 1
0
def setup_database():
    db.create_all()

    u1 = Student('Heather', 'Freeman', '*****@*****.**', 'Abc123',
                 'student')
    u2 = Student('Amanda', 'Evans', '*****@*****.**', 'Cde456',
                 'student')
    u3 = Student('Jerry', 'White', '*****@*****.**', 'qwerty123', 'student')
    u4 = Student('Jane', 'Berry', '*****@*****.**', 'tyu1234', 'student')
    u5 = Student('Lori', 'Welch', '*****@*****.**', 'erg34345', 'student')
    u6 = Student('Dorothy', 'Medina', '*****@*****.**', 'bfdg2',
                 'student')
    u7 = Student('Lawrence', 'Foster', '*****@*****.**', 'regergs2',
                 'student')
    u8 = Student('Annie', 'Pierce', '*****@*****.**', 'bfg3', 'student')
    u9 = Student('Melissa', 'Taylor', '*****@*****.**', 'eret3',
                 'student')
    u10 = Student('Deborah', 'Richards', '*****@*****.**', 'opi234',
                  'student')

    t1 = Teacher('Albert', 'Morris', '*****@*****.**', 'abc123', 'teacher')
    t2 = Teacher('Jane', 'Ripper', '*****@*****.**', 'abc123', 'teacher')

    task1 = Task(1, 1, 1)
    task2 = Task(2, 1, 1)
    task3 = Task(1, 2, 1)
    task3.mark_id = 1
    task3.completed = True

    m1 = Mark(7, 10, 1, 2)
    m2 = Mark(1, 10, 3, 3)
    m3 = Mark(1, 10, 5, 3)
    m4 = Mark(4, 10, 5, 3)
    m5 = Mark(5, 10, 4, 3)
    m6 = Mark(3, 10, 2, 4)

    db.session.add_all([u1, u2, u3, u4, u5, u6, u7, u8, u9, u10, t1, t2])
    db.session.add_all([task1, task2, task3])
    db.session.add_all([m1, m2, m3, m4, m5, m6])

    links = [
        t1.add_student(u1),
        t1.add_student(u2),
        t1.add_student(u3),
        t1.add_student(u8),
        t1.add_student(u9)
    ]
    db.session.add_all(links)

    db.session.commit()

    graph1 = Graph(
        '{"version":2,"graph":{"showGrid":true,"showXAxis":true,"showYAxis":true,"xAxisStep":0,"yAxisStep":0,"xAxisMinorSubdivisions":0,"yAxisMinorSubdivisions":0,"xAxisArrowMode":"NONE","yAxisArrowMode":"NONE","xAxisLabel":"Re","yAxisLabel":"Im","xAxisNumbers":true,"yAxisNumbers":true,"polarMode":false,"polarNumbers":true,"degreeMode":false,"projectorMode":false,"squareAxes":true,"viewport":{"xmin":-1.6708536134523648,"ymin":-1.9601353023240395,"xmax":1.9920012573229602,"ymax":1.847026847468353}},"expressions":{"list":[{"id":"0","type":"expression","latex":"\\sqrt{x^2+y^2}-\\sqrt{x^2+\\left(y+1\\right)^2}=0","domain":{"min":0,"max":1},"hidden":false,"color":"#2d70b3","style":"normal","residualVariable":"","regressionParameters":{},"isLogModeRegression":false},{"id":"1","type":"expression","latex":"\\sqrt{x^2+y^2}-\\sqrt{y^2+\\left(x-1\\right)^2}=0","domain":{"min":0,"max":1},"hidden":false,"color":"#388c46","style":"normal","residualVariable":"","regressionParameters":{},"isLogModeRegression":false}]}}',
        '<thead><tr><th>Plot</th><th></th><th></th></tr></thead><tbody> <tr id="row0"><td><span class="MathJax_Preview" style="color: inherit; display: none;"></span><span class="MathJax" id="MathJax-Element-2-Frame" tabindex="0" style="position: relative;" data-mathml="<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mstyle displaystyle=&quot;true&quot;><mrow><mo>|</mo><mi>z</mi><mo>|</mo></mrow><mo>=</mo><mrow><mo>|</mo><mi>z</mi><mo>+</mo><mi>i</mi><mo>|</mo></mrow></mstyle></math>" role="presentation"><nobr aria-hidden="true"><span class="math" id="MathJax-Span-128" style="width: 6.074em; display: inline-block;"><span style="display: inline-block; position: relative; width: 5.06em; height: 0px; font-size: 120%;"><span style="position: absolute; clip: rect(1.691em, 1004.93em, 2.927em, -1000em); top: -2.56em; left: 0em;"><span class="mrow" id="MathJax-Span-129"><span class="mstyle" id="MathJax-Span-130"><span class="mrow" id="MathJax-Span-131"><span class="mrow" id="MathJax-Span-132"><span class="mo" id="MathJax-Span-133" style="font-family: STIXVariants;">|</span><span class="mi" id="MathJax-Span-134" style="font-family: STIXGeneral; font-style: italic;">z</span><span class="mo" id="MathJax-Span-135" style="font-family: STIXVariants;">|</span></span><span class="mo" id="MathJax-Span-136" style="font-family: STIXGeneral; padding-left: 0.375em; padding-right: 0.375em;">=</span><span class="mrow" id="MathJax-Span-137"><span class="mo" id="MathJax-Span-138" style="font-family: STIXVariants;">|</span><span class="mi" id="MathJax-Span-139" style="font-family: STIXGeneral; font-style: italic;">z</span><span class="mo" id="MathJax-Span-140" style="font-family: STIXGeneral; padding-left: 0.3em; padding-right: 0.3em;">+</span><span class="mi" id="MathJax-Span-141" style="font-family: STIXGeneral; font-style: italic;">i</span><span class="mo" id="MathJax-Span-142" style="font-family: STIXVariants;">|</span></span></span></span></span><span style="display: inline-block; width: 0px; height: 2.56em;"></span></span></span><span style="display: inline-block; overflow: hidden; vertical-align: -0.298em; border-left: 0px solid; width: 0px; height: 1.198em;"></span></span></nobr><span class="MJX_Assistive_MathML" role="presentation"><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true"><mrow><mo>|</mo><mi>z</mi><mo>|</mo></mrow><mo>=</mo><mrow><mo>|</mo><mi>z</mi><mo>+</mo><mi>i</mi><mo>|</mo></mrow></mstyle></math></span></span><script type="math/asciimath" id="MathJax-Element-2">|z|=|z+i|</script></td><td><input name="plot" id="0" checked="" type="checkbox"></td><td><input class="btn btn-block" name="del" id="del0" value="X" type="button"></td></tr><tr id="row1"><td><span class="MathJax_Preview" style="color: inherit; display: none;"></span><span class="MathJax" id="MathJax-Element-3-Frame" tabindex="0" style="position: relative;" data-mathml="<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mstyle displaystyle=&quot;true&quot;><mrow><mo>|</mo><mi>z</mi><mo>|</mo></mrow><mo>=</mo><mrow><mo>|</mo><mi>z</mi><mo>-</mo><mn>1</mn><mo>|</mo></mrow></mstyle></math>" role="presentation"><nobr aria-hidden="true"><span class="math" id="MathJax-Span-201" style="width: 6.372em; display: inline-block;"><span style="display: inline-block; position: relative; width: 5.298em; height: 0px; font-size: 120%;"><span style="position: absolute; clip: rect(1.691em, 1005.17em, 2.927em, -1000em); top: -2.56em; left: 0em;"><span class="mrow" id="MathJax-Span-202"><span class="mstyle" id="MathJax-Span-203"><span class="mrow" id="MathJax-Span-204"><span class="mrow" id="MathJax-Span-205"><span class="mo" id="MathJax-Span-206" style="font-family: STIXVariants;">|</span><span class="mi" id="MathJax-Span-207" style="font-family: STIXGeneral; font-style: italic;">z</span><span class="mo" id="MathJax-Span-208" style="font-family: STIXVariants;">|</span></span><span class="mo" id="MathJax-Span-209" style="font-family: STIXGeneral; padding-left: 0.375em; padding-right: 0.375em;">=</span><span class="mrow" id="MathJax-Span-210"><span class="mo" id="MathJax-Span-211" style="font-family: STIXVariants;">|</span><span class="mi" id="MathJax-Span-212" style="font-family: STIXGeneral; font-style: italic;">z</span><span class="mo" id="MathJax-Span-213" style="font-family: STIXGeneral; padding-left: 0.3em; padding-right: 0.3em;">−</span><span class="mn" id="MathJax-Span-214" style="font-family: STIXGeneral;">1</span><span class="mo" id="MathJax-Span-215" style="font-family: STIXVariants;">|</span></span></span></span></span><span style="display: inline-block; width: 0px; height: 2.56em;"></span></span></span><span style="display: inline-block; overflow: hidden; vertical-align: -0.298em; border-left: 0px solid; width: 0px; height: 1.198em;"></span></span></nobr><span class="MJX_Assistive_MathML" role="presentation"><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true"><mrow><mo>|</mo><mi>z</mi><mo>|</mo></mrow><mo>=</mo><mrow><mo>|</mo><mi>z</mi><mo>-</mo><mn>1</mn><mo>|</mo></mrow></mstyle></math></span></span><script type="math/asciimath" id="MathJax-Element-3">|z|=|z-1|</script></td><td><input name="plot" id="1" checked="" type="checkbox"></td><td><input class="btn btn-block" name="del" id="del1" value="X" type="button"></td></tr></tbody>',
        2, '2 Lines', '',
        'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAPWklEQVR4nO3dXVBU9xnH8UN7k15wZ/ei5cIyGTJDpzR1hs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SZWz45zX6y85GWvz3i/T+Z030j9O3aLf9Nu2236bNhy7TOxsP0rQZObrx41/Opnc2HqSNBxtpx+mW0GtGj8r9F3Wvm/7yPFqx7ThtO3ZNmbtozW7D5aTNWqz896I1u2nX2XbD5cVi4DIvQ/F4mdfn8+keGzEbZjcCx3ry1+j/R6+trTVdRnFxcVz+JdgAwlA8AolVjx49ovr6empsbKTz58/T9evX4/rvzwIQhgBEbgDC0FQG4vP54voT4GkDEIamMpCp/HsjAhCWAERuAMIQgMgNQBgCELkBCEMAIjcAYQhA5AYgDAGI3ACEIQCRG4AwBCByAxCGAERuAMIQgMgNQBgCELkBCEMAIjcAYQhA5AYgDAGI3ACEIQCRG4AwBCByAxCGAERuAMIQgMgNQBgCELlpIxsY6+FwOMjhcMR8PaIxRv/bfAkJCVFbjnVvMS3Z864ybt1ux+/tKYYW6xX4f/hBA4jcgUMshnCIJTcAYQhA5AYgDAGI3ACEIQCRG4AwBCByAxCGAERuAMIQgMgNQBgCELkBCEMAIjcAYQhA5AYgDAGI3ACEIQCRG4AwBCByAxCGAERuAMIQgMgNQBgCELkBCEMAIjcAYQhA5AYgDAGI3ACEIQCRG4AwBCByAxCGAERuAMIQgMgNQBgCELkBCEMAIjcAYQhA5AYgDAGI3ACEIQCRG4AwBCByAxCGAERuAMIQgMgNQBgCELkBCEMAIjcAYQhA5AYgDAGI3ACEIQCRG4AwBCByAxCGAERuAMIQgMgNQBgCELkBCEMAIjcAYQhA5AYgDAGI3ACEIQCRG4AwBCByAxCGAERuAMIQgMgNQBgCELn9B4KLRTkmtn8TAAAAAElFTkSuQmCC'
    )

    db.session.add(graph1)
    db.session.commit()
Ejemplo n.º 2
0
def views(request):

    data = {'title': 'To Do Application - My Lists'}

    if request.method == 'POST':
        if 'action' in request.POST and request.POST['action'] != '':
            action = request.POST['action']

            if action == 'create':
                try:
                    with transaction.atomic():
                        f = ListForm(request.POST)
                        if f.is_valid():
                            name = f.cleaned_data['name']
                            priority = f.cleaned_data['priority']
                            assigned_to = f.cleaned_data['assigned_to']
                            due_date = f.cleaned_data['due_date']

                            if not name:
                                return bad_json(
                                    message='Please enter a list name.')

                            if not priority:
                                return bad_json(
                                    message='Please select a priority.')

                            if not assigned_to:
                                return bad_json(
                                    message=
                                    'Please select a user to assign this list.'
                                )

                            if not due_date:
                                return bad_json(
                                    message=
                                    'Please select a due date for this list.')

                            list = List(name=name,
                                        priority=priority,
                                        assigned_to=assigned_to,
                                        created_by=request.user,
                                        due_date=due_date)
                            list.save()

                            return ok_json(
                                data={
                                    'message':
                                    'You have successfully created a list',
                                    'redirect_url': '/lists'
                                })
                        else:
                            # for field in f.errors:
                            #     error = field + ": " + field.data[0]
                            #     break
                            return bad_json(extradata={'errors': f._errors})
                except Exception as ex:
                    return bad_json(message=ex.__str__())

            if action == 'edit':
                try:
                    with transaction.atomic():
                        f = ListForm(request.POST)
                        if f.is_valid():
                            name = f.cleaned_data['name']
                            priority = f.cleaned_data['priority']
                            assigned_to = f.cleaned_data['assigned_to']
                            due_date = f.cleaned_data['due_date']
                            list = None

                            if 'id' in request.POST and request.POST[
                                    'id'] != '':
                                if List.objects.filter(
                                        id=int(request.POST['id'])).exists():
                                    list = List.objects.get(
                                        id=int(request.POST['id']))

                            if not list:
                                return bad_json(
                                    message='Please select a list to edit.')

                            if not name:
                                return bad_json(
                                    message='Please enter a list name.')

                            if not priority:
                                return bad_json(
                                    message='Please select a priority.')

                            if not assigned_to:
                                return bad_json(
                                    message=
                                    'Please select a user to assign this list.'
                                )

                            if not due_date:
                                return bad_json(
                                    message=
                                    'Please select a due date for this list.')

                            list.name = name
                            list.priority = priority
                            list.assigned_to = assigned_to
                            list.due_date = due_date
                            list.save()

                            return ok_json(
                                data={
                                    'message':
                                    'You have successfully edited a list',
                                    'redirect_url': '/lists'
                                })
                        else:
                            return bad_json(extradata={'errors': f._errors})
                except Exception as ex:
                    return bad_json(message=ex.__str__())

            if action == 'add_task':
                try:
                    with transaction.atomic():
                        f = TaskForm(request.POST)
                        if f.is_valid():
                            title = f.cleaned_data['title']
                            priority = f.cleaned_data['priority']
                            assigned_to = f.cleaned_data['assigned_to']
                            due_date = f.cleaned_data['due_date']
                            note = f.cleaned_data['note']
                            list = None

                            if 'id' in request.POST and request.POST[
                                    'id'] != '':
                                if List.objects.filter(
                                        id=int(request.POST['id'])).exists():
                                    list = List.objects.get(
                                        id=int(request.POST['id']))

                            if not list:
                                return bad_json(
                                    message=
                                    'Please select a list to add this task to.'
                                )

                            if not title:
                                return bad_json(
                                    message='Please enter a task title.')

                            if not priority:
                                return bad_json(
                                    message='Please select a priority.')

                            if not assigned_to:
                                return bad_json(
                                    message=
                                    'Please select a user to assign this task to.'
                                )

                            if not due_date:
                                return bad_json(
                                    message=
                                    'Please select a due date for this task.')

                            if not note:
                                return bad_json(
                                    message='Please enter a note for this task.'
                                )

                            task = Task(list=list,
                                        title=title,
                                        priority=priority,
                                        assigned_to=assigned_to,
                                        created_by=request.user,
                                        due_date=due_date,
                                        note=note)
                            task.save()

                            return ok_json(
                                data={
                                    'message':
                                    'You have successfully added a task',
                                    'redirect_url':
                                    '/lists?action=view&id={}'.format(list.id)
                                })
                        else:
                            # for field in f.errors:
                            #     error = field + ": " + field.data[0]
                            #     break
                            return bad_json(extradata={'errors': f._errors})
                except Exception as ex:
                    return bad_json(message=ex.__str__())

            if action == 'edit_task':
                try:
                    with transaction.atomic():
                        f = TaskForm(request.POST)
                        if f.is_valid():
                            title = f.cleaned_data['title']
                            priority = f.cleaned_data['priority']
                            assigned_to = f.cleaned_data['assigned_to']
                            due_date = f.cleaned_data['due_date']
                            note = f.cleaned_data['note']
                            task = None

                            if 'id' in request.POST and request.POST[
                                    'id'] != '':
                                if Task.objects.filter(
                                        id=int(request.POST['id'])).exists():
                                    task = Task.objects.get(
                                        id=int(request.POST['id']))

                            if not task:
                                return bad_json(
                                    message='Please select a task to edit.')

                            if not title:
                                return bad_json(
                                    message='Please enter a task title.')

                            if not priority:
                                return bad_json(
                                    message='Please select a priority.')

                            if not assigned_to:
                                return bad_json(
                                    message=
                                    'Please select a user to assign this task to.'
                                )

                            if not due_date:
                                return bad_json(
                                    message=
                                    'Please select a due date for this task.')

                            if not note:
                                return bad_json(
                                    message='Please enter a note for this task.'
                                )

                            task.title = title
                            task.priority = priority
                            task.assigned_to = assigned_to
                            task.due_date = due_date
                            task.note = note
                            task.save()

                            return ok_json(
                                data={
                                    'message':
                                    'You have successfully edited a task',
                                    'redirect_url':
                                    '/lists?action=view&id={}'.format(
                                        task.list.id)
                                })
                        else:
                            # for field in f.errors:
                            #     error = field + ": " + field.data[0]
                            #     break
                            return bad_json(extradata={'errors': f._errors})
                except Exception as ex:
                    return bad_json(message=ex.__str__())

            if action == 'add_comment':
                try:
                    with transaction.atomic():
                        f = CommentForm(request.POST)
                        if f.is_valid():
                            body = f.cleaned_data['body']
                            task = None

                            if 'id' in request.POST and request.POST[
                                    'id'] != '':
                                if Task.objects.filter(
                                        id=int(request.POST['id'])).exists():
                                    task = Task.objects.get(
                                        id=int(request.POST['id']))

                            if not task:
                                return bad_json(
                                    message=
                                    'Please select a task to add this comment to.'
                                )

                            if not body:
                                return bad_json(
                                    message=
                                    'Please enter a comment for this task.')

                            comment = Comment(
                                task=task,
                                author=User.objects.get(id=request.user.id),
                                body=body)
                            comment.save()

                            return ok_json(
                                data={
                                    'message':
                                    'You have successfully added a comment',
                                    'redirect_url':
                                    '/lists?action=view_task&id={}'.format(
                                        task.id)
                                })
                        else:
                            return bad_json(extradata={'errors': f._errors})
                except Exception as ex:
                    return bad_json(message=ex.__str__())

    else:
        if 'action' in request.GET:
            if 'action' in request.GET and request.GET['action'] != '':
                action = request.GET['action']

                if action == 'create':
                    data['title'] = 'Create a new List'
                    data['form'] = ListForm()
                    return render(request, 'lists/create.html', data)

                if action == 'edit':
                    if 'id' in request.GET and request.GET['id'] != '':
                        if List.objects.filter(
                                id=int(request.GET['id'])).exists():
                            data['list'] = list = List.objects.get(
                                id=int(request.GET['id']))
                            data['title'] = 'Edit List: ' + list.name
                            data['form'] = ListForm(
                                initial={
                                    'name': list.name,
                                    'priority': list.priority,
                                    'assigned_to': list.assigned_to,
                                    'due_date': list.due_date
                                })

                            return render(request, 'lists/edit.html', data)

                if action == 'view':
                    if 'id' in request.GET and request.GET['id'] != '':
                        if List.objects.filter(
                                id=int(request.GET['id'])).exists():
                            data['list'] = list = List.objects.get(
                                id=int(request.GET['id']))

                            data['title'] = 'Viewing List: ' + list.name
                            return render(request, 'lists/view.html', data)

                if action == 'add_task':
                    if 'id' in request.GET and request.GET['id'] != '':
                        if List.objects.filter(
                                id=int(request.GET['id'])).exists():
                            data['list'] = list = List.objects.get(
                                id=int(request.GET['id']))
                            data['title'] = 'Add Task to: ' + list.name
                            data['form'] = TaskForm()
                    return render(request, 'tasks/create.html', data)

                if action == 'edit_task':
                    if 'id' in request.GET and request.GET['id'] != '':
                        if Task.objects.filter(
                                id=int(request.GET['id'])).exists():
                            data['task'] = task = Task.objects.get(
                                id=int(request.GET['id']))
                            data['title'] = 'Edit Task for: ' + task.list.name
                            data['form'] = TaskForm(
                                initial={
                                    'title': task.title,
                                    'due_date': task.due_date,
                                    'assigned_to': task.assigned_to,
                                    'note': task.note,
                                    'priority': task.priority
                                })

                    return render(request, 'tasks/edit.html', data)

                if action == 'mark_complete_task':
                    if 'id' in request.GET and request.GET['id'] != '':
                        if Task.objects.filter(
                                id=int(request.GET['id'])).exists():
                            task = Task.objects.get(id=int(request.GET['id']))
                            task.completed = True
                            task.save()
                            return HttpResponseRedirect(
                                '/lists?action=view&id={}'.format(
                                    task.list.id))
                    return HttpResponseRedirect('/lists')

                if action == 'mark_incomplete_task':
                    if 'id' in request.GET and request.GET['id'] != '':
                        if Task.objects.filter(
                                id=int(request.GET['id'])).exists():
                            task = Task.objects.get(id=int(request.GET['id']))
                            task.completed = False
                            task.save()
                            return HttpResponseRedirect(
                                '/lists?action=view&id={}'.format(
                                    task.list.id))
                    return HttpResponseRedirect('/lists')

                if action == 'delete_task':
                    if 'id' in request.GET and request.GET['id'] != '':
                        if Task.objects.filter(
                                id=int(request.GET['id'])).exists():
                            task = Task.objects.get(id=int(request.GET['id']))
                            list = task.list
                            task.delete()
                            return HttpResponseRedirect(
                                '/lists?action=view&id={}'.format(list.id))
                    return HttpResponseRedirect('/lists')

                if action == 'delete':
                    if 'id' in request.GET and request.GET['id'] != '':
                        if List.objects.filter(
                                id=int(request.GET['id'])).exists():
                            list = List.objects.get(id=int(request.GET['id']))
                            list.delete()
                    return HttpResponseRedirect('/lists')

                if action == 'view_task':
                    if 'id' in request.GET and request.GET['id'] != '':
                        if Task.objects.filter(
                                id=int(request.GET['id'])).exists():
                            data['task'] = task = Task.objects.get(
                                id=int(request.GET['id']))

                            data['title'] = 'Viewing Task: ' + task.title
                            return render(request, 'tasks/view.html', data)

                if action == 'add_comment':
                    if 'id' in request.GET and request.GET['id'] != '':
                        if Task.objects.filter(
                                id=int(request.GET['id'])).exists():
                            data['task'] = task = Task.objects.get(
                                id=int(request.GET['id']))
                            data['form'] = CommentForm()

                            data['title'] = 'Comment on Task: ' + task.title
                            return render(request, 'comment/create.html', data)

    data['lists'] = List.objects.all()
    return render(request, 'lists.html', data)