Ejemplo n.º 1
0
def day(request, year, month, day):
    """Entries for the day."""
    year = int(year)
    month = int(month)
    day = int(day)

    EntriesFormset = modelformset_factory(Entry, extra=1, exclude=("creator", "date"),
                                          can_delete=True)
    other_entries = []
    if _show_users(request):
        other_entries = Entry.objects.filter(date__year=year, date__month=month,
                                       date__day=day).exclude(creator=request.user)

    if request.method == 'POST':
        formset = EntriesFormset(request.POST)
        if formset.is_valid():
            # add current user and date to each entry & save
            entries = formset.save(commit=False)
            for entry in entries:
                entry.creator = request.user
                entry.date = date(year, month, day)
                entry.save()
                log = LogEntry(username=request.user.username, datetime=timezone.now(), description='appointment made/changed')
                log.save()
            return HttpResponseRedirect(reverse("calender:month", args=(year, month)))

    else:
        # display formset for existing enties and one extra form
        formset = EntriesFormset(queryset=Entry.objects.filter(date__year=year,
            date__month=month, date__day=day, creator=request.user))
    return render_to_response("calendar/day.html", add_csrf(request, entries=formset, year=year,
            month=month, mname=mnames[month-1], day=day, other_entries=other_entries, reminders=reminders(request)),
            context_instance=RequestContext(request))
Ejemplo n.º 2
0
def RegisterAdmin(request):
	registered = False
	if request.method == 'POST':
		user_form = UserForm(data = request.POST, prefix = 'user')
		admin_form = AdminForm(data = request.POST, prefix = 'admin')

		if user_form.is_valid() and admin_form.is_valid():
			user = user_form.save()
			user.set_password(user.password)
			user.save()
			profile = admin_form.save()

			try:
				user.groups.add(Group.objects.get(name = 'Sys Admin'))
			except Group.DoesNotExist:
				Group.objects.create(name='Sys Admin')
				user.groups.add(Group.objects.get(name = 'Sys Admin'))

			entry = LogEntry(username = user.username, datetime = timezone.now(), description = 'Sys Admin registered')
			entry.save()
			registered = True
		else:
			print(user_form.errors)
	else:
		user_form = UserForm(prefix = 'user')
		admin_form = AdminForm(prefix = 'admin')


	return render(request, 'admin.html', {'user_form' : user_form, 'admin_form' : admin_form,  'registered' : registered})
Ejemplo n.º 3
0
def Register(request):
	registered = False

	if request.method == 'POST':
		user_form = UserForm(data=request.POST,prefix = 'user')
		patient_form = PatientProfileForm(data = request.POST,prefix = 'patient')


		if user_form.is_valid() and patient_form.is_valid():
			user = user_form.save()
			user.set_password(user.password)
			user.save()
			
			try:
				user.groups.add(Group.objects.get(name='Patient'))
			except Group.DoesNotExist:
				Group.objects.create(name='Patient')
				user.groups.add(Group.objects.get(name='Patient'))

			profile = patient_form.save(commit = False)
			profile.user = user
			profile.save()

			entry = LogEntry(username=user.username, datetime=timezone.now(), description='user registered')
			entry.save()
			registered = True
		else:
			print(user_form.errors, patient_form.errors)
	else:
		user_form = UserForm(prefix = 'user')
		patient_form = PatientProfileForm(prefix = 'patient')
		

	return render(request,'register.html',{'user_form': user_form,'patient_form':patient_form , 'registered':
								registered})
Ejemplo n.º 4
0
def user_login(request):
  context = RequestContext(request)
  if request.method == 'POST':
    if 'login' in request.POST:
      username = request.POST['username']
      password = request.POST['password']
      user = authenticate(username=username, password=password)
      if user:
        login(request, user)
        entry = LogEntry(username=username, datetime=timezone.now(), description='user login')
        entry.save()
        return HttpResponseRedirect(request.GET.get('next', '/'))
      else:
        return render_to_response('login.html', {'username': username, 'error': "Invalid email or password."}, context)
    elif 'register' in request.POST:
      return render_to_response('register.html', {'username': username}, context)
  else:
    if request.user.is_authenticated():
      if request.GET.get('logout', '') == 'true':
        logout(request)
        entry = LogEntry(username='******', datetime=timezone.now(), description='user logout')
        entry.save()
      return HttpResponseRedirect(request.GET.get('next', '/'))
    return render_to_response('login.html', {}, context)