From: Michael Wood <michael.g.wood@intel.com>
To: "Damian, Alexandru" <alexandru.damian@intel.com>,
"toaster@yoctoproject.org" <toaster@yoctoproject.org>
Subject: Re: [review-request] adamian/20150515_fix_table_header
Date: Tue, 19 May 2015 17:31:40 +0100 [thread overview]
Message-ID: <555B656C.9040101@intel.com> (raw)
In-Reply-To: <CAJ2CSBv=Avv8rn1_uUmxB3Bk2R7LFkfSGq=rxSa=nBE6_RiRqQ@mail.gmail.com>
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.
>
next prev parent reply other threads:[~2015-05-19 16:31 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-19 15:27 [review-request] adamian/20150515_fix_table_header Damian, Alexandru
2015-05-19 16:31 ` Michael Wood [this message]
2015-05-20 13:38 ` Damian, Alexandru
2015-05-21 10:12 ` Damian, Alexandru
2015-05-21 10:23 ` Barros Pena, Belen
2015-05-21 10:27 ` Barros Pena, Belen
2015-05-21 10:25 ` Michael Wood
2015-05-21 10:43 ` Damian, Alexandru
2015-05-29 13:58 ` Damian, Alexandru
2015-06-01 13:43 ` Paul Eggleton
2015-06-01 13:49 ` Damian, Alexandru
2015-06-01 15:33 ` Paul Eggleton
2015-06-02 9:11 ` Damian, Alexandru
2015-06-02 11:32 ` Damian, Alexandru
2015-06-03 11:50 ` Michael Wood
2015-06-03 14:33 ` Damian, Alexandru
2015-05-19 16:36 ` Barros Pena, Belen
-- strict thread matches above, loose matches on Subject: below --
2015-05-15 13:45 Damian, Alexandru
2015-05-15 16:52 ` Michael Wood
2015-05-21 9:47 ` Damian, Alexandru
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=555B656C.9040101@intel.com \
--to=michael.g.wood@intel.com \
--cc=alexandru.damian@intel.com \
--cc=toaster@yoctoproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.