Esempio n. 1
0
def addsite(request):
    uid = request.session.get('id')
    udata = Userinfo.objects.get(id=uid)
    if request.method == 'POST':
        address = Address()
        address.receiver = request.POST.get('receiver').strip()
        address.detaiarea = request.POST.get('detaiarea').strip()
        address.postcode = request.POST.get('postcode').strip()
        address.phone = request.POST.get('phone').strip()
        address.auser = udata
        address.save()
        if address.pk:
            return HttpResponseRedirect('/user/site/')
    content = {'udata': udata}
    return render(request, 'home/f_users/user_center_addsite .html', content)
Esempio n. 2
0
 def post(self):
     address_all = current_user.address_user_set
     phone = request.form.get('phone', None)
     site = request.form.get('sit', None)
     name = request.form.get('name', None)
     if phone and site and name:
         address = Address()
         address.phone = phone
         address.site = site
         address.name = name
         address.user_address = current_user.id
         db.session.add(address)
         db.session.commit()
         flash('添加完成')
         return redirect(url_for('address.address'))
     flash('检查输入完整')
     return render_template('./user/address.html', address_all=address_all)
Esempio n. 3
0
def do(request, nid, aid, browser_tab):
    WZ = Z.SetWhoZwho(request, browser_tab)
    if WZ['ErrorMessage']:
        return GoLogout(request, WZ)

    try:
        name = Name.objects.get(pk=int(nid))
    except:
        return GoLogout(request, WZ, "[EA01]: URL containd an invalid name ID.")

        if WZ['Authority'] < Z.Admin and name.owner != WZ['AuthorizedOwner']:
            return GoLogout(request, WZ, "[EA02]: URL containd an invalid name ID.")

    if aid != '0':
        try:
            address = Address.objects.get(pk=int(aid))
        except:
            return GoLogout(request, WZ, "[EA03]: URL containd an invalid addressID.")

        if address.owner != name.owner:
            return GoLogout(request, WZ, "[EA04]: URL containd an invalid address ID.")

        if WZ['Authority'] < Z.Admin and address.owner != WZ['AuthorizedOwner']:
            return GoLogout(request, WZ, "[EA05]: URL containd an invalid ID.")

    if request.method == 'POST': # If the form has been submitted...
        form = DirectoryEditAddressForm(request.POST, request.FILES)
        if form.is_valid():
            if aid == '0':
                address = Address()
                address.owner = name.owner

            address.street = form.cleaned_data['street']
            address.address_line2 = form.cleaned_data['address_line2']
            address.municipality = form.cleaned_data['municipality']
            address.city = form.cleaned_data['city']
            address.province = form.cleaned_data['province']
            address.country = form.cleaned_data['country']
            address.postcode = form.cleaned_data['postcode']
            address.phone = form.cleaned_data['home_phone']
            address.save()

            if aid == '0':
                name.address_id = address.id
                name.save()

            logger.info(WZ['User'] + ' EA ' + str(request.POST))

            if name.private == True:
                return HttpResponseRedirect('/WhoZwho/editpc/' + nid + '/' + browser_tab)
            else:
                return HttpResponseRedirect('/WhoZwho/ename/' + nid + '/' + browser_tab)
        else:
            WZ['ErrorMessage'] = str(form.errors)
    else:
        if aid == '0':
            form = DirectoryEditAddressForm()
        else:
            form = DirectoryEditAddressForm(initial={
                'street': address.street,
                'address_line2': address.address_line2,
                'municipality': address.municipality,
                'city': address.city,
                'province': address.province,
                'country': address.country,
                'postcode': address.postcode,
                'home_phone': address.phone,
                }) 

    if aid == '0':
        EditAddressTitle = 'Add New Address:'
    else:
        EditAddressTitle = 'Edit Address: ' + address.street

    context = {
        'EditAddressTitle': EditAddressTitle,
        'aid': aid,
        'browser_tab': WZ['Tabs'][WZ['ActiveTab']][2],
        'form': form,
        'nid': nid,
        'WZ': WZ
        }

    context.update(csrf(request))
    return render_to_response('DirectoryEditAddress.html', context )