Ejemplo n.º 1
0
def plan(request, location):
    context_dict ={}
     # A HTTP POST?
    if request.method == 'POST':
        form = MyForm(request.POST)
        planner = Planner.objects.get(user=request.user)
        tripForm = CreateTrip(request.POST)

        # Have we been provided with a valid form?
        if form.is_valid() and tripForm.is_valid():
            # Save the new category to the database.
            trip = tripForm.save(commit=False)
            trip.planner=planner #Planner will be sent automatically eventually
            trip.save()
            data = form.cleaned_data['places']
            for place in data:
                visit = Visit(trip=trip, place=place)
                visit.save()
            # The user will be shown the summary page.
            return redirect(reverse('tripSummary', args=[trip.id] ))
        else:
            # The supplied form contained errors - just print them to the terminal.
            print form.errors
            context_dict['errors'] = form.errors
    else:
        places = get_places(location)
        form = CreateTrip()
        # If the request was not a POST, display the form to enter details.
        context_dict['places'] = places
        context_dict['tripForm'] = form

    return render(request, 'plan.html', context_dict)
Ejemplo n.º 2
0
def home_view(request, *args, **kwargs):
    today = datetime.datetime.now().date()

    if request.method == 'POST':
        form = MyForm(request.POST, request.FILES)
        if form.is_valid():
            action = request.POST['action']
            title = str(request.FILES['field'])
            content = request.FILES['field'].read()
            f = open(str(settings.MEDIA_ROOT) + title, "wb")
            f.write(content)
            f.close()
            loadInputAndProcess('media/' + title, action == 'watch')
            if action == 'watch':
                return render(request, "myaction.html", {
                    'value': "output.mp4",
                    'annotate': 'false'
                })
            elif action == 'annotate':
                return render(request, "myaction.html", {
                    'value': title,
                    'annotate': 'true'
                })
            else:
                return render(request, "showlink.html",
                              {'value': "output.avi"})

    form = MyForm()
    print(form)
    return render(request, "home.html", {"today": today, 'form': form})
Ejemplo n.º 3
0
    def post(self, request):
        form = MyForm(data=request.POST)
        if form.is_valid():
            messages.success(request, form.cleaned_data['message'])
        else:
            messages.error(request, 'Validation failed')

        c = {'form': form}
        return render(request, 'my_app/form.html', c)
Ejemplo n.º 4
0
def form_creation(request):
    if request.user.is_authenticated():
        pst = request.POST
        form = MyForm(pst)
        if not form.is_valid():
            return render(request, 'create_form/create_form_template.html')
        event_id = map_form_to_database(form.cleaned_data, request.user)
        if event_id is not None:
            context = {"event_id": event_id}
            return render(request, 'create_form/form_created.html', context)
        else:
            return HttpResponseRedirect('/')
    else:
        return render(request, 'unauthorized_template.html')
Ejemplo n.º 5
0
def generatedReport(request):
    if request.method == "POST":
        f = MyForm(request.POST, request.FILES)
        if f.is_valid():
            search = f.cleaned_data["Search"]
            sign = f.cleaned_data["Name"]
            response = HttpResponse(content_type="application/pdf")
            response["Content-Disposition"] = 'attachment; filename="somefilename.pdf"'

            buffer = BytesIO()

            model = Profile
            headers = []
            for field in model._meta.fields:
                headers.append(field.name)

            p = canvas.Canvas(buffer)
            p.setLineWidth(0.3)
            p.setFont("Helvetica", 12)

            line = 0
            for obj in Profile.objects.all():
                line += 1
                string = ""
                for field in headers:
                    if field == "name":
                        val = getattr(obj, field)
                        if type(val) == unicode:
                            val = val.encode("utf-8")
                        if (
                            ((val <= search) and (int(sign) == 1))
                            or ((val == (search)) and (int(sign) == 2))
                            or ((val >= (search)) and (int(sign) == 3))
                        ):
                            string = string + " " + str(val)
            p.drawString(30, 800 - 50 * line, string)

            # Close the PDF object cleanly, and we're done.
            p.showPage()
            p.save()

            pdf = buffer.getvalue()
            buffer.close()
            response.write(pdf)
            return response
def submit(request):
    if is_student(request):
        if request.method == "POST":
            try:
                a = request.FILES['pdf']
            except:
                return HttpResponse("Please select a file")
            f = MyForm(request.POST,request.FILES)
            if f.is_valid():
                try:
                    valid_file = f.clean_content()
                except ValidationError as e:
                    return HttpResponse(e.message)

                assignment = Assignment.objects.get(id=int(request.POST['id']))
                try:
                    sub = Submission.objects.get(user = request.user,
                                           assignment = assignment
                                            )
                    sub.is_checked = False
                    if assignment.deadline.microsecond < datetime.now().microsecond:
                        sub.is_late = True
                    sub.save()
                except:
                    sub = Submission.objects.create(user=request.user,
                                                    assignment=assignment
                                                    )
                    if assignment.deadline.microsecond < datetime.now().microsecond:
                        sub.is_late = True
                        sub.save()
                with open(join(settings.BASE_DIR ,'Uploads/'+str(request.user.id))+'/'+str(request.POST['id'])+'.pdf', 'wb+') as destination:
                    for chunk in valid_file.chunks():
                        destination.write(chunk)
            else:
                return HttpResponse("Select a file")

        return student_home(request)
    elif is_teacher(request):
        return teacher_home(request)
    return render(request,"home.html")