當前位置: 首頁>>代碼示例>>Python>>正文


Python Page.id方法代碼示例

本文整理匯總了Python中packages.bin.bin.Page.id方法的典型用法代碼示例。如果您正苦於以下問題:Python Page.id方法的具體用法?Python Page.id怎麽用?Python Page.id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在packages.bin.bin.Page的用法示例。


在下文中一共展示了Page.id方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: UserManage

# 需要導入模塊: from packages.bin.bin import Page [as 別名]
# 或者: from packages.bin.bin.Page import id [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()
#.........這裏部分代碼省略.........
開發者ID:pukonu,項目名稱:doas,代碼行數:103,代碼來源:views.py


注:本文中的packages.bin.bin.Page.id方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。