Пример #1
0
def refugee(request):
    """
    View to add a refugee to the crisis communicator db

    """

    if request.method == 'POST':
        person_form = PersonForm(request.POST)
        refugee_form = RefugeeForm(request.POST)
        valid_person_form = person_form.is_valid()
        valid_refugee_form = refugee_form.is_valid()

        if valid_person_form and valid_refugee_form:
            person_form.save()
            refugee_form_data = refugee_form.save(commit=False)
            refugee_form_data.gid = generate_gid()
            refugee_form_data.person_id = get_object_or_404(Person, person_id= \
                    person_form.cleaned_data['person_id'])
            refugee_form_data.save()
            return HttpResponseRedirect('/crisis/')
        else:
            return render_to_response('person/refugee.html', {
                'person_form': person_form,
                'refugee_form': refugee_form
            }, RequestContext(request))

    else:
        return render_to_response('person/refugee.html', {
            'person_form': PersonForm(),
            'refugee_form': RefugeeForm()
        }, RequestContext(request))
Пример #2
0
def edit_index_data_ajax(request):
    if request.method != 'POST':
        return HttpResponseNotAllowed("Method not allowed")

    person = Person.objects.get()
    other = person.othercontact_set.all().get()

    form = PersonForm(request.POST, instance=person)
    contact_formset = ContactFormSet(request.POST, instance=person)
    othercontact_form = OtherContactForm(request.POST, instance=other)

    if form.is_valid() and contact_formset.is_valid() and \
            othercontact_form.is_valid():
        form.save()
        contact_formset.save()
        othercontact_form.save()

        ret = {"status": "ok"}

    else:
        err = form.errors
        for form in contact_formset:
            for field in form.errors:
                err["%s-%s" % (form.prefix, field)] = form.errors[field]

        err.update(othercontact_form.errors)

        ret = {"status": "error", "fields": err}

    json = simplejson.dumps(ret)

    return HttpResponse(json, mimetype='application/json')
Пример #3
0
def create_new_account(request, itemId=None):
    """
    View for saving new Person entry
    :param itemId:
    :param request:
    :return:
    """
    entry = None
    try:
        entry = Person.objects.get(id=itemId)
    except Person.DoesNotExist:
        pass

    if request.is_ajax():
        form = PersonForm(request.POST, request.FILES, instance=entry)
        if form.is_valid():
            if request.FILES:
                form.cleaned_data['photo'] = request.FILES['photo']
            form.save()
            return HttpResponse(
                json.dumps(dict(status=0, redirect=reverse('persons'))))
        else:
            errors = form.errors
            return HttpResponse(json.dumps({'status': 1, 'errors': errors}))
    else:
        form = PersonForm(instance=entry)
        return render(request, 'edit.html', locals())
Пример #4
0
def deceased(request):

    """
    View to add deceased people details. 

    """

    if request.method == 'POST':
        person_form = PersonForm(request.POST)
        deceased_form = DeceasedForm(request.POST)
        valid_person_form = person_form.is_valid()
        valid_deceased_form = deceased_form.is_valid()

        if valid_person_form and valid_deceased_form:
            person_form.save()
            deceased_form_data = deceased_form.save(commit=False)
            deceased_form_data.gid = generate_gid()
            deceased_form_data.person_id = get_object_or_404(Person, person_id= \
                    person_form.cleaned_data['person_id'])
            deceased_form_data.save()
            return HttpResponseRedirect('/crisis/')
        else:
            return render_to_response('person/deceased.html', {'deceased_form':deceased_form, 
                'person_form': person_form, 'error1':person_form, 'error2':deceased_form}, RequestContext(request))

    else:
        return render_to_response('person/deceased.html', {'deceased_form':DeceasedForm(), 
            'person_form': PersonForm()}, RequestContext(request))
Пример #5
0
def refugee(request):

    """
    View to add a refugee to the crisis communicator db

    """

    if request.method == 'POST':
        person_form = PersonForm(request.POST)
        refugee_form = RefugeeForm(request.POST)
        valid_person_form = person_form.is_valid()
        valid_refugee_form = refugee_form.is_valid()

        if valid_person_form and valid_refugee_form:
            person_form.save()
            refugee_form_data = refugee_form.save(commit=False)
            refugee_form_data.gid = generate_gid()
            refugee_form_data.person_id = get_object_or_404(Person, person_id= \
                    person_form.cleaned_data['person_id'])
            refugee_form_data.save()
            return HttpResponseRedirect('/crisis/')
        else:
            return render_to_response('person/refugee.html', {'person_form':person_form,
                'refugee_form':refugee_form}, RequestContext(request))

    else:
        return render_to_response('person/refugee.html', {'person_form':PersonForm(),
            'refugee_form':RefugeeForm()}, RequestContext(request))
Пример #6
0
def deceased(request):
    """
    View to add deceased people details. 

    """

    if request.method == 'POST':
        person_form = PersonForm(request.POST)
        deceased_form = DeceasedForm(request.POST)
        valid_person_form = person_form.is_valid()
        valid_deceased_form = deceased_form.is_valid()

        if valid_person_form and valid_deceased_form:
            person_form.save()
            deceased_form_data = deceased_form.save(commit=False)
            deceased_form_data.gid = generate_gid()
            deceased_form_data.person_id = get_object_or_404(Person, person_id= \
                    person_form.cleaned_data['person_id'])
            deceased_form_data.save()
            return HttpResponseRedirect('/crisis/')
        else:
            return render_to_response(
                'person/deceased.html', {
                    'deceased_form': deceased_form,
                    'person_form': person_form,
                    'error1': person_form,
                    'error2': deceased_form
                }, RequestContext(request))

    else:
        return render_to_response('person/deceased.html', {
            'deceased_form': DeceasedForm(),
            'person_form': PersonForm()
        }, RequestContext(request))
Пример #7
0
def create_new_account(request, itemId=None):
    """
    View for saving new Person entry
    :param itemId:
    :param request:
    :return:
    """
    entry = None
    try:
        entry = Person.objects.get(id=itemId)
    except Person.DoesNotExist:
        pass

    if request.is_ajax():
        form = PersonForm(request.POST, request.FILES, instance=entry)
        if form.is_valid():
            if request.FILES:
                form.cleaned_data['photo'] = request.FILES['photo']
            form.save()
            return HttpResponse(json.dumps(dict(status=0, redirect=reverse('persons'))))
        else:
            errors = form.errors
            return HttpResponse(json.dumps({'status': 1, 'errors': errors}))
    else:
        form = PersonForm(instance=entry)
        return render(request, 'edit.html', locals())
Пример #8
0
def add_person(request):
    form = PersonForm(request.POST or None)
    if form.is_valid():
        form.save()
        return redirect(reverse('list_person'))
    return direct_to_template(request, 'add.html', {
        'form': form,
        'title': Person._meta.verbose_name,
    })
Пример #9
0
def add_person(request):
    if request.method == 'POST':
        form = PersonForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/add_person/thanks/')
    else:
        form = PersonForm()
    return render_to_response('holidays/add_person.html', {'form': form},context_instance=RequestContext(request))
Пример #10
0
def new(request):
    if request.method == 'POST':
        form = PersonForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('people:index')
    else:
        form = PersonForm()

    return render(request, 'people/person_new.html', {'form': form})
def create_person(request):
    form = PersonForm()
    if request.method == 'POST':
        form = PersonForm(request.POST)
        if form.is_valid():
            form.save()

    c = {'form': form}
    c.update(csrf(request))
    return render_to_response('my_app/create.html', c)
Пример #12
0
def edit_person(request):
    person = get_object_or_404(Person)
    form = PersonForm(instance=person)
    if request.method == 'POST' and form.is_valid():
        form.save()
        return HttpResponseRedirect(reverse('startpage'))
    return direct_to_template(request, 'myapp/edit_info.html',
                             {
                                'form': form
                             })
Пример #13
0
def edit_person(request):
    first_person = Person.objects.all()[0]  # first person in DB
    form = PersonForm(instance=first_person)
    if request.method == 'POST':  # recived post data to save
        # load post data into object
        form = PersonForm(request.POST, instance=first_person)
        sucsess_text = 'form data not saved'
        if form.is_valid():  # if form data are valid
            form.save()      # save data from object to DB
            sucsess_text = 'data saved'
        return HttpResponse(form.ajax_response(sucsess_text))
    return render_to_response('bio/edit.html',
                              {'form': form},
                              context_instance=RequestContext(request))
Пример #14
0
def me(request):	
    if request.method == 'POST': # If the form has been submitted...
        # ContactForm was defined in the the previous section
        form = PersonForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            # ...
            form.save()
            return HttpResponseRedirect('/') # Redirect after POST
    else:
        form = PersonForm() # An unbound form

    return render(request, 'gpgsign/person.html', {
        'form': form,
    })
Пример #15
0
def edit_contact(request):
    contact = get_object_or_404(Contact, pk=1)
    if request.method == 'POST': 
        form_person = PersonForm(
                request.POST, 
                request.FILES,
                prefix='person',
                instance=contact.person
                )
        form_contact = ContactForm(
                request.POST, 
                request.FILES,
                prefix='contact',
                instance=contact
                )
        is_ajax_request = form_person.data.get('person-is_ajax_request',0)
        if form_person.is_valid() and form_contact.is_valid(): 
            # Process the data in form.cleaned_data
            form_person.save()
            form_contact.save()
            response = json.dumps({
                'success': True,
                'html': 'Data is succesfully updated.'
                })
        else:
            html = form_person.errors.as_ul() + form_contact.errors.as_ul()
            response = json.dumps({'success': False, 'html': html})

        if is_ajax_request:
            return HttpResponse(response, content_type="application/javascript")
        else:
            if form_person.is_valid() and form_contact.is_valid(): 
                return HttpResponseRedirect(reverse('index')) # Redirect after POST
    else:
        form_contact = ContactForm(
                prefix="contact", instance=contact
                )
        form_person = PersonForm(
                prefix="person", instance=contact.person
                )

    return render_to_response('edit_contact.html', {
        'contact': contact,
        'form_contact': form_contact,
        'form_person': form_person,
        },
        context_instance=RequestContext(request)
        )
Пример #16
0
def signupView(request, carid, eventid):
	event = EventModel.getEvent(eventid)
	user = request.user
	car = Car.cars.get(event=event, carid=carid)
	if memberCheck(request.user, event) == False:
			return render(request, 'invite/notMember.html')
	if request.method == 'GET':
		instance = Person.objects.filter(event=event, personid=user)
		if instance.count() == 0:
			personform = PersonForm()
		else:
			personform = PersonForm(instance = instance[0])

		context = {'menu' : getMenuInfo(request), 'title' : "Sign Up", 'personform' : personform, 'event' : event, 'user' : request.user}
		return render(request, 'ride_share/sign_up_form.html', context)

	if request.method == 'POST':
		instance = Car.cars.car(event = event,carid=carid)
		if instance.count() == 0:
			personform = PersonForm(request.POST)
		else:
			personform = PersonForm(request.POST, instance = instance[0])

		 
		if personform.is_valid():
			form = personform.save(commit=False)
			form.user = request.user
			form.event = event
			form.save()
			
		return HttpResponseRedirect(reverse('events:tools:rideshare:executeSignup', kwargs={'eventid':eventid, 'carid':carid}))
Пример #17
0
def person_edit(request, person_id=None, template='poll/person_form.html'):
    """ edit person """
    if person_id:
        instance = Person.objects.get(id=person_id)
        action = _('Edit')
    else:
        instance = None
        action = _('Add')

    if request.method == 'POST':
        form = PersonForm(request.POST, instance=instance)
        if form.is_valid():
            person = form.save(commit=False)
            person.save()
            form.save_m2m()
            messages.add_message(request, messages.SUCCESS,
                ugettext("Successfully saved person: %s") % person.name)
            return HttpResponseRedirect(reverse('person-list'))
    elif instance:
        form = PersonForm(instance=instance)
    else:
        form = PersonForm()
        
    data = {'form': form, 'action':action}
    return render_to_response(template, data, context_instance=RequestContext(request))
Пример #18
0
def edit_view(request):
    c = tools.get_default_context(request, 'm_edit')
    if request.method == 'POST': 
        form = PersonForm(request.POST, instance=Person.objects.all()[0])
        if form.is_valid():
            form.save()
            if request.is_ajax():
                return HttpResponse("Saved!")
            return HttpResponseRedirect('/')
    else:
        p = Person.objects.all()[0]
        form = PersonForm(instance=p) 

    c['form'] = form
    return render_to_response('edit.html', c,
                              context_instance=RequestContext(request))
Пример #19
0
def get_form_or_save(request):
    entry = None
    try:
        entry = Person.objects.get(pk=1)
    except Person.DoesNotExist:
        pass

    if request.method == 'POST':
        form = PersonForm(request.POST, request.FILES, instance=entry)
        if form.is_valid():
                if request.FILES:
                    form.cleaned_data['image_photo'] = \
                        request.FILES['image_photo']
                form.save()
    else:
        form = PersonForm(instance=entry)
    return form
Пример #20
0
def edit_view(request):
    c = tools.get_default_context(request, 'm_edit')
    if request.method == 'POST':
        form = PersonForm(request.POST, instance=Person.objects.all()[0])
        if form.is_valid():
            form.save()
            if request.is_ajax():
                return HttpResponse("Saved!")
            return HttpResponseRedirect('/')
    else:
        p = Person.objects.all()[0]
        form = PersonForm(instance=p)

    c['form'] = form
    return render_to_response('edit.html',
                              c,
                              context_instance=RequestContext(request))
Пример #21
0
def edit_profile(request):
    person = util.current_person(request)

    if request.method == "POST":
        form = PersonForm(request.POST, instance=person)
        form.save()
        return redirect('your_profile')

    else:
        form = PersonForm(instance=person)

    d = {
        "person": person,
        "form": form
        } 

    return render_with_extra_info(request, d, 'edit_profile.html')
Пример #22
0
def person_edit(request, template="contact/person_edit.html"):
    """
    Renders person edit template with person form, validate and save form.
    """
    detail_url = reverse('person_detail')
    person = get_object_or_404(Person, pk=settings.DEFAULT_PERSON_PK)
    form = PersonForm(request.POST or None,
                      request.FILES or None,
                      instance=person)
    if request.is_ajax() and request.POST:
        return HttpResponse(json.dumps(form.errors or None))
    if form.is_valid():
        form.save()
        return HttpResponseRedirect(reverse('person_detail'))
    return direct_to_template(request, template,
                              {'form': form,
                               'next': request.GET.get('next', detail_url), })
Пример #23
0
def create_person(request):
	if request.POST:
		form = PersonForm(request.POST)
		if form.is_valid():	
			user = request.POST['username']
			pwd =  request.POST['password']
			form.save()
			user = User.objects.create_user(user, '*****@*****.**',pwd)
			user.save()	
			user = authenticate(username=user, password=pwd)
			auth_login(request, user)
			return HttpResponseRedirect('/appwptn/')
	else:
		form = PersonForm()
	args = {}
	args.update(csrf(request))
	args['form'] = form
	return render_to_response('create_person.html',args)	
Пример #24
0
def save_person(request):
    if not request.user.is_authenticated():
        return {'saved': False, 'errors': ['Not authenticated']}

    try:
        person = Person.objects.latest('id')
    except:
        person = Person()

    post = request.POST or None
    data = request.FILES or None
    form = PersonForm(post, data, instance=person)

    if form.is_valid():
        form.save()
        return {'saved': True}
    else:
        return {'saved': False, 'errors': form.errors}
Пример #25
0
def create(request):
	#if request.POST:
	if request.method == 'POST':
		form = PersonForm(request.POST)
		if form.is_valid():
			form.save()
				
			return HttpResponseRedirect('/persons/all')
	
		else:
			raise Http404
		#else:
		#form = PersonForm()
                
	args = {}
	args.update(csrf(request))
	
	args['form'] = PersonForm()
	print args
	return render_to_response('create_person.html', args)
Пример #26
0
def person_create_view(request):
    if request.method == "POST":
        form = PersonForm(request.POST)
        if form.is_valid():
            person = form.save()
            return redirect("person-detail", person.pk)
    else:
        form = PersonForm()

    context = {"form": form}
    return render(request, "case/person/create.html", context)
Пример #27
0
def create(request):
	#if request.POST:
	if request.method == 'POST':
		form = PersonForm(request.POST , request.FILES)
		if form.is_valid():
			form.save()
			messages.add_message(request, messages.SUCCESS, "Your person added")	
			return HttpResponseRedirect('/persons/all')
	
		else:
			raise Http404
		#else:
		#form = PersonForm()
                
	args = {}
	args.update(csrf(request))
	
	args['form'] = PersonForm()
	print args
	return render_to_response('create_person.html', args)
Пример #28
0
def register(request):
    personform = PersonForm()
    if request.method=='POST':
        personform = PersonForm(request.POST)
        if personform.is_valid():
            profile = personform.save(commit=False)
            profile.save()
            personform.save_m2m()
            return HttpResponseRedirect(reverse('thanks'))
        else:
            personform = PersonForm()
    return render(request, "register/reg.html", {'PersonForm': personform})
Пример #29
0
 def post(self, request):
     form = PersonForm(request.POST, request.FILES, instance=self.instance)
     if form.is_valid():
         object_to_save = form.save(commit=False)
         object_to_save.save()
         logout(request)
         return HttpResponseRedirect(reverse('home-page'))
     else:
         form = PersonForm(request.POST, request.FILES, instance=self.instance)
         data = {
                 'form':form,
                 }
         return TemplateResponse(request, self.template_name, data)
Пример #30
0
def add(request):
    if request.method == 'POST':
        form = PersonForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            new_person = form.save()
            if cd.get('person'):
                rs = Relationship.objects.create(person1=cd.get('person'),
                                                 person2=new_person,
                                                 status=cd.get('status'))
            return HttpResponseRedirect('/')
    else:
        form = PersonForm()
    return {'form': form}
Пример #31
0
def registration(request, template_name="faca_parte.html"):

    person_form = PersonForm(request.POST or None)

    if request.method == "POST" and request.POST['action'] == "send":
        email_typed = person_form['email'].value()

        if Person.objects.filter(email=email_typed).exists():
            messages.error(request, _("E-mail already registered"))

        if person_form.is_valid():

            person_form.save()
            messages.success(request, _('Registration created successfully!'))
            redirect_url = reverse("registration")
            return HttpResponseRedirect(redirect_url)

        else:
            messages.warning(request, _('Information not saved.'))

    context = {"person_form": person_form}

    return render(request, template_name, context)
Пример #32
0
def register_person(request):
	if request.method == 'GET':
		form = list(PersonForm())
		return render_to_response('register.html', {'form': form}, context_instance=RequestContext(request))

	if request.method == 'POST':
		form = PersonForm(request.POST)

		if form.is_valid():
			person = form.save()
			request.session['person_id'] = person.id
			return redirect(reverse('list_polls'))
		form = list(form)
		return render_to_response('register.html', {'form': form}, context_instance=RequestContext(request))
Пример #33
0
def edit_index_data(request):

    person = Person.objects.all().get()
    other = person.othercontact_set.all().get()

    if request.method == 'GET':
        form = PersonForm(instance=person)
        contact_formset = ContactFormSet(instance=person)
        othercontact_form = OtherContactForm(instance=other)

        kw = {
                "form": form,
                "contact": contact_formset,
                "other": othercontact_form,
        }

        return render(request, 'edit_person.html', kw)

    form = PersonForm(request.POST, instance=person)
    contact_formset = ContactFormSet(request.POST, instance=person)
    othercontact_form = OtherContactForm(request.POST, instance=other)

    if form.is_valid() and contact_formset.is_valid() and \
            othercontact_form.is_valid():
        form.save()
        contact_formset.save()
        othercontact_form.save()

        return redirect('/')

    kw = {
            "form": form,
            "contact": contact_formset,
            "other": othercontact_form,
    }

    return render(request, 'edit_person.html', kw)
Пример #34
0
 def post(self, request):
     form = PersonForm(request.POST, request.FILES, instance=self.instance)
     if form.is_valid():
         object_to_save = form.save(commit=False)
         object_to_save.save()
         logout(request)
         return HttpResponseRedirect(reverse('home-page'))
     else:
         form = PersonForm(request.POST,
                           request.FILES,
                           instance=self.instance)
         data = {
             'form': form,
         }
         return TemplateResponse(request, self.template_name, data)
Пример #35
0
def home(request):
    if request.method == 'POST':
        form = PersonForm(request.POST)
        if form.is_valid():
            person = form.save(commit=False)
            person.save()
            return HttpResponseRedirect('/techsite/home/')
    else:
        form = PersonForm()
        list_people = Person.objects.all()
        context = {'list_people': list_people, 'form': form}
    return render(request, 'home.html', context)


# Create your views here.
Пример #36
0
def register_person(request):
	person_form = PersonForm(prefix="prs")

	if request.method == 'POST':
		person_form = PersonForm(request.POST, prefix="prs")
		if person_form.is_valid():
			person = person_form.save(commit=False)
			person.save()
			return redirect('locker_manager.views.person_details', matriculation=person.matriculation)
		else:
			messages.error(request, "Error")
			return render(request, 'locker_manager/register_person.html',{'person_form':person_form})

	else:	
		return render(request, 'locker_manager/register_person.html',{'person_form':person_form})
Пример #37
0
def register_person(request):
    person_form = PersonForm(prefix="prs")

    if request.method == 'POST':
        person_form = PersonForm(request.POST, prefix="prs")
        if person_form.is_valid():
            person = person_form.save(commit=False)
            person.save()
            return redirect('locker_manager.views.person_details',
                            matriculation=person.matriculation)
        else:
            messages.error(request, "Error")
            return render(request, 'locker_manager/register_person.html',
                          {'person_form': person_form})

    else:
        return render(request, 'locker_manager/register_person.html',
                      {'person_form': person_form})
Пример #38
0
def add_profile(request):
    'Add user profile.'
    if request.method == 'POST':
        form = PersonForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            #un = str(uuid.uuid4()).split('-')[0]
            #new_user = User.objects.create(username=un, email=cd['email'], first_name=cd['first_name'], 
            #                               last_name=cd['last_name'], password='******')
            new_person = form.save(commit=False)
            #new_person.user = new_user
            new_person.save()
            return HttpResponseRedirect(reverse('get-profile', args=[new_person.id]))
        #else:
        #    print form.errors['email']
    else:
        context = {'phone': '40xxxxxxxxx'}
        form = PersonForm(initial=context)
    
    return render_to_response('profile.html', {'form': form}, context_instance=RequestContext(request))
Пример #39
0
def register(request):
    """Main view."""
    if not request.user.is_authenticated():
        raise PermissionDenied
    if request.method == 'POST':
        is_update = Person.objects.filter(user=request.user).exists()
        if is_update:
            form = PersonForm(request.POST, instance=Person.objects.get(user=request.user))
        else:
            form = PersonForm(request.POST)
        data = {'form': form}
        if form.is_valid():
            person = form.save(commit=False)
            if is_update:
                person.save()
                return redirect('intro.home')
            else:
                person.user = auth.get_user(request)
                person.save()
                return redirect('user.register.complete')
    elif Person.objects.filter(user=request.user).exists():
        data = {'form': PersonForm(instance=request.user.get_profile())}
    else:
        fbAuth = UserSocialAuth.objects.filter(user=request.user, provider='facebook')
        initData = {}
        if fbAuth.exists():
            token = fbAuth.get().tokens['access_token']
            if token:
                graph = facebook.GraphAPI(token)
                me = graph.get_object('me', locale='zh_TW')
                if 'name' in me:
                    initData['fullname'] = me['name']
                if 'gender' in me and me['gender'] in genderMap.keys():
                    initData['gender'] = genderMap[me['gender']]

        data = {'form': PersonForm(initial=initData)}  # You'd add data here that you're sending to the template.

    return render(request, 'person/register.html', data)
Пример #40
0
def missing(request):
    """
    The view is to file missing person, in the diseaster area.

    """

    if request.method == 'POST':
        person_form = PersonForm(request.POST)
        missing_form = MissingForm(request.POST)
        comment_form = CommentForm(request.POST)
        valid_person_form = person_form.is_valid()
        valid_missing_form = missing_form.is_valid()
        valid_comment_form = comment_form.is_valid()
        if valid_person_form and valid_missing_form and valid_comment_form:
            person_form_data = person_form.save()
            missing_form_data = missing_form.save(commit=False)
            missing_form_data.gid = generate_gid()
            missing_form_data.person_id = get_object_or_404(Person, person_id= \
                    person_form_data.person_id)
            comment_form_data = comment_form.save(commit=False)
            _comment_id = randint(1, 1000)
            comment_form_data.comment_id = _comment_id
            comment_form_data.user_id = get_object_or_404(
                User, user_id=request.session['user_id'])
            comment_form_data.save()
            missing_form_data.comment = get_object_or_404(
                Comment, comment_id=_comment_id)
            missing_form_data.save()
            return HttpResponseRedirect('/crisis/')
        else:
            return render_to_response('person/missing.html', {'person_form': person_form,\
                    'missing_form':missing_form, 'comment_form':\
                    comment_form, 'error':person_form, 'error1':missing_form, 'error2':comment_form},RequestContext(request))
    else:
        return render_to_response('person/missing.html', {'person_form': PersonForm(),\
                'missing_form':MissingForm(), 'comment_form': \
                CommentForm()}, RequestContext(request))
Пример #41
0
def missing(request):

    """
    The view is to file missing person, in the diseaster area.

    """

    if request.method == 'POST':
        person_form = PersonForm(request.POST)
        missing_form = MissingForm(request.POST)
        comment_form = CommentForm(request.POST)
        valid_person_form = person_form.is_valid()
        valid_missing_form = missing_form.is_valid()
        valid_comment_form = comment_form.is_valid()
        if valid_person_form and valid_missing_form and valid_comment_form:
            person_form_data = person_form.save()
            missing_form_data = missing_form.save(commit=False)
            missing_form_data.gid = generate_gid()
            missing_form_data.person_id = get_object_or_404(Person, person_id= \
                    person_form_data.person_id)
            comment_form_data = comment_form.save(commit=False)
            _comment_id = randint(1,1000)
            comment_form_data.comment_id = _comment_id
            comment_form_data.user_id = get_object_or_404(User, user_id=request.session['user_id'])
            comment_form_data.save()
            missing_form_data.comment = get_object_or_404(Comment, comment_id=_comment_id)
            missing_form_data.save()
            return HttpResponseRedirect('/crisis/')
        else:
            return render_to_response('person/missing.html', {'person_form': person_form,\
                    'missing_form':missing_form, 'comment_form':\
                    comment_form, 'error':person_form, 'error1':missing_form, 'error2':comment_form},RequestContext(request))
    else:
        return render_to_response('person/missing.html', {'person_form': PersonForm(),\
                'missing_form':MissingForm(), 'comment_form': \
                CommentForm()}, RequestContext(request))
Пример #42
0
def add_edit_item(request, model_name, add_edit, edit_id):
    """Add/Edit page for the inventory"""
    if add_edit == "add":
        edit_id = None
    if _checkModel(model_name):
        directory = "asset_inventory/add_edit_Pages/"
        # Adding or Editing a Job
        if model_name == "Job":
            templateFile = directory + "Job.html"
            post_data = request.POST or None

            try:
                Job_Instance = Job.objects.get(pk=edit_id)
            except Job.DoesNotExist:
                Job_Instance = None
                if add_edit == "edit":
                    return HttpResponseRedirect(reverse("asset_inventory_add_edit_item", args=["Job", "add", "new"]))

            Job_Form = JobForm(post_data, instance=Job_Instance)

            if Job_Form.is_valid():
                Job_Occurance = Job_Form.save()
                return HttpResponseRedirect(reverse("asset_inventory_list_model", args=["Job"]))
            return render_to_response(templateFile, {"form": Job_Form}, context_instance=RequestContext(request))
        # Adding or Editing a Location
        elif model_name == "Location":
            templateFile = directory + "Location.html"
            post_data = request.POST or None

            try:
                Location_Instance = Location.objects.get(pk=edit_id)
            except Location.DoesNotExist:
                Location_Instance = None
                if add_edit == "edit":
                    return HttpResponseRedirect(
                        reverse("asset_inventory_add_edit_item", args=["Location", "add", "new"])
                    )

            Location_Form = LocationForm(post_data, instance=Location_Instance)

            if Location_Form.is_valid():
                Location_Occurance = Location_Form.save()
                return HttpResponseRedirect(reverse("asset_inventory_list_model", args=["Location"]))

            return render_to_response(templateFile, {"form": Location_Form}, context_instance=RequestContext(request))

        # Adding or Editing a Person
        elif model_name == "Person":
            templateFile = directory + "Person.html"
            post_data = request.POST or None

            try:
                Person_Instance = Person.objects.get(pk=edit_id)
            except Person.DoesNotExist:
                Person_Instance = None
                if add_edit == "edit":
                    return HttpResponseRedirect(reverse("asset_inventory_add_edit_item", args=["Person", "add", "new"]))

            Person_Form = PersonForm(post_data, instance=Person_Instance)

            if Person_Form.is_valid():
                Person_Occurance = Person_Form.save()
                return HttpResponseRedirect(reverse("asset_inventory_list_model", args=["Person"]))

            return render_to_response(templateFile, {"form": Person_Form}, context_instance=RequestContext(request))

        # Adding or Editing a Purchase
        elif model_name == "Purchase":
            templateFile = directory + "Purchase.html"
            post_data = request.POST or None

            try:
                Purchase_Instance = Purchase.objects.get(pk=edit_id)
            except Purchase.DoesNotExist:
                Purchase_Instance = None
                if add_edit == "edit":
                    return HttpResponseRedirect(
                        reverse("asset_inventory_add_edit_item", args=["Purchase", "add", "new"])
                    )

            Purchase_Form = PurchaseForm(post_data, instance=Purchase_Instance)

            if Purchase_Form.is_valid():
                Purchase_Occurance = Purchase_Form.save()
                return HttpResponseRedirect(reverse("asset_inventory_list_model", args=["Purchase"]))

            return render_to_response(templateFile, {"form": Purchase_Form}, context_instance=RequestContext(request))
        # Adding or Editing a Status
        elif model_name == "Status":
            templateFile = directory + "Status.html"
            post_data = request.POST or None

            try:
                Status_Instance = Status.objects.get(pk=edit_id)
            except Status.DoesNotExist:
                Status_Instance = None
                if add_edit == "edit":
                    return HttpResponseRedirect(reverse("asset_inventory_add_edit_item", args=["Status", "add", "new"]))

            Status_Form = StatusForm(post_data, instance=Status_Instance)

            if Status_Form.is_valid():
                Status_Occurance = Status_Form.save()
                return HttpResponseRedirect(reverse("asset_inventory_list_model", args=["Status"]))

            return render_to_response(templateFile, {"form": Status_Form}, context_instance=RequestContext(request))
        # Adding or Editing a Esign
        elif model_name == "Esign":
            templateFile = directory + "Esign.html"
            post_data = request.POST or None

            try:
                Esign_Instance = Esign.objects.get(pk=edit_id)
            except Esign.DoesNotExist:
                Esign_Instance = None
                if add_edit == "edit":
                    return HttpResponseRedirect(reverse("asset_inventory_add_edit_item", args=["Esign", "add", "new"]))

            Esign_Form = EsignForm(post_data, instance=Esign_Instance)

            if Esign_Form.is_valid():
                Esign_Occurance = Esign_Form.save()
                return HttpResponseRedirect(reverse("asset_inventory_list_model", args=["Esign"]))

            return render_to_response(templateFile, {"form": Esign_Form}, context_instance=RequestContext(request))
        # Adding or Editing a Device
        elif model_name == "Device":
            templateFile = directory + "Device.html"
            post_data = request.POST or None

            try:
                Device_Instance = Device.objects.get(pk=edit_id)
            except Device.DoesNotExist:
                Device_Instance = None
                if add_edit == "edit":
                    return HttpResponseRedirect(reverse("asset_inventory_add_edit_item", args=["Device", "add", "new"]))

            Device_Form = DeviceForm(post_data, instance=Device_Instance)

            if Device_Form.is_valid():
                Device_Occurance = Device_Form.save()
                return HttpResponseRedirect(reverse("asset_inventory_list_model", args=["Device"]))

            return render_to_response(templateFile, {"form": Device_Form}, context_instance=RequestContext(request))
    # This is a catch all response, if some unforseen error manages
    # to occur with the calling of add/edit pages
    else:
        render_to_response(reverse("homepage"))