Ejemplo n.º 1
0
def appointment(request):
    booked = False
    rejected = False
    if request.method == 'POST':
        time = request.POST['time']
        tpe = request.POST['type']
        date = str(request.POST['date'])
        li = Counsellor.objects.filter(Type=tpe)
        req = []
        col = None
        with connection.cursor() as cursor:
            cursor.execute(
                'select * from IT_appointment where Date=%r and Student_id=%d and Time=%s'
                % (date, auth(request)['user'].id, time))
            col = cursor.fetchone()
        if col:
            return render(
                request, 'redirect.html', {
                    'title':
                    'Already Booked',
                    'message':
                    "You have booked an appointment for that slot already."
                })
        for i in li:

            with connection.cursor() as cursor:
                cursor.execute(
                    'select Counsellor_ID from IT_appointment where Date=%r and Counsellor_id=%d and Time=%s'
                    % (date, i.id, time))
                row = cursor.fetchone()

            if row is None:
                req.append(i)

        if req:
            appt = Appointment(Counsellor=req[0],
                               Date=date,
                               Time=time,
                               Student=auth(request)['user'])
            appt.save()
            booked = True

        else:
            rejected = True

    return render(request, 'appointment.html', {
        'booked': booked,
        'rejected': rejected
    })
Ejemplo n.º 2
0
def map(request):
    user = auth(request)['user']
    if user.is_authenticated:

        # sets the user to be online when they are on the map
        user.userprofile.online = True
        user.userprofile.save()

        users_list = User.objects.all()

        non_admin_users_list = []

        # removes the admin from the list of online users  displayed
        for user in users_list:
            if not user.is_staff:
                non_admin_users_list.append(user)

        # makes sure people are online in the context users list
        online_users = [
            person for person in non_admin_users_list
            if person.userprofile.online == True
        ]

        return render(request, 'home/map.html', {'users_list': online_users})

    else:
        return HttpResponseRedirect(reverse('home:login'))
Ejemplo n.º 3
0
def submit_location(request):
    user = auth(request)['user']
    load_dotenv()
    GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')

    if user.is_authenticated:
        if request.method == 'GET':
            return
        elif request.method == 'POST':
            d = request.POST.dict()
            user.userprofile.latitude = d['latitude']
            user.userprofile.longitude = d['longitude']
            user.userprofile.save()

            response = requests.get(
                F'https://maps.googleapis.com/maps/api/geocode/json?latlng={user.userprofile.latitude},{user.userprofile.longitude}&key={GOOGLE_API_KEY}'
            )
            geodata = "".join(response.json()['results'][0]
                              ['formatted_address'].split(',')[0:3])

            user.userprofile.geodata = geodata
            user.userprofile.save()
            return HttpResponse('')
    else:
        return render(request, 'home/login.html', {})
Ejemplo n.º 4
0
def create_user(request):
    user = auth(request)['user']
    if not hasattr(user, 'userprofile'):
        profile = UserProfile()
        profile.user = user
        profile.save()

    return HttpResponseRedirect(reverse('home:map'))
Ejemplo n.º 5
0
def feedback(request):
	feedback=" "
	if request.method=='POST':
		feedback=request.POST['feedback']
		fback=Feedback(Student=auth(request)['user'],Date=datetime.date.today(),Time=datetime.datetime.now().time(),feedback=feedback)
		fback.save()
		return HttpResponseRedirect('/home')
	return render(request,'feedback.html',)
Ejemplo n.º 6
0
def logout_view(request, next_page):
    user = auth(request)['user']

    # sets a user to "offline" once they have logged out
    user.userprofile.online = False
    user.userprofile.save()

    logout(request)
    return HttpResponseRedirect(redirect_to=next_page)
Ejemplo n.º 7
0
def chat(request):
	curr_user=auth(request)['user']
	a=Student.objects.filter(student=curr_user)
	profile=[]
	slot="0"
	now = datetime.datetime.now()
	today4pm =now.replace(hour=16, minute=0, second=0, microsecond=0)
	today45pm =now.replace(hour=16, minute=30, second=0, microsecond=0)
	today5pm = now.replace(hour=17, minute=0, second=0, microsecond=0)
	today55pm = now.replace(hour=17, minute=30, second=0, microsecond=0)
	today6pm = now.replace(hour=18, minute=0, second=0, microsecond=0)
	if now>today4pm and now<today45pm:
		slot="4"
	elif now>today45pm and now<today5pm:
		slot="4.5"
	elif now>today5pm and now<today55pm:
		slot="5"
	elif now>today55pm and now<today6pm:
		slot="5.5"
	print slot
	if a:
		utype=1
		
		profile=Appointment.objects.filter(Student_id=curr_user.id,Date=datetime.date.today(),Time=slot)
		if not profile:
			return HttpResponse("No appointment for you right now")
		
		
		                        
		sender,to= str(profile[0]).split(":")
	else:
		utype=2
		with connection.cursor() as cursor:
				cursor.execute('select id from IT_counsellor where counsellor_id=%d'%(curr_user.id))
				Counsellor_id=cursor.fetchone()
				
		profile=Appointment.objects.filter(Counsellor_id=Counsellor_id,Date=datetime.date.today(),Time=slot)
		
		if not profile:
			return HttpResponse("No appointment right now")

		to,sender= str(profile[0]).split(":")
		
		
		
		
					
	return render(request,'chat2.html',{'to':to,'sender':sender,'type':utype})
Ejemplo n.º 8
0
def myprofile(request):
	stu=auth(request)['user']
	li=[]
	profile=[]
	li=Appointment.objects.filter(Student=stu,Date__gte=datetime.date.today()).order_by('Time').order_by('Date')
	print li

	utype=1
	profile=Student.objects.filter(student_id=stu.id)
	if not profile:
				profile=Counsellor.objects.filter(counsellor=stu)
				print profile
				
				li=Appointment.objects.filter(Counsellor_id=profile[0],Date__gte=datetime.date.today()).order_by('Time').order_by('Date')
				utype=0
	return render(request,'appointments.html',{'appointment':li,'profile':profile,'type':utype})
Ejemplo n.º 9
0
    def get_context_data(self, *args, **kwargs):
        context = super(ProposalPdfDetailView,
                        self).get_context_data(*args, **kwargs)
        context['status_history'] = Status.objects.filter(
            proposal=self.object).exclude(status__in="UR")
        try:
            tech = ""
            for s in Status.objects.filter(proposal=self.object).filter(
                    status__in="WTU"):
                if not s.hiddenremark or s.status == 'U':
                    break
                tech += "<i>%s</i>: %s<br/>" % (s.user.contact, s.hiddenremark)
            context['tech'] = tech

        except Status.DoesNotExist:
            context['tech'] = None

        context = {**context, **context_processors.auth(self.request)}
        return context
Ejemplo n.º 10
0
def users_list(request):
    user = auth(request)['user']
    if user.is_authenticated:
        users_list = User.objects.all()

        non_admin_users_list = []

        # removes the admin from the list of online users  displayed
        for user in users_list:
            if not user.is_staff:
                non_admin_users_list.append(user)

        # makes sure people are online in the context users list
        online_users = [
            person for person in non_admin_users_list
            if person.userprofile.online == True
        ]

        return render(request, 'home/users_list.html',
                      {'users_list': online_users})
    else:
        return render(request, 'home/login.html', {})
Ejemplo n.º 11
0
def page_section(context, page_id, location, blank_if_empty=True):

    pc, _ = PageContentBlock.objects.get_or_create(page_id=page_id,
                                                   location=location)

    if blank_if_empty and not pc.contents:
        return ""

    auth_data = auth(context['request'])
    auth_data['request'] = context['request']

    context = Context(auth_data)
    formatted_contents = Template(pc.contents).render(context=context)

    return mark_safe("""
        <div class="page-section-wrapper {location}" data-page-section-id="{id}">
            <div class="page-section-contents">
                {contents}
            </div>
        </div>""".format(id=pc.pk,
                         location=location,
                         contents=formatted_contents))
Ejemplo n.º 12
0
def updateProf(request):

    user = auth(request)['user']
    if user.is_authenticated:
        if request.method == 'POST':
            user_form = UpdateUser(request.POST, instance=request.user)
            profile_form = UserProfileForm(request.POST,
                                           instance=request.user.userprofile)
            if user_form.is_valid() and profile_form.is_valid():
                user = user_form.save(commit=False)
                user.save()
                profile = profile_form.save(commit=False)
                profile.user = user
                profile.save()
                return HttpResponseRedirect(reverse('home:users_list'))

        else:
            profile_form = UserProfileForm(instance=request.user.userprofile)
            user_form = UpdateUser(instance=request.user)
            args = {'user_form': user_form, 'profile_form': profile_form}
            return render(request, 'home/updateprofile.html', args)

    else:
        return render(request, 'home/login.html', {})
Ejemplo n.º 13
0
def chat(request):
    curr_user = auth(request)['user']
    a = Student.objects.filter(student=curr_user)
    profile = []
    print curr_user.id
    recv_id = None
    if a:
        utype = 1
        profile = Appointment.objects.filter(Student_id=curr_user.id,
                                             Date=datetime.date.today())
        times = Appointment.objects.filter(
            Student_id=curr_user.id,
            Date=datetime.date.today()).values_list('Time')
        if not profile:
            return render(
                request, 'redirect.html', {
                    'title': 'No appointment',
                    'message': "You haven't booked an appointment for today"
                })
        slot = times[0][0]
        now = datetime.datetime.now()
        today4pm = now.replace(hour=16, minute=0, second=0, microsecond=0)
        today45pm = now.replace(hour=16, minute=30, second=0, microsecond=0)
        today5pm = now.replace(hour=17, minute=0, second=0, microsecond=0)
        today55pm = now.replace(hour=17, minute=30, second=0, microsecond=0)
        today6pm = now.replace(hour=18, minute=0, second=0, microsecond=0)
        if slot == "4":
            if now > today45pm or now < today4pm:
                return render(request, 'redirect.html', {
                    'title': 'No appointment',
                    'message': "Its not your slot"
                })
            else:
                pass
        if slot == "4.5":
            if now > today5pm or now < today45pm:
                return render(request, 'redirect.html', {
                    'title': 'No appointment',
                    'message': "Its not your slot"
                })
            else:
                pass
        if slot == "5":
            if now > today55pm or now < today5pm:
                return render(request, 'redirect.html', {
                    'title': 'No appointment',
                    'message': "Its not your slot"
                })
            else:
                pass
        if slot == "5.5":
            if now > today6pm or now < today55pm:
                return render(request, 'redirect.html', {
                    'title': 'No appointment',
                    'message': "Its not your slot"
                })
            else:
                pass

        sender, to = str(profile[0]).split(":")

    else:
        utype = 2
        with connection.cursor() as cursor:
            cursor.execute(
                'select id from IT_counsellor where counsellor_id=%d' %
                (curr_user.id))
            Counsellor_id = cursor.fetchone()

        profile = Appointment.objects.filter(Counsellor_id=Counsellor_id,
                                             Date=datetime.date.today())
        times = Appointment.objects.filter(
            Counsellor_id=Counsellor_id,
            Date=datetime.date.today()).values_list('Time')
        if not profile:
            return render(
                request, 'redirect.html', {
                    'title': 'No appointment',
                    'message': "Its a free day for you enjoy"
                })
        slot = times[0][0]

        now = datetime.datetime.now()
        today4pm = now.replace(hour=16, minute=0, second=0, microsecond=0)
        today45pm = now.replace(hour=16, minute=30, second=0, microsecond=0)
        today5pm = now.replace(hour=17, minute=0, second=0, microsecond=0)
        today55pm = now.replace(hour=17, minute=30, second=0, microsecond=0)
        today6pm = now.replace(hour=18, minute=0, second=0, microsecond=0)
        if slot == "4":
            if now > today45pm or now < today4pm:
                return render(request, 'redirect.html', {
                    'title': 'No appointment',
                    'message': "Its not your slot"
                })
            else:
                pass
        if slot == "4.5":
            if now > today5pm or now < today45pm:
                return render(request, 'redirect.html', {
                    'title': 'No appointment',
                    'message': "Its not your slot"
                })
            else:
                pass
        if slot == "5":
            if now > today55pm or now < today5pm:
                return render(request, 'redirect.html', {
                    'title': 'No appointment',
                    'message': "Its not your slot"
                })
            else:
                pass
        if slot == "5.5":
            if now > today6pm or now < today55pm:
                return render(request, 'redirect.html', {
                    'title': 'No appointment',
                    'message': "Its not your slot"
                })
            else:
                pass
        to, sender = str(profile[0]).split(":")

    with connection.cursor() as cursor:
        cursor.execute('select id from auth_user where email="%s"' % (to))
        recv_id = cursor.fetchone()
    print recv_id[0]
    history = Message.objects.filter(
        Sender=recv_id[0], Receiver=curr_user.id) | Message.objects.filter(
            Receiver=recv_id[0], Sender=curr_user.id)
    return render(request, 'chat2.html', {
        'to': to,
        'sender': sender,
        'type': utype,
        'history': history
    })
Ejemplo n.º 14
0
def login(request):
    user = auth(request)['user']
    if user.is_authenticated:
        return HttpResponseRedirect(reverse('home:map'))
    else:
        return HttpResponseRedirect(reverse('home:home'))
Ejemplo n.º 15
0
def users(request):
    context = auth(request)
    user = context.pop('user', None)
    context['current_user'] = user
    return context