Re: 2 questions: unique properties + history
Ralf Schlatterbeck <[email protected]>
| Newsgroups | gmane.comp.bug-tracking.roundup.user |
|---|---|
| Message-ID | <[email protected]> |
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.
> > >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.
> > >+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.
Ralf
--
Dr. Ralf Schlatterbeck Tel: +43/2243/26465-16
Open Source Consulting www: www.runtux.com
Reichergasse 131, A-3411 Weidling email: [email protected]