Exemplo n.º 1
0
def edit_patient(request, patient_id):
    form_title = 'Edit Patient Information'
    patient = get_object_or_404(Patient, pk=patient_id)
    if request.method == 'POST':
        form = PersonForm(request.POST, instance=patient)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(
                reverse('patient:view_patient', args=(patient.id, )))
    else:
        form = PersonForm(instance=patient)

    return render(request, 'patient/create_patient.html', {
        'form': form,
        'form_title': form_title
    })
Exemplo n.º 2
0
def person_edit(request, pk):
    if pk == 'new':
        instance = None
    else:
        instance = get_object_or_404(Person, pk=pk)
    form = PersonForm(request.POST or None, instance=instance)
    if form.is_valid():
        person = form.save()
        messages.success(request, 'Successfully saved!')
        return redirect('person_edit', pk=person.pk)
    return render(
        request,
        'person/person_edit.html',
        {
            'main_menu_key': 'persons',
            'form': form,
        },
    )
Exemplo n.º 3
0
def add_or_edit(request, id):
    if id is None:
        person = None
        page_name = "add"
    else:
        person = get_object_or_404(Person, id=id)
        page_name = "edit"
    if request.method == "GET":
        form = PersonForm(instance=person)
        phone_forms = PhoneNumberFormSet(instance=person)
    if request.method == "POST":
        form = PersonForm(request.POST, instance=person)
        phone_forms = PhoneNumberFormSet(request.POST, instance=person)
        if form.is_valid() and phone_forms.is_valid():
            person = form.save()
            phone_forms = PhoneNumberFormSet(request.POST, instance=person)
            phone_forms.is_valid()
            phone_forms.save()
            return HttpResponseRedirect('/person/%s/' % person.id)
    return render_to_response('add.html', {'page_name': page_name, 'form': form, 'phone_forms': phone_forms, 'person': person}, RequestContext(request))
Exemplo n.º 4
0
class PersonEditView(TemplateView):
    template_name = 'person/profile_edit.html'

    @method_decorator(login_required)
    def dispatch(self, request, *args, **kwargs):
        action = request.POST.get('action')
        self.profile_form = PersonForm(
            (request.POST if action == 'profile' else None),
            (request.FILES if action == 'profile' else None),
            prefix='profile', instance=request.user
        )
        self.password_form = UserPasswordChangeForm(request.user, (request.POST if action == 'password' else None),
                                                    prefix='password')
        self.email_form = UserEmailChangeForm(request.user, (request.POST if action == 'email' else None),
                                                    prefix='email')
        return super(PersonEditView, self).dispatch(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super(PersonEditView, self).get_context_data(**kwargs)
        context['profile_form'] = self.profile_form
        context['password_form'] = self.password_form
        context['email_form'] = self.email_form
        return context

    def post(self, request, *args, **kwargs):
        if self.profile_form.is_valid():
            self.profile_form.save()
            messages.success(request, ugettext(u'Профиль успешно сохранен.'))
            return redirect(request.path)
        elif self.password_form.is_valid():
            self.password_form.save()
            request.user.backend = request.session[BACKEND_SESSION_KEY]
            login(request, request.user)
            messages.success(request, ugettext(u'Пароль успешно сохранен.'))
            return redirect(request.path)
        elif self.email_form.is_valid():
            self.email_form.save()
            messages.success(request, ugettext(u'Email успешно сохранен.'))
            return redirect(request.path)
        return self.get(request, *args, **kwargs)
Exemplo n.º 5
0
def create_person(request):

    # redirect to sign in not logged in
    if 'id' not in request.session.keys():
        return redirect('/sign_in/')

    # if this is a POST request we need to process the form dat
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:

        form = PersonForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            form_data = form.cleaned_data
            current_user = User.objects.get(pk=request.user.id)

            new_row = Person(
                user=current_user,
                name=form_data['name'],
                message=form_data['message'],
                created=datetime.datetime.now(),
                start_date=form_data['start_date'],
                last_send=None,
                next_send=form_data['start_date'],
                interval=form_data['interval'],
                interval_type=form_data['interval_type'],
                snooze=0,
                snooze_interval=None,
                snooze_interval_type=None,
                snooze_last_send=None,
                snooze_next_send=None,
                in_deleted=0
            )
            new_row.save()
            return redirect('/view_person_list/')
    else:
        form = PersonForm()

    return render(request, 'person/create_person.html', {'form': form})
Exemplo n.º 6
0
def edit_person(request):

    if 'id' not in request.session.keys():
        return redirect('/sign_in/')
    #TODO: check to make sure user logged in is associated with person - person ID may be public in the URL

    # get person ID from querystring
    person_id = request.GET['id']
    # pass person ID to Person model to pull current person
    current_person = Person.objects.get(pk=person_id)

    form = PersonForm(request.POST or None, instance=current_person)
    if request.POST and form.is_valid():
        form.save()

        # Save was successful
        redirect_url = '/view_person_list/'
        return redirect(redirect_url)

    context = {'form': form}

    return render(request, 'person/update_person.html', context=context)
Exemplo n.º 7
0
def create_patient(request):
    form_title = "Add New Patient"
    if request.method == 'POST':
        form = PersonForm(request.POST)
        if form.is_valid():
            patient = Patient()
            patient.surname = request.POST['surname']
            patient.firstname = request.POST['firstname']
            patient.othername = request.POST['othername']
            patient.prefix = Prefix.objects.get(pk=request.POST['prefix'])
            patient.id_number = "{}-{}".format(
                date.today().strftime('%Y-%m'),
                1 if len(Patient.objects.all()) == 0 else
                (Patient.objects.all().order_by('-id')[0].id) + 1)
            patient.save()
            return HttpResponseRedirect(
                reverse('patient:view_patient', args=(patient.id, )))
    else:
        form = PersonForm()

    return render(request, 'patient/create_patient.html', {
        'form': form,
        'form_title': form_title
    })