本文整理汇总了Python中packages.bin.bin.Page.non_field_errors方法的典型用法代码示例。如果您正苦于以下问题:Python Page.non_field_errors方法的具体用法?Python Page.non_field_errors怎么用?Python Page.non_field_errors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类packages.bin.bin.Page
的用法示例。
在下文中一共展示了Page.non_field_errors方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: system_license
# 需要导入模块: from packages.bin.bin import Page [as 别名]
# 或者: from packages.bin.bin.Page import non_field_errors [as 别名]
#.........这里部分代码省略.........
]
})
# maintain autocomplete state
try:
instance_var = instance.modules.all()
except (AttributeError, ValueError):
instance_var = []
# script for autocomplete
page.script = autocomplete_state(
instance_var=instance_var,
queryset=Module.objects.all(),
url='/bin/json/system/modules/',
element='id_modules',
token=20,
)
# CREATE & UPDATE
if request.method == "POST":
form = FormLicense(request.POST, request.FILES, instance=instance)
modules = []
if form.is_valid():
# do method to process
posts = request.POST
for post in posts:
# skip the many to many fields
if hasattr(instance, post) and post != 'modules':
setattr(instance, post, form.cleaned_data[post])
# non field specific errors
page.non_field_errors = errors
try:
x = request.POST['modules']
if not x:
instance.modules = []
else:
for pk in x.split(','):
modules.append(Module.objects.get(pk=pk))
except MultiValueDictKeyError:
instance.modules = []
try:
del form.errors['modules']
except KeyError:
pass
errors += format_form_error(form)
if not errors:
from packages.bin.bin import get_all_images
# check for any old instance of picture
# delete any previous instance
try:
o_instance = License.pp.get(pk=pk)
if instance.company_logo != o_instance.company_logo:
picture = str(o_instance.company_logo)
ext = '.' + picture.split('.')[-1]
filename = "".join(picture.split('.')[:-1])
示例2: subscription
# 需要导入模块: from packages.bin.bin import Page [as 别名]
# 或者: from packages.bin.bin.Page import non_field_errors [as 别名]
def subscription(request, pk=None, method=None):
# check if root login
if request.session['auth_username'] != 'root':
return HttpResponse(response_success(route='#hr/personnel/'))
s = request.session
base_url = '/pp-license/'
second_base = 'subscription/'
base_template = 'system/'
page = Page(request)
page.title = 'License Management'
page.icon = 'fa fa-unlock-alt'
page.form_name = 'subscriptionForm'
page.breadcrumbs = ['License Management', 'Subscription']
errors = []
page.user = request.session['auth_username']
# query table list
obj = Subscription.objects.filter(license__id=pk)
# login url processing
if method is None or (method != 'new' and method != 'update'):
instance = Subscription()
form = FormSubscription()
template = base_template + 'snippets/list.html'
else:
instance = Subscription()
instance.license = License.objects.get(pk=pk)
form = FormSubscription(instance=instance)
page.form_action = base_url + second_base + 'new/' + str(pk) + '/'
template = base_template + 'snippets/manage.html'
obj_settings = [
{'link': base_url+'update/', 'icon': ActionButton.edit},
{'link': base_url+'delete/', 'icon': ActionButton.delete},
]
table = Table()
table.cols = ['License', 'Expiry']
table.rows = []
for val in obj:
table.rows.append({
'id': val.id,
'fields': [
{'field': val.license},
{'field': val.expiry}
]
})
# CREATE & UPDATE
if request.method == "POST":
form = FormSubscription(request.POST, instance=instance)
if form.is_valid():
# do method to process
posts = request.POST
for post in posts:
# skip the many to many fields
if hasattr(instance, post):
setattr(instance, post, form.cleaned_data[post])
# non field specific errors
page.non_field_errors = errors
errors += format_form_error(form)
# if not errors and not form.errors:
if not errors:
Subscription.objects.filter(license__id=pk).update(status=0)
instance.save()
return HttpResponse(response_success(route=base_url+second_base))
else:
return HttpResponse(response_error(response=[errors]))
# render to browser
return render_to_response(
template,
{'s': s, 'form': form, 'page': page, 'table': table, 'obj': obj, 'settings': obj_settings},
context_instance=RequestContext(request)
)
示例3: user_class
# 需要导入模块: from packages.bin.bin import Page [as 别名]
# 或者: from packages.bin.bin.Page import non_field_errors [as 别名]
def user_class(request, pk=None, method=None):
s = Auth().is_auth(request)
if not s:
return Auth.routeLogin
second_base = 'user_class/'
page = Page(request)
page.title = 'User Class'
page.icon = 'glyphicons glyphicons-parents'
page.form_name = 'applicationUserClass'
page.breadcrumbs = ['Privileges', 'User Class']
errors = []
obj_list = UserClass.objects.filter(status__exact=1)
#search logic
q = request.GET.get('q')
if q:
search_query = get_query(q, ['name'])
obj_list = obj_list.filter(search_query)
#build pagination
page, obj = paginate(page, obj_list, request, q)
#login url processing
if method is None or method == 'index':
instance = UserClass()
form = forms.FormUserClass()
template = base_template + 'list.html'
elif pk is not None:
instance = UserClass.objects.get(pk=pk)
form = forms.FormUserClass(instance=instance, data=model_to_dict(instance))
page.form_action = base_url + second_base + 'update/'+str(pk)+'/'
template = base_template + 'manage.html'
else:
instance = UserClass()
form = forms.FormUserClass(instance=instance)
page.form_action = base_url + second_base + 'new/'
template = base_template + 'manage.html'
obj_settings = [
{'link': base_url+second_base+'update/', 'icon': ActionButton.edit},
{'link': base_url+'user_class-delete/', 'icon': ActionButton.delete},
]
table = Table()
table.cols = ['Module', 'Name', 'Privilege', 'Users']
table.rows = []
for val in obj:
# fetch privileges
tmp = val.user_class_users.filter(sys=request.session['sys'], lid=request.session['lid'])[: 25]
assoc_users = ""
for x in tmp:
assoc_users += "<a href='#"+base_url+"uc_user-delete/%s/' class='text-danger'>%s</a>, " % \
(x.id, "%s [%s %s]" % (x.user.username, x.user.profile.firstname, x.user.profile.lastname))
# fetch associated users
tmp = val.user_class_privilege.all()
assoc = ""
for x in tmp:
assoc += "<a href='#"+base_url+"flush/%s/' class='text-danger'>%s</a><br/>" % (x.id, x.manifest.name)
table.rows.append({
'id': val.id,
'fields': [
{'field': val.module.name},
{'field': val.name},
{'field': assoc},
{'field': assoc_users}
]
})
# CREATE & UPDATE
if request.method == "POST":
form = forms.FormUserClass(request.POST, instance=instance)
if form.is_valid():
#do method to process
posts = request.POST
for post in posts:
if hasattr(instance, post):
setattr(instance, post, form.cleaned_data[post])
# non field specific errors
page.non_field_errors = errors
errors += format_form_error(form)
if not errors:
instance.save()
response = 'Saved successfully'
return HttpResponse(response_success(route=base_url + second_base, response=response))
else:
return HttpResponse(response_error(response=[errors]))
#render to browser
#.........这里部分代码省略.........
示例4: manifest
# 需要导入模块: from packages.bin.bin import Page [as 别名]
# 或者: from packages.bin.bin.Page import non_field_errors [as 别名]
def manifest(request, pk=None, method=None):
s = Auth().is_auth(request)
if not s:
return Auth.routeLogin
second_base = 'manifest/'
page = Page(request)
page.title = 'Privilege Manifest'
page.icon = 'fa fa-list-alt'
page.form_name = 'privilegeManifest'
page.breadcrumbs = ['Privileges', 'Manifest']
errors = []
obj_list = PrivilegeManifest.objects.filter(status__exact=1).order_by('module__name', 'name')
#search logic
q = request.GET.get('q')
if q:
search_query = get_query(q, ['name'])
obj_list = obj_list.filter(search_query)
#build pagination
page, obj = paginate(page, obj_list, request, q)
#login url processing
if method is None or method == 'index':
instance = PrivilegeManifest()
form = forms.FormUserClass()
template = base_template + 'list.html'
elif pk is not None:
instance = PrivilegeManifest.objects.get(pk=pk)
form = forms.FormPrivilegeManifest(instance=instance, data=model_to_dict(instance))
page.form_action = base_url + second_base + 'update/'+str(pk)+'/'
template = base_template + 'manage.html'
else:
instance = PrivilegeManifest()
form = forms.FormPrivilegeManifest(instance=instance)
page.form_action = base_url + second_base + 'new/'
template = base_template + 'manage.html'
obj_settings = [
{'link': base_url+second_base+'update/', 'icon': ActionButton.edit},
{'link': base_url+'manifest-delete/', 'icon': ActionButton.delete},
]
table = Table()
table.cols = ['Module', 'Name', 'Associated User Classes']
table.rows = []
for val in obj:
tmp = val.manifest_privilege.all()
assoc = ""
for x in tmp:
assoc += "%s<br/>" % x.user_class.name
table.rows.append({
'id': val.id,
'fields': [
{'field': val.module.name},
{'field': val.name},
{'field': assoc}
]
})
# CREATE & UPDATE
if request.method == "POST":
form = forms.FormPrivilegeManifest(request.POST, instance=instance)
if form.is_valid():
#do method to process
posts = request.POST
for post in posts:
if hasattr(instance, post):
setattr(instance, post, form.cleaned_data[post])
# non field specific errors
page.non_field_errors = errors
errors += format_form_error(form)
if not errors:
instance.save()
response = 'Saved successfully'
return HttpResponse(response_success(route=base_url + second_base, response=response))
else:
return HttpResponse(response_error(response=[errors]))
#render to browser
return render_to_response(
template,
{'s': s, 'form': form, 'page': page, 'table': table, 'obj': obj, 'settings': obj_settings},
context_instance=RequestContext(request)
)
示例5: UserManage
# 需要导入模块: from packages.bin.bin import Page [as 别名]
# 或者: from packages.bin.bin.Page import non_field_errors [as 别名]
def UserManage(request, pk=None):
s = Auth().isAuth(request)
if s is False:
return Auth.routeLogin
second_base_url = ''
obj = Users() if pk is None else Users.objects.get(pk=pk)
page = Page(request)
page.title = 'User Management'
page.icon = 'fa fa-group'
page.form_name = 'user_management'
page.form_action = base_url_admin+second_base_url+'new/'
page.breadcrumbs = ['System', 'User Management']
page.errors = []
# create record
if request.method != "POST" and pk is None:
page.breadcrumbs.append('New')
form = FormRegisterNew(instance=obj)
return Auth.routeLogin if s is False else \
render_to_response(
base_template_admin+'manage.html',
{'s': s, 'form': form, 'page': page},
context_instance=RequestContext(request)
)
elif request.method != "POST" and pk is not None:
page.form_action = base_url_admin + second_base_url + 'update/' + str(pk) + '/'
page.title = 'Update User: %s' % obj.username
page.breadcrumbs.append('Update')
page.request = request
page.id = pk
from django.forms.models import model_to_dict
form = FormRegister(instance=obj, data=model_to_dict(obj))
return render_to_response(
base_template_admin+'manage.html',
{'s': s, 'form': form, 'page': page},
context_instance=RequestContext(request)
)
# process record
elif request.method == "POST":
page.breadcrumbs.append('Update')
page.form_action = base_url_admin+second_base_url + 'new/' if pk is None else \
base_url_admin+second_base_url + 'update/'+str(pk)+'/'
try:
raw_password = request.POST["password"]
except KeyError:
raw_password = None
# do some non field specific validations
if pk is None:
form = FormRegisterNew(request.POST, request.FILES, instance=obj)
if raw_password == "":
page.non_field_errors = ['Please enter a valid password']
else:
form = FormRegister(request.POST, request.FILES, instance=obj)
# validate and process
if form.is_valid() and not page.non_field_errors:
# do method to process
posts = request.POST
for post in posts:
if hasattr(obj, post):
setattr(obj, post, form.cleaned_data[post])
try:
if request.FILES['picture']:
# delete any previous image
try:
# get actual file name
ext = '.' + obj.picture.url.split('.')[-1]
filename = "".join(obj.picture.url.split('.')[:-1])
fn = list()
fn.append(settings.MEDIA_ROOT + '/' + filename + ext)
fn.append(settings.MEDIA_ROOT + '/' + filename + '.64x64' + ext)
fn.append(settings.MEDIA_ROOT + '/' + filename + '.128x128' + ext)
fn.append(settings.MEDIA_ROOT + '/' + filename + '.256x256' + ext)
fn.append(settings.MEDIA_ROOT + '/' + filename + '.512x512' + ext)
fn.append(settings.MEDIA_ROOT + '/' + filename + '.1024x1024' + ext)
for f in fn:
os.path.exists(f) and os.remove(f)
except (KeyError, AttributeError, ValueError):
pass
except KeyError:
pass
# encrypt password
if raw_password:
obj.password = sha1(raw_password).hexdigest()
#.........这里部分代码省略.........
示例6: cim
# 需要导入模块: from packages.bin.bin import Page [as 别名]
# 或者: from packages.bin.bin.Page import non_field_errors [as 别名]
def cim(request, pk=None, method=None):
s = Auth().isAuth(request)
if not s:
return Auth.routeLogin
second_base = 'cim/'
page = Page(request)
page.title = 'CRM - Customer Information Management'
page.icon = 'glyphicons glyphicons-notes'
page.form_name = 'crmIndex'
template = base_template + 'snippets/list.html'
errors = []
obj_list = CIM.objects.filter(status__exact=1)
#search logic
q = request.GET.get('q')
if q:
sQuery = get_query(q, ['name', 'contact_person', 'email', 'phone', 'website', 'state', 'city', 'country'])
obj_list = obj_list.filter(sQuery)
#build pagination
page, obj = paginate(page, obj_list, request, q)
#form processing
if method is None or method == 'index':
form = forms.FormCIM()
template = base_template + 'snippets/list.html'
elif pk is not None:
instance = CIM.objects.get(pk=pk)
form = forms.FormCIM(instance=instance, data=model_to_dict(instance))
page.form_action = base_url + second_base + 'update/'+str(pk)+'/'
template = base_template + 'snippets/manage.html'
else:
instance = CIM()
form = forms.FormCIM(instance=instance)
page.form_action = base_url + second_base + 'new/'
template = base_template + 'snippets/manage.html'
obj_settings = [
{'link': base_url + second_base + 'update/', 'icon': Actions().Icon.edit},
{'link': base_url + second_base + 'delete/index/', 'icon': Actions().Icon.delete},
]
table = Table()
table.cols = ['Name', 'Corporate?', 'Phone', 'Email', 'Country']
table.rows = []
for val in obj:
table.rows.append({
'id': val.id,
'fields': [
{'field': val.name},
{'field': val.is_coy},
{'field': val.phone},
{'field': val.email},
{'field': val.country}
]
})
# CREATE & UPDATE
if request.method == "POST":
template = base_template + 'snippets/manage.html'
form = forms.FormCIM(request.POST, instance=instance)
if form.is_valid():
#do method to process
posts = request.POST
for post in posts:
if hasattr(instance, post):
setattr(instance, post, form.cleaned_data[post])
# non field specific errors
for f in form.errors:
errors.append(f)
page.non_field_errors = errors
if not errors and not form.errors:
instance.save()
return HttpResponseRedirect(base_url)
#render to browser
return render_to_response(template,
{'s': s, 'form': form, 'page': page, 'table': table, 'obj': obj, 'settings': obj_settings},
context_instance=RequestContext(request)
)
示例7: credit
# 需要导入模块: from packages.bin.bin import Page [as 别名]
# 或者: from packages.bin.bin.Page import non_field_errors [as 别名]
def credit(request, qk=None, pk=None, method=None):
if qk is None:
HttpResponseRedirect('/404/hack/')
s = Auth().isAuth(request)
if not s:
return Auth.routeLogin
second_base = 'asset/'
#practitioner factory
obj_practitioner = Practitioner.objects.get(pk=qk)
# asset factory
page = Page(request)
page.title = 'Practitioner\'s Deposit Form'
page.icon = 'glyphicons glyphicons-display'
page.form_name = 'practitionerFR'
template = base_template + second_base + 'snippets/manage-financial.html'
page.q = str(qk) + '/'
errors = []
#form processing
if pk is not None:
instance = FRSummary.objects.get(pk=pk)
form = forms.FormPractitionerFR(instance=instance, data=model_to_dict(instance))
page.form_action = base_url + 'credit/' + str(qk)+'/'+str(pk)+'/'
template = base_template + second_base + 'snippets/manage-financial.html'
else:
instance = FRSummary()
form = forms.FormPractitionerFR(instance=instance)
page.form_action = base_url + 'credit/' + str(qk)+'/'
template = base_template + second_base + 'snippets/manage-financial.html'
# SCRIPT
page.script = '''
<script>
</script>
'''
# CREATE & UPDATE
if request.method == "POST":
template = base_template + second_base + 'snippets/manage-financial.html'
form = forms.FormPractitionerFR(request.POST, instance=instance)
if form.is_valid():
#do method to process
posts = request.POST
for post in posts:
if hasattr(instance, post):
setattr(instance, post, form.cleaned_data[post])
# non field specific errors
if instance.credit < 100:
errors.append('Amount entered is too low')
page.non_field_errors = errors
if not errors and not form.errors:
instance.balance = instance.credit
instance.practitioner = obj_practitioner
instance.save()
return HttpResponseRedirect(base_url + 'statement/' + '%s/' % qk)
#render to browser
return render_to_response(template,
{'s': s, 'form': form, 'page': page, 'obj': instance,
'practitioner': obj_practitioner},
context_instance=RequestContext(request)
)
示例8: practitioner
# 需要导入模块: from packages.bin.bin import Page [as 别名]
# 或者: from packages.bin.bin.Page import non_field_errors [as 别名]
def practitioner(request, pk=None, method=None, cat=None):
s = Auth().isAuth(request)
if not s:
return Auth.routeLogin
second_base = 'index/'
page = Page(request)
page.title = 'Practitioner Management'
page.icon = 'glyphicons glyphicons-notes'
page.form_name = 'practitionerIndex'
template = base_template + second_base + 'snippets/list.html'
errors = []
if cat is not None:
cat = cat.replace("_", " ")
obj_list = Practitioner.objects.filter(status__exact=1).filter(type=cat)
else:
obj_list = Practitioner.objects.filter(status__exact=1)
#search logic
q = request.GET.get('q')
if q:
sQuery = get_query(q, ['name', 'contact_person', 'email', 'phone', 'website', 'state', 'city', 'country'])
obj_list = obj_list.filter(sQuery)
#build pagination
page, obj = paginate(page, obj_list, request, q)
#form processing
if method is None or method == 'index':
form = forms.FormPractitioner()
template = base_template + second_base + 'snippets/list.html'
elif pk is not None:
print pk
instance = Practitioner.objects.get(pk=pk)
form = forms.FormPractitioner(instance=instance, data=model_to_dict(instance))
page.form_action = base_url + second_base + 'update/'+str(pk)+'/'
template = base_template + second_base + 'snippets/manage.html'
else:
instance = Practitioner()
form = forms.FormPractitioner(instance=instance)
page.form_action = base_url + second_base + 'new/'
template = base_template + second_base + 'snippets/manage.html'
obj_settings = [
{'link': base_url + second_base + 'update/', 'icon': Actions().Icon.edit},
{'link': base_url + 'delete/', 'icon': Actions().Icon.delete},
]
table = Table()
table.cols = ['Name', 'Practitioner Type', 'Phone', 'Email', 'Country']
table.rows = []
for val in obj:
practitioner_link = "<a href='%s' class='text-danger'>%s</a>" % ('/practitioner/asset/%s/'%val.id, val.name)
table.rows.append({
'id': val.id,
'fields': [
{'field': practitioner_link},
{'field': val.type},
{'field': val.mobile1},
{'field': val.email},
{'field': val.country}
]
})
# SCRIPT
page.script = '''
<script>
$('#id_phone').mask('(234)-0-99999999');
$('#id_mobile1').mask('(234) 999-999-9999');
$('#id_mobile2').mask('(234) 999-999-9999');
</script>
'''
# CREATE & UPDATE
if request.method == "POST":
template = base_template + second_base + 'snippets/manage.html'
form = forms.FormPractitioner(request.POST, instance=instance)
if form.is_valid():
#do method to process
posts = request.POST
for post in posts:
if hasattr(instance, post):
setattr(instance, post, form.cleaned_data[post])
# non field specific errors
for f in form.errors:
errors.append(f)
page.non_field_errors = errors
if not errors and not form.errors:
instance.save()
return HttpResponseRedirect(base_url + second_base)
#.........这里部分代码省略.........
示例9: asset
# 需要导入模块: from packages.bin.bin import Page [as 别名]
# 或者: from packages.bin.bin.Page import non_field_errors [as 别名]
#.........这里部分代码省略.........
# SCRIPT
page.script = '''
<script>
$('#id_longitude').mask('9.99999');
$('#id_latitude').mask('9.99999');
</script>
'''
# CREATE & UPDATE
if request.method == "POST":
template = base_template + second_base + 'snippets/manage.html'
form = forms.FormAsset(request.POST, request.FILES, instance=instance)
if form.is_valid():
#do method to process
posts = request.POST
for post in posts:
if hasattr(instance, post):
setattr(instance, post, form.cleaned_data[post])
# non field specific errors
# longitude must lie within 8.920553 > 9.142545
# latitude must lie within 7.147278 > 7.546261 (7.480202)
try:
instance.longitude = float(instance.longitude)
instance.latitude = float(instance.latitude)
except ValueError:
instance.longitude = 0.0
instance.latitude = 0.0
if instance.longitude < 8.920553 or instance.longitude > 9.142545:
errors.append('Longitude entered is out of scope or not correctly entered')
if instance.latitude < 7.147278 or instance.latitude > 7.546261:
errors.append('Latitude entered is out of scope or not correctly entered')
page.non_field_errors = errors
if not errors and not form.errors:
if pk is None:
instance.billing_date = instance.install_date
if pk is not None:
if request.FILES.get('photo1', False):
try:
remove_prev_photo(prev_instance.photo1.url)
instance.photo1 = form.cleaned_data['photo1']
except ValueError:
pass
if request.FILES.get('photo2', False):
try:
remove_prev_photo(prev_instance.photo2.url)
instance.photo2 = form.cleaned_data['photo2']
except ValueError:
pass
if request.FILES.get('photo3', False):
try:
remove_prev_photo(prev_instance.photo3.url)
instance.photo3 = form.cleaned_data['photo3']
except ValueError:
pass
if request.FILES.get('photo4', False):
try:
remove_prev_photo(prev_instance.photo4.url)
instance.photo4 = form.cleaned_data['photo4']
except ValueError:
pass
if request.FILES.get('photo5', False):
try:
remove_prev_photo(prev_instance.photo5.url)
instance.photo5 = form.cleaned_data['photo5']
except ValueError:
pass
instance.longitude = "%.6f" % float(instance.longitude)
instance.latitude = "%.6f" % float(instance.latitude)
instance.practitioner = obj_practitioner
instance.save()
return HttpResponseRedirect(base_url + second_base + '%s/' % qk)
#render to browser
return render_to_response(template,
{'s': s, 'form': form, 'page': page, 'table': table, 'obj': obj, 'settings': obj_settings,
'practitioner': obj_practitioner},
context_instance=RequestContext(request)
)