From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by yocto-www.yoctoproject.org (Postfix, from userid 118) id E0164E0095D; Tue, 19 May 2015 09:31:44 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on yocto-www.yoctoproject.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-HAM-Report: * -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low * trust * [74.125.82.51 listed in list.dnswl.org] * -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% * [score: 0.0000] Received: from mail-wg0-f51.google.com (mail-wg0-f51.google.com [74.125.82.51]) by yocto-www.yoctoproject.org (Postfix) with ESMTP id 3A6CEE0027F for ; Tue, 19 May 2015 09:31:42 -0700 (PDT) Received: by wgfl8 with SMTP id l8so24365708wgf.2 for ; Tue, 19 May 2015 09:31:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=ZbPdXUQ29XxXcx0o5b8q8shVO29Zi6/qj4SRaodzHNI=; b=KWAsg6eN48DJbZfHlBpjC6p370R5mcKSB89hyirsD4WLiHbcKHOhQpWl91vvkGKsDC Lt4Vgf5cSniO17NAv7J1AEInm3RWgM7EC5gFcYmFlD/J1g828dWwVoCQYDfZrWGutEIe ilSicFPEXpQOS00Ta9P7DqmJMtMAlbiRO7ZnveWLLodCfLSkJss/BskAtUSjkGUZ3oA/ gFUAZmjGPZXEZd4mIMa6lj9Nbl2ikBkkrB+uz9DkcP7P88vI9PkzHEP5VlF/xqZdUQg9 G/RLkOCeOLt8HJqW39tQwezEaBQ3boVGWF8JVpwl0iG707xL0LkhkjG9IzwSq8ylYcxc 7fvQ== X-Gm-Message-State: ALoCoQluFdSc6lHS3R8z89AsvsURZ3xNK7k3LTTAHozfC4G9DErulPxWVo0dtyLhYup/ocW2jYa5 X-Received: by 10.180.107.38 with SMTP id gz6mr33208652wib.63.1432053101870; Tue, 19 May 2015 09:31:41 -0700 (PDT) Received: from [192.168.2.36] ([83.217.123.106]) by mx.google.com with ESMTPSA id u9sm22531437wjx.15.2015.05.19.09.31.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 May 2015 09:31:40 -0700 (PDT) Message-ID: <555B656C.9040101@intel.com> Date: Tue, 19 May 2015 17:31:40 +0100 From: Michael Wood User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: "Damian, Alexandru" , "toaster@yoctoproject.org" References: In-Reply-To: Subject: Re: [review-request] adamian/20150515_fix_table_header X-BeenThere: toaster@yoctoproject.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Web based interface for BitBake List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 May 2015 16:31:45 -0000 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi, Review below. - - libtoaster.makeTypeahead(newBuildProjectInput, { type : "projects" }, function(item){ + libtoaster.makeTypeahead(newBuildProjectInput, libtoaster.ctx.projectsUrl, { type : "projects", format : "json" }, function(item){ /* successfully selected a project */ newBuildProjectSaveBtn.removeAttr("disabled"); selectedProject = item; + + }) I understand the having the xhrUrl as a new parameter, but it doesn't make any sense to me to have "type" and "format", no one should expect setting the type to json as an argument to some magic urls in the request would then return something to consume for an API. How are you supposed to know which urls support JSON responses? Really wouldn't be happy with that. If you're wanting to avoid having a query for the projects html page and another copy of it for the API response why not use a defined Queryset? the django QuerySet managers are exactly for this. + /* we set the effective context of the page to the currently selected project */ + /* TBD: do we override even if we already have a context project ?? */ + /* TODO: replace global library context with references to the "selected" project */ + libtoaster.ctx.projectPageUrl = selectedProject.projectPageUrl; + libtoaster.ctx.xhrProjectEditUrl = selectedProject.xhrProjectEditUrl; + libtoaster.ctx.projectName = selectedProject.name; What happens if something else accesses those afterwards? If you select a project then close the popup you've potentially broken any other "user" of that context data. Ideally those properties are read-only. +class RedirectException(Exception): + def __init__(self, view, g, mandatory_parameters, *args, **kwargs): + super(RedirectException, self).__init__() + self.view = view + self.g = g + self.mandatory_parameters = mandatory_parameters + self.oargs = args + self.okwargs = kwargs + + def get_redirect_response(self): + return _redirect_parameters(self.view, self.g, self.mandatory_parameters, self.oargs, self.okwargs) + Using HTTP redirects are a real pain because they get cached by the browser and are very difficult to invalidate. - def projects(request): - template="projects.html" + def template_renderer(template): + def func_wrapper(view): + def returned_wrapper(request, *args, **kwargs): + try: + context = view(request, *args, **kwargs) + except RedirectException as e: + return e.get_redirect_response() + + if request.GET.get('format', None) == 'json': + # objects is a special keyword - it's a Page, but we need the actual objects here + # in XHR, the objects come in the "list" property + if "objects" in context: + context["list"] = context["objects"].object_list + del context["objects"] + + # convert separately the values that are JSON-serializable + json_safe = {} + for k in context: + try: + jsonfilter(context[k]) + json_safe[k] = context[k] + except TypeError as te: + # hackity-hacky: we serialize the structure using a default serializer handler, then load + # it from JSON so it can be re-serialized later in the proper context # hackity-hacky !! We're doing re-factoring to remove hacks and awkward code, let's not be adding them back in at the same rate. Michael On 19/05/15 16:27, Damian, Alexandru wrote: > Hi, > > Can you please review this branch ? It brings in an important piece of > refactoring to move Toaster towards the REST-style API that will > enable a cleaner design and support for interconnection with other > systems. > > Getting into details, the "New build" button in all the pages, bar the > project page, now fetches data using the projects API, which is just > the "all projects" page in machine-readable format. This cleans up a > bit the overloading of the xhr_datatypeahead; after the API > refactoring, all xhr_ calls should be completely replaced with proper > calls to the REST endpoints. > > The code is here: > https://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/log/?h=adamian/20150515_fix_table_header > > Incidentally, this patch fixes the "new build" breakage by the first > round of URL refactoring, and the "construction" of URLs on the client > side. > > Can you please review and comment ? > > Cheers, > Alex > > -- > Alex Damian > Yocto Project > SSG / OTC > > --------------------------------------------------------------------- > Intel Corporation (UK) Limited > Registered No. 1134945 (England) > Registered Office: Pipers Way, Swindon SN3 1RJ > VAT No: 860 2173 47 > > This e-mail and any attachments may contain confidential material for > the sole use of the intended recipient(s). Any review or distribution > by others is strictly prohibited. If you are not the intended > recipient, please contact the sender and delete all copies. >