def edit_Sprofile(request, pk):
    if request.user.is_student:
        if request.user.pk == pk:
            student = User.objects.get(pk=pk)
            Sprofile = studentprofile.objects.get(user=student)
            form = forms.edit_student(student.email,
                                      student.first_name,
                                      student.last_name,
                                      instance=Sprofile)
            form.fields['subject'].widget.attrs.update({'class': 'checkbox'})
            form.fields['dob'].widget.attrs.update({'class': 'date'})
            if request.method == 'POST':
                form = forms.edit_student(request.POST["email"],
                                          request.POST["first_name"],
                                          request.POST["last_name"],
                                          request.POST, request.FILES)
                if form.is_valid():
                    fo = form.update(pk)
                    if 'image' in request.FILES:
                        fs = FileSystemStorage()
                        filename = fs.save(request.FILES["image"].name,
                                           request.FILES["image"])
                    return redirect("/" + request.session["type_profile"] +
                                    "/dashboard/profile/" + str(pk) + "/")
                else:
                    return HttpResponse("OOOOO")
            else:
                return render(request, 'student/edit.html', {'form': form})
from django.contrib.auth.decorators import login_required
import student.forms as forms 
from django.db.models import Q
from attendance.models import attendance
from .functions import *
import statistics
import plotly.offline as py
import plotly.graph_objs as go
# Create your views here.
@login_required
def edit_Sprofile(request,pk):
            student=User.objects.get(pk=pk)
        if request.user.pk==pk:
            student=User.objects.get(pk=pk)
            Sprofile=studentprofile.objects.get(user=student)
            form=forms.edit_student(student.email,student.first_name,student.last_name,instance=Sprofile)
            form.fields['subject'].widget.attrs.update({'class':'checkbox'})
            form.fields['dob'].widget.attrs.update({'class':'date'})
            if request.method=='POST':
                form=forms.edit_student(request.POST["email"],request.POST["first_name"],request.POST["last_name"],request.POST,request.FILES)
                if form.is_valid():
                    fo=form.update(pk)
                    if 'image' in request.FILES:
                        fs=FileSystemStorage()
                        filename=fs.save(request.FILES["image"].name,request.FILES["image"])
                    return redirect("/"+request.session["type_profile"]+"/dashboard/profile/"+str(pk)+"/")
                else:
                    return HttpResponse("OOOOO")
            else:
                return render(request,'student/edit.html',{'form':form})