In https://sourceforge.net/p/roundup/mailman/roundup-users/thread/20190226175830.817694C0555%40itserver6.localdomain/#msg36597696 Tom asked for
I have a request from one of our tracker users to have 2 types of submit buttons for issue creation or editing. One submit button would write to the database (messages too) and do nothing else (silent). The other would work as it does now, writing to the database and sending emails using the nosy list. I don't see an easy way to do that other than have javascript that sets a field (input type="hidden") to a value that the detector nosyreaction.py can check.
See the thread for more ideas on how to implement this.
I implemented this for my tracker adding a "Silent Change" button next to the "Submit Changes" button.
Create a new edit2 action and invoke it when a web form requests the edit action. In extensions/edit2.py:
1 from roundup.cgi.actions import EditItemAction
2
3 class Edit2Action(EditItemAction):
4
5 def handle(self):
6 # If we want to have two actions on a form e.g.:
7 # 1 Submit changes and send nosy email
8 # 2 Submit changes and do not send nosy email
9 #
10 # We need some way to pass this selection to the detectors
11 # where the nosy email is sent.
12 #
13 # One way to do it is to use the per transaction db object that
14 # is accessible by the detectors (auditors/reactors).
15 # Create a dictionary in the db object and map the form data
16 # into the dictionary.
17 #
18 # Add this to your form:
19 # (the button must have the same name (submit_button) as the
20 # primary submit button)
21 #
22 # <button class="second-button" tal:condition="context/is_edit_ok"
23 # type="submit" name="submit_button"
24 # value="silent_change" i18n:translate="">
25 # Silent Change</button>
26 #
27 # Using a button element lets you translate the text on
28 # the button (Silent Change) without changing the value of
29 # submit_button field.
30 #
31 # In reactors (or auditors) the data is accessed as:
32 #
33 # try:
34 # if db.web['submit'] == "silent_change":
35 # logger.debug("silent_change issue%s: no notification.", nodeid)
36 # return
37 # except AttributeError, KeyError:
38 # # The web attribute or submit key don't exist.
39 # # That's fine. We were probably triggered by an email
40 # # or cli based change.
41 # pass
42
43 self.db.web = {} # create the dict
44 # populate the dict by getting the value of the submit_button
45 # element from the form. Some forms don't have a submit button
46 # e.g. edit form to update user's queries.
47 if 'submit_button' in self.form:
48 self.db.web['submit'] = self.form['submit_button'].value
49 else:
50 self.db.web['submit'] = None
51
52 # call the core EditItemAction to process the edit.
53 EditItemAction.handle(self)
54
55 def init(instance):
56 '''Override the default edit action with this new version'''
57 instance.registerAction('edit', Edit2Action)
Then in your detectors/nosyreaction.py in your nosyreaction function add:
at the top of the file so it prevents sending email if a silent change was requested. (Make sure you check the indentation on cut/paste.) You might want to add some logging, or send a nosy message only to the assigned to person or what ever your site requires.
Now add the button in issue.item.html:
<button class="second-button" tal:condition="context/is_edit_ok" type="submit" name="submit_button" value="silent_change" i18n:translate=""> Silent Change</button>
after the <span tal:replace="structure context/submit">submit button</span>
In sysadmin.css I added:
/* secondary submit button */ input[type="submit"].second-button, button.second-button { background: transparent; margin: 0px 10px; }
to make the button look like a secondary button (box with the page background showing though).