Re: 2 questions: unique properties + history
Nagy Gabor <[email protected]>
| Newsgroups | gmane.comp.bug-tracking.roundup.user |
|---|---|
| Message-ID | <20210226124707.4bc5eb0b@fejer> |
Dear Ralf,
Thank you for reply and your sample codes. Then I will use db._db to
access the database API, if necessary.
> On Wed, Feb 24, 2021 at 02:47:59PM +0100, Nagy Gabor wrote:
> > multiple IDs either, I was asked to implement it.
> >
> > Now I am still struggling with the Hyperdb class wrapper of the web
> > interface. My (lame?) question is how can I access items of classes
> > via their key property, or at least fetch the ID, like
> > db.status.lookup("resolved").
>
> You can alway access the underlying API by using db._db where the db
> is the web hyperdb wrapper and _db is the hyperdb object.
>
> I don't think the hyperdb wraps the lookup class, you can still use
> filter, something along the lines of
> db.status.filter (None, dict (name = 'resolved'))
> or use the hyperdb layer directly.
>
> > As I see, all operation requires the numeric ID of
> > the item (@link@ etc.). Let's say I want to add a button "Change
> > status to resolved" to the web page. To this end, I need the ID of
> > "resolved" item of status class (right?). I do not want to hardcode
> > to the HTML template that this is, let's say, 6. What is the easiest
> > way to retrieve the ID of the status with (key property) name
> > "resolved"? I can do it (loop through db/status/list, etc.), but
> > none of my solutions is nice... If not necessary, I don't want to
> > use low level methods, but if it is necessary, I will. :)
>
> In many places you can use the key property instead of the id, I don't
> see enough of your use-case to suggest what to do in your case.
In fact, I want to write a wizard for editing issues and to mimic a
process management system: The layout of issue.item html page should
depend on the actual status of the issue. For example, if the status is
"new", then I want to restrict user to set the status to "phase1A" or
"phase1B". (And I don't want to use the "menu" method, a hidden status
variable should be set silently by an onclick javascript action when
the user pressed a button - and for this, I will need the IDs of the
statuses).
But after thinking on this a bit, I realized that I should probably
follow the relevant part of the customization guide (and search for
working examples for inspection):
https://roundup-tracker.org/docs/customizing.html#setting-up-a-wizard-or-druid-for-controlled-adding-of-issues
> > > >1. Is it possible to tell Roundup to enforce the uniqueness of
> > > >more than one property of a class?
>
> I'm doing this with an auditor, taken from my lib:
>
> def is_matching_result (cl, kw, search_result) :
> for k, v in kw.iteritems () :
> if isinstance (cl.properties [k], String) :
> if cl.get (search_result, k) != v :
> return False
> return True
> # end def is_matching_result
>
> def check_unique (_, cl, id, ** kw) :
> search = cl.filter (None, kw)
> # strings do a substring search.
> for s in search :
> if s != id and is_matching_result (cl, kw, s) :
> r = []
> for k, v in kw.iteritems () :
> attr = _ (str (k))
> val = cgi.escape (str (v))
> r.append ("%(attr)s=%(val)s" % locals ())
> raise Reject \
> (_ ("Duplicate: %s: %s%s") % (', '.join (r),
> cl.classname, s)) # end def check_unique
>
> This is used in an auditor like so:
> common.check_unique (_, cl, nodeid, nickname = v)
> Where nickname is a property of user where you don't want two users to
> have the same nickname.
>
> Where _ is gettext:
> from roundup.cgi.TranslationService import get_translation
> _ = get_translation \
> (db.config.TRACKER_LANGUAGE, db.config.TRACKER_HOME).gettext
>
> Sorry if I've omitted some code, you can find everything on github
> https://github.com/time-track-tool/time-track-tool
> And yes, the code has peculiar non-pep formatting, sorry.
>
> Note that this code has race-conditions depending on the SQL isolation
> level you set in the database. It would be better to enforce this via
> a uniqueness constraint. As John already said: Code to do this via the
> database is welcome.
OK. Unfortunately, I am not a Python expert and I am far from
complete understanding of Roundup code. I think most of my questions
are implied by this: I am trying to understand what Roundup can and
cannot do. But I do not want to spam this ML with Q&A emails, I will
use irc instead (I just have to find a good time for most timezones :).
But if I implement this to the (hyper)database layer, I will definitely
submit a patch. :)
My little contribution now is just a bugreport in customization guide:
The first line of
https://roundup-tracker.org/docs/customizing.html#editing-multiple-items-in-an-index-view
issue.index.html should be mentioned instead of issue.item.html
> > > >+1. My lame bonus question:
> > > >Can I change the initial id (of issues) from 1 to an other
> > > >number? :) (To easily "continue" the numberings of an old issue
> > > >tracker.)
> > >
> > > There is a setid method in the database. But it is not immediately
> > > obvious to me how to use it. It may be usable from initial_data.py
> > > as db.setid('issue', 23345) but I have never used it.
>
> I think this would work.
>
> > > I think the "easiest" way to do this is to use the importtables
> > > function in roundup_admin to seed the id.
>
> Yes, I think this is currently the only user of the method.
Thank you again,
Gábor
> Ralf
_______________________________________________
Roundup-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/roundup-users