Merge lp:~acoconut/systers/flexible_essays into lp:systers
- flexible_essays
- Merge into stable
Status: | Superseded |
---|---|
Proposed branch: | lp:~acoconut/systers/flexible_essays |
Merge into: | lp:systers |
Diff against target: |
504 lines (+105/-81) 3 files modified
Mailman/Cgi/listinfo.py (+16/-6) Mailman/DlistUtils.py (+88/-69) bin/rmlist (+1/-6) |
To merge this branch: | bzr merge lp:~acoconut/systers/flexible_essays |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Robin J | Pending | ||
Review via email:
|
This proposal supersedes a proposal from 2012-06-21.
This proposal has been superseded by a proposal from 2012-06-27.
Commit message
Description of the change
I fixed everything Robin told me too:
- The for loop that goes through the list of questions.
- The length of the lines I wrote.
- Deleted the syslog statements I wrote when I was debugging because they weren't really useful.
- Added a TODO line.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Robin J (robin-jeffries) wrote : Posted in a previous version of this proposal | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Ana Cutillas (acoconut) wrote : Posted in a previous version of this proposal | # |
> Review: Needs Fixing
>
> A suggestion for the future: when you put in a syslog statement, put in
> some identifying text, preferably the file that the message came from and
> what the data is. e.g.,
>
> syslog('info', "listinfo.py: essay question data for question %d = %s",
> i, mlist.questions
>
Mmm... I thought I had gotten rid of all the syslog statements, I was just
using them for my own testing purposes.
>
> In listinfo.py
>
> I'm confused by your parameters --can you remind me what the datastructure
> is for mlist.questions (what the columns are? I don't understand how you
> can do things with mlist.questions
> worked "by accident". )
>
[{1: ['talk about yourself', 'talk', 'largebox', 300, 'top']}, {2: ['Are
you a woman?', 'woman', 'checkbox', 0, 'bottom']}]
So basically:
[{question_number: ['question description', 'short version of question',
'type of box', 'size of box', 'position']}]
Why do you think this works by accident?
>
> I believe that mailman coding style requires 80 column line lengths. Can
> you shorten the long lines? (you may need to add some extra parens to make
> python understand that your new lines are continuation lines).
>
Ok, I will. There are some files in the systers folders that have very long
lines too, should I shorten those too? I mean code that I didn't write but
has very long lines.
>
> For things you are planning to do later (even if later is in the
> indefinite future, please start the comment with:
> #TODO (your name):
> that way it's easy to grep the code and find things you left for later.
>
> As best I can tell, you didn't actually make any changes to DlistUtils.py.
> Is that correct? If not, can you point out the places you made changes
> (it looks like these were the changes to fix our nasty lower case bug;
> maybe you had to import that file onto your branch?)
>
I only modified listinfo.py for the changes for the first week.
>
> Where do you define mlist.questions? (presumably in MailList.py, but why
> wasn't that included in your merge?) If you just manually created a
> mailing list with questions, please put that in the description of the
> change, showing exactly what is in that faked data structure.
>
mlist.questions was something that mailman was already using. It used to
get the one question from the pickle file, now it gets the data structure I
posted earlier.
> Use the description of the change to tell your reviewers the things they
> need to know to understand this code (like the mlist.questions data
> structure)
>
>
> Please, let me know if all this made or not sense and I'll make the
changes and resubmit .
> --
> https:/
> You are the owner of lp:~acoconut/systers/flexible_essays.
>
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Robin J (robin-jeffries) wrote : Posted in a previous version of this proposal | # |
1. It's fine to leave the syslog statements in (you can make a grep for them at the end of the summer). If they happen to make it into production, we turn DEBUG off there, so there is no harm. And you never know when a bug will come back to you
2. For the way you march down the mlist.questions data structure, I don't understand how you got it to work. If I understand it correctly, given
[{1: ['talk about yourself', 'talk', 'largebox', 300, 'top']}, {2: ['Are
you a woman?', 'woman', 'checkbox', 0, 'bottom']}]
your tests are for mlist.questions
the first time through that is mlist.questions
The next time through it is mlist.questions
(also, I missed this earlier. It would be better code to have your loop statement in line 12 in the diff be
for question in mlist.questions:
(range has to take that number an convert it to a location in the data structure, and this just marches down the data structure)
If you do that, then the test becomes something like
if question[1][2] ==...
(see how this is clearer? You could make it even clearer by making this a named structure (where you might have question.boxtype for the above), but for the small number of times you are going to reference it, it may not be worth it. But we may want to revisit this when we see how complex the admin UI is and how much improvement in clarity it gives)
3. For the updating of mlist.questions. I understand more now, but I think there is going to be an issue when you do the admin GUI -- this is not where things that are changed in the admin gui are stored (they are not part of mlist). This is not something you introduced, but it is something you will need to correct when you get to doing the admin GUI for this. Let's leave that issue until later.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Ana Cutillas (acoconut) wrote : Posted in a previous version of this proposal | # |
Yes, I see what you meant about the for loop and I just got done fixing it.
I had to add an index though, I'm going to push the new version so that you
can see it. I couldn't figure out a way of doing it without an index.
As for the lines length, there are lines a lot longer that I didn't write.
I made mine shorter, let me know if I should change the ones I didn't write
too.
Thanks Robin! I love learning little things like the for loop thing. :)
On Tue, Jun 26, 2012 at 7:26 AM, Robin J <email address hidden> wrote:
> 1. It's fine to leave the syslog statements in (you can make a grep for
> them at the end of the summer). If they happen to make it into production,
> we turn DEBUG off there, so there is no harm. And you never know when a
> bug will come back to you
>
> 2. For the way you march down the mlist.questions data structure, I don't
> understand how you got it to work. If I understand it correctly, given
>
> [{1: ['talk about yourself', 'talk', 'largebox', 300, 'top']}, {2: ['Are
> you a woman?', 'woman', 'checkbox', 0, 'bottom']}]
>
> your tests are for mlist.questions
>
> the first time through that is mlist.questions
> the diff) -- that would be 'talk' above.)
>
> The next time through it is mlist.questions
> exist, right? shouldn't your test (and other items) be
> mlist.questions
>
> (also, I missed this earlier. It would be better code to have your loop
> statement in line 12 in the diff be
> for question in mlist.questions:
> (range has to take that number an convert it to a location in the data
> structure, and this just marches down the data structure)
>
> If you do that, then the test becomes something like
> if question[1][2] ==...
>
> (see how this is clearer? You could make it even clearer by making this a
> named structure (where you might have question.boxtype for the above), but
> for the small number of times you are going to reference it, it may not be
> worth it. But we may want to revisit this when we see how complex the
> admin UI is and how much improvement in clarity it gives)
>
> 3. For the updating of mlist.questions. I understand more now, but I
> think there is going to be an issue when you do the admin GUI -- this is
> not where things that are changed in the admin gui are stored (they are not
> part of mlist). This is not something you introduced, but it is something
> you will need to correct when you get to doing the admin GUI for this.
> Let's leave that issue until later.
>
> --
> https:/
> You are the owner of lp:~acoconut/systers/flexible_essays.
>
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Ana Cutillas (acoconut) wrote : | # |
Mm, ignore the import of DlistUtils for revision, I accidentally left it
there from when I was trying to make the STORM stuff work. Sorry!
On Tue, Jun 26, 2012 at 7:46 PM, Ana Cutillas <email address hidden> wrote:
> Ana Cutillas has proposed merging lp:~acoconut/systers/flexible_essays
> into lp:systers.
>
> Requested reviews:
> Robin J (robin-jeffries)
>
> For more details, see:
> https:/
>
> I fixed everything Robin told me too:
>
> - The for loop that goes through the list of questions.
> - The length of the lines I wrote.
> - Deleted the syslog statements I wrote when I was debugging because they
> weren't really useful.
> - Added a TODO line.
> --
> https:/
> You are the owner of lp:~acoconut/systers/flexible_essays.
>
> === modified file 'Mailman/
> --- Mailman/
> +++ Mailman/
> @@ -22,6 +22,7 @@
> import os
> import cgi
>
> +from Mailman import DlistUtils
> from Mailman import mm_cfg
> from Mailman import Utils
> from Mailman import MailList
> @@ -36,7 +37,6 @@
> i18n.set_
>
>
> -
> def main():
> parts = Utils.GetPathPi
> if not parts:
> @@ -62,7 +62,6 @@
> list_listinfo(
>
>
> -
> def listinfo_
> # Present the general listinfo overview
> hostname = Utils.get_domain()
> @@ -152,7 +151,6 @@
> print doc.Format()
>
>
> -
> def list_listinfo(
> # Generate list specific listinfo
> doc = HeadlessDocument()
> @@ -190,9 +188,24 @@
> # If activated, the content and presence of questions and a field to
> answer them. Added by Systers.
> try:
> if mlist.essay_
> - replacements[
> - <TD COLSPAN="3">""" + mlist.questions
> - replacements[
> rows=8, cols=60).Format() + """ </TD></TR>"""# Added to support
> subscribe essays
> + questions = [] # Added to support subscribe essays
> + index = 1
> + for question in mlist.questions:
> + questions.
> + <TD COLSPAN="3">""" + question[index][0] + """</TD>""")
> + if (question[index][2] == 'smallbox'):
> + questions.
> TextArea(
> + '', rows=1, cols=60).Format() +
> """</TD></TR>""")
> + elif (question[index][2] == 'largebox'):
> + questions.
> TextArea(
> + '', rows=8, cols=60).Format() +
> """</TD></TR>""")
> + elif (question[index][2] == 'checkbox'):
> + #TODO (Ana Cutillas): consider creating a class like
> TextArea for checkboxes?
> + questions.
> name='""" + \
> + question[index][1] + """' value ='""" + \
> + ...
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Robin J (robin-jeffries) wrote : Posted in a previous version of this proposal | # |
That's what code reviews are for.
I will look at the changed code as soon as I can, but I have out of town
guests tonight, and I don't know if I can steal some cycles from work or
not.
Robin
On Tue, Jun 26, 2012 at 10:34 AM, Ana Cutillas <email address hidden> wrote:
> Yes, I see what you meant about the for loop and I just got done fixing it.
> I had to add an index though, I'm going to push the new version so that you
> can see it. I couldn't figure out a way of doing it without an index.
>
> As for the lines length, there are lines a lot longer that I didn't write.
> I made mine shorter, let me know if I should change the ones I didn't write
> too.
>
> Thanks Robin! I love learning little things like the for loop thing. :)
>
> On Tue, Jun 26, 2012 at 7:26 AM, Robin J <email address hidden> wrote:
>
> > 1. It's fine to leave the syslog statements in (you can make a grep for
> > them at the end of the summer). If they happen to make it into
> production,
> > we turn DEBUG off there, so there is no harm. And you never know when a
> > bug will come back to you
> >
> > 2. For the way you march down the mlist.questions data structure, I
> don't
> > understand how you got it to work. If I understand it correctly, given
> >
> > [{1: ['talk about yourself', 'talk', 'largebox', 300, 'top']}, {2: ['Are
> > you a woman?', 'woman', 'checkbox', 0, 'bottom']}]
> >
> > your tests are for mlist.questions
> >
> > the first time through that is mlist.questions
> > the diff) -- that would be 'talk' above.)
> >
> > The next time through it is mlist.questions
> > exist, right? shouldn't your test (and other items) be
> > mlist.questions
> >
> > (also, I missed this earlier. It would be better code to have your loop
> > statement in line 12 in the diff be
> > for question in mlist.questions:
> > (range has to take that number an convert it to a location in the data
> > structure, and this just marches down the data structure)
> >
> > If you do that, then the test becomes something like
> > if question[1][2] ==...
> >
> > (see how this is clearer? You could make it even clearer by making this
> a
> > named structure (where you might have question.boxtype for the above),
> but
> > for the small number of times you are going to reference it, it may not
> be
> > worth it. But we may want to revisit this when we see how complex the
> > admin UI is and how much improvement in clarity it gives)
> >
> > 3. For the updating of mlist.questions. I understand more now, but I
> > think there is going to be an issue when you do the admin GUI -- this is
> > not where things that are changed in the admin gui are stored (they are
> not
> > part of mlist). This is not something you introduced, but it is
> something
> > you will need to correct when you get to doing the admin GUI for this.
> > Let's leave that issue until later.
> >
> > --
> >
> https:/
> > You are the owner of lp:~acoconut/systers/flexible_essays.
> >
>
> --
> https:/
> You are reviewing the pro...
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Robin J (robin-jeffries) wrote : | # |
Ana, please test things before you send out the code for review.
And also add priya and me both to all the reviews. We will trade off who
is reviewing things, but it's good for both of us to see the others
comments.
On Tue, Jun 26, 2012 at 10:48 AM, Ana Cutillas <email address hidden> wrote:
> Mm, ignore the import of DlistUtils for revision, I accidentally left it
> there from when I was trying to make the STORM stuff work. Sorry!
>
> On Tue, Jun 26, 2012 at 7:46 PM, Ana Cutillas <email address hidden> wrote:
>
>> Ana Cutillas has proposed merging lp:~acoconut/systers/flexible_essays
>> into lp:systers.
>>
>> Requested reviews:
>> Robin J (robin-jeffries)
>>
>> For more details, see:
>> https:/
>>
>> I fixed everything Robin told me too:
>>
>> - The for loop that goes through the list of questions.
>> - The length of the lines I wrote.
>> - Deleted the syslog statements I wrote when I was debugging because they
>> weren't really useful.
>> - Added a TODO line.
>> --
>> https:/
>> You are the owner of lp:~acoconut/systers/flexible_essays.
>>
>> === modified file 'Mailman/
>> --- Mailman/
>> +++ Mailman/
>> @@ -22,6 +22,7 @@
>> import os
>> import cgi
>>
>> +from Mailman import DlistUtils
>> from Mailman import mm_cfg
>> from Mailman import Utils
>> from Mailman import MailList
>> @@ -36,7 +37,6 @@
>> i18n.set_
>>
>>
>> -
>> def main():
>> parts = Utils.GetPathPi
>> if not parts:
>> @@ -62,7 +62,6 @@
>> list_listinfo(
>>
>>
>> -
>> def listinfo_
>> # Present the general listinfo overview
>> hostname = Utils.get_domain()
>> @@ -152,7 +151,6 @@
>> print doc.Format()
>>
>>
>> -
>> def list_listinfo(
>> # Generate list specific listinfo
>> doc = HeadlessDocument()
>> @@ -190,9 +188,24 @@
>> # If activated, the content and presence of questions and a field to
>> answer them. Added by Systers.
>> try:
>> if mlist.essay_
>> - replacements[
>> - <TD COLSPAN="3">""" + mlist.questions
>> - replacements[
>> rows=8, cols=60).Format() + """ </TD></TR>"""# Added to support
>> subscribe essays
>> + questions = [] # Added to support subscribe essays
>> + index = 1
>>
>
No, you don't need index; actually, index should always be 1
for the data structure
[{1: ['talk about yourself', 'talk', 'largebox', 300, 'top']}, {2: ['Are
you a woman?', 'woman', 'checkbox', 0, 'bottom']}]
the first time through, question is
{1: ['talk about yourself', 'talk', 'largebox', 300, 'top']}
and the second time through it is
{2: ['Are you a woman?', 'woman', 'checkbox', 0, 'bottom']}
To address 'largebox' and 'checkbox' you want
question[1][2] not
question[index][2]
(If you had tested your code, you would have seen that this causes problems)
(for now, I...
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Ana Cutillas (acoconut) wrote : | # |
Mmm... I definitely tested it before submitting and I actually went back to
it right now and it is working in my environment. AND when I change index
for 1, it doesn't work. I even opened a python interpreter earlier today
and tested the for loop without index and with index and it wouldn't work
with index. I can write up my testes again and show them to you.
It's almost 3am right now (but 82ºF (28 ºC) - I am a Spaniard but heat...
it kills me. I don´t know if I'll ever be able to handle it.) but I will
try the data structure you proposed tomorrow and let you know how that
goes. You're right that I'm not really doing anything with the question
numbers.
On Tue, Jun 26, 2012 at 11:58 PM, Robin J <email address hidden> wrote:
> Ana, please test things before you send out the code for review.
>
> And also add priya and me both to all the reviews. We will trade off who
> is reviewing things, but it's good for both of us to see the others
> comments.
>
>
> On Tue, Jun 26, 2012 at 10:48 AM, Ana Cutillas <email address hidden>
> wrote:
>
> > Mm, ignore the import of DlistUtils for revision, I accidentally left it
> > there from when I was trying to make the STORM stuff work. Sorry!
> >
> > On Tue, Jun 26, 2012 at 7:46 PM, Ana Cutillas <email address hidden>
> wrote:
> >
> >> Ana Cutillas has proposed merging lp:~acoconut/systers/flexible_essays
> >> into lp:systers.
> >>
> >> Requested reviews:
> >> Robin J (robin-jeffries)
> >>
> >> For more details, see:
> >>
> https:/
> >>
> >> I fixed everything Robin told me too:
> >>
> >> - The for loop that goes through the list of questions.
> >> - The length of the lines I wrote.
> >> - Deleted the syslog statements I wrote when I was debugging because
> they
> >> weren't really useful.
> >> - Added a TODO line.
> >> --
> >>
> https:/
> >> You are the owner of lp:~acoconut/systers/flexible_essays.
> >>
> >> === modified file 'Mailman/
> >> --- Mailman/
> >> +++ Mailman/
> >> @@ -22,6 +22,7 @@
> >> import os
> >> import cgi
> >>
> >> +from Mailman import DlistUtils
> >> from Mailman import mm_cfg
> >> from Mailman import Utils
> >> from Mailman import MailList
> >> @@ -36,7 +37,6 @@
> >> i18n.set_
> >>
> >>
> >> -
> >> def main():
> >> parts = Utils.GetPathPi
> >> if not parts:
> >> @@ -62,7 +62,6 @@
> >> list_listinfo(
> >>
> >>
> >> -
> >> def listinfo_
> >> # Present the general listinfo overview
> >> hostname = Utils.get_domain()
> >> @@ -152,7 +151,6 @@
> >> print doc.Format()
> >>
> >>
> >> -
> >> def list_listinfo(
> >> # Generate list specific listinfo
> >> doc = HeadlessDocument()
> >> @@ -190,9 +188,24 @@
> >> # If activated, the content and presence of questions and a field to
> >> answer them. Added by Systers.
> >> try:
> >> if mlist.essay_
> >> - replacements[
> >> - ...
- 85. By Ana Cutillas <email address hidden>
-
Changed the data structure to store the questions. Now it looks like:
[['Talk about yourself', 'talk', 'largebox', 300, 'top'], ['Are you a woman?', 'woman', 'checkbox', 0, 'bottom']]
- 86. By Ana Cutillas <email address hidden>
-
Changed the name of the variable questions to html_questions.
- 87. By Ana Cutillas <email address hidden>
-
Added changes to the DlistUtils.py file to handle the database
operations to the new table form_question. - 88. By Ana Cutillas <email address hidden>
-
Added the database backend and the functionality to connect forms to the database.
- 89. By Ana Cutillas <email address hidden>
-
Made changes to the database and to the way we store the answers. Made
changes to the way we handle the information coming from the form. - 90. By Ana Cutillas <email address hidden>
-
Cleaned up listinfo.py
- 91. By Ana Cutillas <email address hidden>
-
Cleaned up.
- 92. By Ana Cutillas <email address hidden>
-
Cleaned up DlistUtils and changed the error message in subscribe. Added
comments. - 93. By Ana Cutillas <email address hidden>
-
Removed the unused function get_answer from DlistUtils.py
- 94. By Ana Cutillas <email address hidden>
-
Added changes to show the new essays in the pending subscriptions table.
Handle the possibility of a user trying to subscribe twice before the
subscription is reviewed. - 95. By Ana Cutillas <email address hidden>
-
Added the functionality to check that the answers aren't longer than
what the database can hold. - 96. By Ana Cutillas <email address hidden>
-
Added the error message saying that the user hasn't been subscribe to
the list when a user tries to subscribe with a pending subscription. - 97. By Ana Cutillas <email address hidden>
-
Made the changes suggested by Robin: concerning error messages and
asserting the size of the answers.Added the code to mark answers as accepted in the database when a user
is accepted. - 98. By Ana Cutillas <email address hidden>
-
Changed the logic in the checking of answers in subscribe.py
Cleaned up DlistUtils.py - 99. By Ana Cutillas <email address hidden>
-
Added support for setting answers to rejected in the database.
Unmerged revisions
- 99. By Ana Cutillas <email address hidden>
-
Added support for setting answers to rejected in the database.
- 98. By Ana Cutillas <email address hidden>
-
Changed the logic in the checking of answers in subscribe.py
Cleaned up DlistUtils.py - 97. By Ana Cutillas <email address hidden>
-
Made the changes suggested by Robin: concerning error messages and
asserting the size of the answers.Added the code to mark answers as accepted in the database when a user
is accepted. - 96. By Ana Cutillas <email address hidden>
-
Added the error message saying that the user hasn't been subscribe to
the list when a user tries to subscribe with a pending subscription. - 95. By Ana Cutillas <email address hidden>
-
Added the functionality to check that the answers aren't longer than
what the database can hold. - 94. By Ana Cutillas <email address hidden>
-
Added changes to show the new essays in the pending subscriptions table.
Handle the possibility of a user trying to subscribe twice before the
subscription is reviewed. - 93. By Ana Cutillas <email address hidden>
-
Removed the unused function get_answer from DlistUtils.py
- 92. By Ana Cutillas <email address hidden>
-
Cleaned up DlistUtils and changed the error message in subscribe. Added
comments. - 91. By Ana Cutillas <email address hidden>
-
Cleaned up.
- 90. By Ana Cutillas <email address hidden>
-
Cleaned up listinfo.py
Preview Diff
1 | === modified file 'Mailman/Cgi/listinfo.py' |
2 | --- Mailman/Cgi/listinfo.py 2009-08-14 15:41:17 +0000 |
3 | +++ Mailman/Cgi/listinfo.py 2012-06-27 11:21:20 +0000 |
4 | @@ -36,7 +36,6 @@ |
5 | i18n.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE) |
6 | |
7 | |
8 | - |
9 | |
10 | def main(): |
11 | parts = Utils.GetPathPieces() |
12 | if not parts: |
13 | @@ -62,7 +61,6 @@ |
14 | list_listinfo(mlist, language) |
15 | |
16 | |
17 | - |
18 | |
19 | def listinfo_overview(msg=''): |
20 | # Present the general listinfo overview |
21 | hostname = Utils.get_domain() |
22 | @@ -152,7 +150,6 @@ |
23 | print doc.Format() |
24 | |
25 | |
26 | - |
27 | |
28 | def list_listinfo(mlist, lang): |
29 | # Generate list specific listinfo |
30 | doc = HeadlessDocument() |
31 | @@ -190,9 +187,22 @@ |
32 | # If activated, the content and presence of questions and a field to answer them. Added by Systers. |
33 | try: |
34 | if mlist.essay_enabled: |
35 | - replacements['<mm-questions>'] = """<TR> |
36 | - <TD COLSPAN="3">""" + mlist.questions |
37 | - replacements['<mm-essay-box>'] = TextArea('essay', '', rows=8, cols=60).Format() + """ </TD></TR>"""# Added to support subscribe essays |
38 | + questions = [] # Added to support subscribe essays |
39 | + for question in mlist.questions: |
40 | + questions.append("""<TR> |
41 | + <TD COLSPAN="3">""" + question[0] + """</TD>""") |
42 | + if (question[2] == 'smallbox'): |
43 | + questions.append("""<TD>""" + TextArea(question[1],\ |
44 | + '', rows=1, cols=60).Format() + """</TD></TR>""") |
45 | + elif (question[2] == 'largebox'): |
46 | + questions.append("""<TD>""" + TextArea(question[1], \ |
47 | + '', rows=8, cols=60).Format() + """</TD></TR>""") |
48 | + elif (question[2] == 'checkbox'): |
49 | + #TODO (Ana Cutillas): consider creating a class like TextArea for checkboxes? |
50 | + questions.append("""<TD><input type='checkbox' name='""" + \ |
51 | + question[1] + """' value ='""" + \ |
52 | + question[1] + """'></TD></TR>""") |
53 | + replacements['<mm-questions>'] = ''.join(questions) |
54 | else: |
55 | replacements['<mm-questions>'] = '' |
56 | replacements['<mm-essay-box>'] = '' |
57 | |
58 | === modified file 'Mailman/DlistUtils.py' |
59 | --- Mailman/DlistUtils.py 2010-01-31 20:29:48 +0000 |
60 | +++ Mailman/DlistUtils.py 2012-06-27 11:21:20 +0000 |
61 | @@ -40,17 +40,17 @@ |
62 | if self == classObject: |
63 | if self.store == None:#for the case when same object is used for calling more than one functions |
64 | self.store = Store(self.database) |
65 | - result = f(self,*args) |
66 | + result = f(self, *args) |
67 | self.store.commit() |
68 | self.store.close() |
69 | self.store = None |
70 | else:#To handle the nesting issue |
71 | - result = f(self,*args) |
72 | + result = f(self, *args) |
73 | self.store.commit() |
74 | else:#for the case whenever a new object calls its decorated member function |
75 | classObject = self |
76 | self.store = Store(self.database) |
77 | - result = f(self,*args) |
78 | + result = f(self, *args) |
79 | self.store.commit() |
80 | self.store.close() |
81 | self.store = None |
82 | @@ -60,14 +60,14 @@ |
83 | #Define all the classes corresponding to the tables in the database |
84 | class Subscriber(object): |
85 | __storm_table__ = "subscriber" |
86 | - subscriber_id = Int(primary = True,default = AutoReload) |
87 | + subscriber_id = Int(primary = True, default = AutoReload) |
88 | mailman_key = Unicode() |
89 | preference = Int(default = 1) |
90 | format = Int(default = 3) |
91 | deleted = Bool(default = False) |
92 | suppress = Int(default = 0) |
93 | |
94 | - def __init__(self,mlist): |
95 | + def __init__(self, mlist): |
96 | self.mlist = mlist |
97 | self.database = getConn(mlist) |
98 | |
99 | @@ -76,11 +76,11 @@ |
100 | if addr == None: |
101 | return None |
102 | |
103 | - command = "result = self.store.find(Subscriber,Subscriber.mailman_key == unicode(addr.lower(),'utf-8'))\na = [(subscriber.subscriber_id) for subscriber in result]\n" |
104 | + command = "result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(addr.lower(),'utf-8'))\na = [(subscriber.subscriber_id) for subscriber in result]\n" |
105 | if DEBUG_MODE: |
106 | syslog('info', "DlistUtils:(getSubscriber_id_raw)executing query:\n%s", command) |
107 | #storm recognizes unicode only |
108 | - result = self.store.find(Subscriber,Subscriber.mailman_key == unicode(addr.lower(),"utf-8")) |
109 | + result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(addr,"utf-8")) |
110 | a = [(subscriber.subscriber_id) for subscriber in result] |
111 | if DEBUG_MODE: |
112 | syslog('info', 'value of a is: %s\n', a) |
113 | @@ -136,70 +136,70 @@ |
114 | @decfunc |
115 | def setDisable(self, member, flag): |
116 | """Disable/enable delivery based on mm_cfg.DisableDelivery""" |
117 | - command = "result = self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,'utf-8'))\noldval = [(subscriber.suppress) for subscriber in result]\n" |
118 | + command = "result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,'utf-8'))\noldval = [(subscriber.suppress) for subscriber in result]\n" |
119 | if DEBUG_MODE: |
120 | - syslog('info', 'DlistUtils(setDisable):Executing query:\n%s\n Member whoes suppress value is to be found \n %s', command,member) |
121 | - result = self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,"utf-8")) |
122 | + syslog('info', 'DlistUtils(setDisable):Executing query:\n%s\n Member whose suppress value is to be found \n %s', command, member) |
123 | + result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,"utf-8")) |
124 | oldval = [(subscriber.suppress) for subscriber in result] |
125 | if oldval == []: |
126 | if DEBUG_MODE: |
127 | syslog('info','oldval is an empty list.\nThis can happen either because of\n 1)Permission issues (Do a: bin/check_perms)\n 2)Inconsistency between database and pickle files (A user is in the database but not in pickle files or vice versa,Do a bin/find_problems.py)') |
128 | oldval = oldval[0] |
129 | if DEBUG_MODE: |
130 | - syslog('info','the value of oldval is %s:',oldval) |
131 | + syslog('info','the value of oldval is %s:', oldval) |
132 | |
133 | if flag: |
134 | newval = oldval | 1 # Disable delivery |
135 | else: |
136 | newval = oldval & ~1 # Enable delivery |
137 | if DEBUG_MODE: |
138 | - syslog('info','the value of newval is %s:',newval) |
139 | - command = "self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,'utf-8')).set(suppress = newval)\n" |
140 | + syslog('info','the value of newval is %s:', newval) |
141 | + command = "self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,'utf-8')).set(suppress = newval)\n" |
142 | if DEBUG_MODE: |
143 | syslog('info', 'DlistUtils(setDisable):Executing query:\n%s', command) |
144 | - self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,"utf-8")).set(suppress = newval) |
145 | + self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,"utf-8")).set(suppress = newval) |
146 | |
147 | @decfunc |
148 | def setDigest(self, member, flag): |
149 | """Disable/enable delivery based on user digest status""" |
150 | |
151 | - command = "result = self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,'utf-8'))\noldval = [(subscriber.suppress) for subscriber in result]\n" |
152 | + command = "result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,'utf-8'))\noldval = [(subscriber.suppress) for subscriber in result]\n" |
153 | if DEBUG_MODE: |
154 | syslog('info', 'DlistUtils(setDigest):Executing query:\n%s', command) |
155 | - result = self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,"utf-8")) |
156 | + result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,"utf-8")) |
157 | oldval = [(subscriber.suppress) for subscriber in result] |
158 | if oldval == []: |
159 | if DEBUG_MODE: |
160 | syslog('info','oldval is an empty list.\nThis can happen either because of\n 1)permission issues (Do a: bin/check_perms)\n 2)Inconsistency between database and pickle files (A user is in the database but not in pickle files or vice versa,Do a bin/find_problems.py)') |
161 | oldval = oldval[0] |
162 | if DEBUG_MODE: |
163 | - syslog('info','value of oldval %s:',oldval) |
164 | + syslog('info','value of oldval %s:', oldval) |
165 | |
166 | if flag: |
167 | newval = oldval | 2 # Suppress delivery (in favor of digests) |
168 | else: |
169 | newval = oldval & ~2 # Enable delivery (instead of digests) |
170 | |
171 | - command = "self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,'utf-8')).set(suppress = newval)\n" |
172 | + command = "self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,'utf-8')).set(suppress = newval)\n" |
173 | if DEBUG_MODE: |
174 | syslog('info', 'DlistUtils(setDigest):Executing query:\n%s', command) |
175 | - self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,"utf-8")).set(suppress = newval) |
176 | + self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,"utf-8")).set(suppress = newval) |
177 | |
178 | @decfunc |
179 | def changePreference(self, member, preference): |
180 | """Change a user's default preference for new threads.""" |
181 | - command = "self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,'utf-8')).set(preference = preference)\n" |
182 | + command = "self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,'utf-8')).set(preference = preference)\n" |
183 | if DEBUG_MODE: |
184 | syslog('info', 'DlistUtils(changePreference):Executing query:\n%s', command) |
185 | - self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,"utf-8")).set(preference = preference) |
186 | + self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,"utf-8")).set(preference = preference) |
187 | |
188 | @decfunc |
189 | def changeFormat(self, member, format): |
190 | """Change a user's preferred delivery format (plain text and/or html)""" |
191 | - command = "self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,'utf-8')).set(format = format)\n" |
192 | + command = "self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,'utf-8')).set(format = format)\n" |
193 | if DEBUG_MODE: |
194 | syslog('info', 'DlistUtils(changeFormat):Executing query:\n%s', command) |
195 | - self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,"utf-8")).set(format = format) |
196 | + self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,"utf-8")).set(format = format) |
197 | |
198 | ### We have to watch out for a tricky case (that actually happened): |
199 | ### User foo@bar.com changes her address to something already in the |
200 | @@ -207,32 +207,32 @@ |
201 | @decfunc |
202 | def changeAddress(self, oldaddr, newaddr): |
203 | """Change email address in SQL database""" |
204 | - #if DEBUG_MODE: |
205 | - #syslog('info', "Changing email address on %s from '%s' to '%s'", self.mlist.internal_name(), oldaddr, newaddr) |
206 | + if DEBUG_MODE: |
207 | + syslog('info', "Changing email address on %s from '%s' to '%s'", self.mlist.internal_name(), oldaddr, newaddr) |
208 | ## Check if newaddr is in sql database |
209 | - num_matches = self.store.find(Subscriber,Subscriber.mailman_key == unicode(newaddr,"utf-8")).count() |
210 | + num_matches = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(newaddr.lower(),"utf-8")).count() |
211 | |
212 | if num_matches > 1: |
213 | - #syslog('error', 'Multiple users with same key (%s): %s', self.mlist.internal_name(), newaddr) |
214 | + syslog('error', 'Multiple users with same key (%s): %s', self.mlist.internal_name(), newaddr) |
215 | return |
216 | if num_matches == 1: |
217 | self.mergeSubscribers(oldaddr, newaddr) |
218 | |
219 | - command = "num_matches = self.store.find(Subscriber,Subscriber.mailman_key == unicode(newaddr,'utf-8')).count()\nself.store.find(Subscriber,Subscriber.mailman_key == unicode(oldaddr,'utf-8')).set(mailman_key = unicode(newaddr,'utf-8'))\nself.store.find(Subscriber,Subscriber.mailman_key == unicode(newaddr,'utf-8')).set(deleted = False)\n" |
220 | + command = "num_matches = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(newaddr,'utf-8')).count()\nself.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(oldaddr,'utf-8')).set(mailman_key = unicode(newaddr,'utf-8'))\nself.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(newaddr.lower(),'utf-8')).set(deleted = False)\n" |
221 | if DEBUG_MODE: |
222 | syslog('info', 'DlistUtils(changeAddress):Executing query:\n%s', command) |
223 | - self.store.find(Subscriber,Subscriber.mailman_key == unicode(oldaddr,"utf-8")).set(mailman_key = unicode(newaddr,"utf-8")) |
224 | + self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(oldaddr,"utf-8")).set(mailman_key = unicode(newaddr,"utf-8")) |
225 | self.store.commit() |
226 | - self.store.find(Subscriber,Subscriber.mailman_key == unicode(newaddr,"utf-8")).set(deleted = False) |
227 | + self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(newaddr.lower(),"utf-8")).set(deleted = False) |
228 | |
229 | @decfunc |
230 | def unsubscribeFromList(self, key): |
231 | """Indicate that a user has unsubscribed by setting the deleted flag in the subscriber table.""" |
232 | |
233 | - command = "self.store.find(Subscriber,Subscriber.mailman_key == unicode(key,'utf-8')).set(deleted = True)\nself.store.find(Alias,Alias.subscriber_id == subscriber_id).remove()\n" |
234 | + command = "self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(key,'utf-8')).set(deleted = True)\nself.store.find(Alias,Alias.subscriber_id == subscriber_id).remove()\n" |
235 | if DEBUG_MODE: |
236 | syslog('info', 'DlisUtils(unsubscribeFromList):Executing query:\n%s', command) |
237 | - self.store.find(Subscriber,Subscriber.mailman_key == unicode(key,"utf-8")).set(deleted = True) |
238 | + self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(key,"utf-8")).set(deleted = True) |
239 | # get the subscriber id from the mailman_key & delete all aliases |
240 | subscriber_id = self.getSubscriber_id_raw(key) |
241 | |
242 | @@ -245,20 +245,27 @@ |
243 | def subscribeToList(self, key): |
244 | """Add a member to the subscriber database, or change the record from deleted if it was already present.""" |
245 | |
246 | - command = "count = (self.store.find(Subscriber,Subscriber.mailman_key == unicode(key,'utf-8'))).count()\n" |
247 | + command = "count = (self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(key.lower(),'utf-8'))).count()\n" |
248 | if DEBUG_MODE: |
249 | syslog('info', 'DlistUtils(subscribeToList):Executing query:\n%s', command) |
250 | # First see if member is subscribed with deleted field = false |
251 | - count = (self.store.find(Subscriber,Subscriber.mailman_key == unicode(key,"utf-8"))).count() |
252 | + count = (self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(key.lower(),"utf-8"))).count() |
253 | |
254 | if count: |
255 | - command = "self.store.find(Subscriber,Subscriber.mailman_key == unicode(key,'utf-8')).set(deleted = False)" |
256 | + command = "self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(key.lower(),'utf-8')).set(deleted = False)" |
257 | if DEBUG_MODE: |
258 | syslog('info', 'DlistUtils(subscribeToList):Executing query:\n%s', command) |
259 | - self.store.find(Subscriber,Subscriber.mailman_key == unicode(key,"utf-8")).set(deleted = False) |
260 | + self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(key.lower(),"utf-8")).set(deleted = False) |
261 | + |
262 | + result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(key.lower(),"utf-8")) |
263 | + Email = [(subscriber.mailman_key) for subscriber in result] |
264 | + Email = Email[0] |
265 | + if Email != key: #That is if one was in lowercase and other in uppercase then update mailman_key with case sensitivity same as key |
266 | + self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(key.lower(),"utf-8")).set(mailman_key = unicode(key,"utf-8")) |
267 | + |
268 | else: |
269 | # format is text-only (1) by default |
270 | - command = "subscriber = self.store.add(Subscriber())\nsubscriber.mailman_key = unicode(key,'utf-8')\nsubscriber.preference = 1\nsubscriber.deleted = False\nsubscriber.format = 1\nsubscriber.suppress = 0" |
271 | + command = "subscriber = self.store.add(Subscriber())\nmailman_key = unicode(key,'utf-8')\npreference = 1\ndeleted = False\nformat = 1\nsuppress = 0" |
272 | if DEBUG_MODE: |
273 | syslog('info', 'DlistUtils(subscribeToList)Executing query:\n%s', command) |
274 | self.mailman_key = unicode(key,"utf-8") |
275 | @@ -273,12 +280,12 @@ |
276 | # use the original subscriber id as the ID going forward |
277 | if DEBUG_MODE: |
278 | syslog('info', 'Executing commands of mergeSubscribers:') |
279 | - result = self.store.find(Subscriber,Subscriber.mailman_key == unicode(oldaddr,"utf-8")) |
280 | + result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(oldaddr,"utf-8")) |
281 | new_id = [(subscriber.subscriber_id) for subscriber in result] |
282 | new_id = new_id[0] |
283 | if DEBUG_MODE: |
284 | syslog('info', 'the value of new_id: %s', new_id) |
285 | - result = self.store.find(Subscriber,Subscriber.mailman_key == unicode(newaddr,"utf-8")) |
286 | + result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(newaddr.lower(),"utf-8")) |
287 | obsolete_id = [(subscriber.subscriber_id) for subscriber in result] |
288 | obsolete_id = obsolete_id[0] |
289 | if DEBUG_MODE: |
290 | @@ -291,13 +298,13 @@ |
291 | |
292 | class Message(object): |
293 | __storm_table__ = "message" |
294 | - message_id = Int(primary = True,default = AutoReload) |
295 | + message_id = Int(primary = True, default = AutoReload) |
296 | sender_id = Int() |
297 | - subscriber = Reference(sender_id,Subscriber.subscriber_id) |
298 | + subscriber = Reference(sender_id, Subscriber.subscriber_id) |
299 | subject = Unicode() |
300 | thread_id = Int() |
301 | |
302 | - def __init__(self,mlist): |
303 | + def __init__(self, mlist): |
304 | self.mlist = mlist |
305 | self.database = getConn(mlist) |
306 | |
307 | @@ -314,7 +321,7 @@ |
308 | threadID = -1 |
309 | command = "message = self.store.add(Message())\nmessage.sender_id = senderID\nmessage.thread_id = threadID\nmessage.subject = unicode(subject,'utf-8')\nmessageID = self.store.find(Message).max(Message.message_id)\n" |
310 | if DEBUG_MODE: |
311 | - syslog('info','DlistUtils:(createMessage)executing query:\n%s',command) |
312 | + syslog('info','DlistUtils:(createMessage)executing query:\n%s', command) |
313 | #message_id has autoreload set,its value will be serially updated in database |
314 | self.sender_id = senderID |
315 | self.thread_id = threadID |
316 | @@ -322,19 +329,19 @@ |
317 | self.store.add(self) |
318 | messageID = self.store.find(Message).max(Message.message_id) |
319 | if DEBUG_MODE: |
320 | - syslog('info','Result of query(messageID) is: %s\n',messageID) |
321 | + syslog('info','Result of query(messageID) is: %s\n', messageID) |
322 | return messageID |
323 | |
324 | class Thread(object): |
325 | __storm_table__ = "thread" |
326 | - thread_id = Int(primary = True,default = AutoReload) |
327 | + thread_id = Int(primary = True, default = AutoReload) |
328 | thread_name = Unicode() |
329 | base_message_id = Int() |
330 | - message = Reference(base_message_id,Message.message_id) |
331 | + message = Reference(base_message_id, Message.message_id) |
332 | status = Int(default = 0) |
333 | parent = Int() |
334 | |
335 | - def __init__(self,mlist): |
336 | + def __init__(self, mlist): |
337 | self.mlist = mlist |
338 | self.database = getConn(mlist) |
339 | |
340 | @@ -347,7 +354,7 @@ |
341 | senderID = subscriber.getSubscriber_id(msg, msgdata, safe=1, loose=1) |
342 | command = "thread = self.store.add(Thread())\nthread.base_message_id = msgdata['message_id']\nthreadID = self.store.find(Thread).max(Thread.thread_id)\nself.store.find(Message,Message.message_id == msgdata['message_id']).set(thread_id = threadID)\n" |
343 | if DEBUG_MODE: |
344 | - syslog('info','DlistUtils:(createThread)executing query:\n%s',command) |
345 | + syslog('info','DlistUtils:(createThread)executing query:\n%s', command) |
346 | self.base_message_id = msgdata['message_id'] |
347 | self.store.add(self) |
348 | threadID = self.store.find(Thread).max(Thread.thread_id) |
349 | @@ -370,7 +377,7 @@ |
350 | threadBase = threadBase[:13] |
351 | command = "num = self.store.find(Thread,Thread.thread_name == unicode(threadBase,'utf-8')).count()\nself.store.find(Thread,Thread.thread_id == threadID).set(thread_name = threadName)\n" |
352 | if DEBUG_MODE: |
353 | - syslog('info','DlistUtils:(createThread)executing query:\n%s',command) |
354 | + syslog('info','DlistUtils:(createThread)executing query:\n%s', command) |
355 | # If the threadBase is not unique, make threadBase unique by appending a number |
356 | num = self.store.find(Thread,Thread.thread_name.like(unicode(threadBase + "%","utf-8"))).count() |
357 | if not num: |
358 | @@ -405,26 +412,24 @@ |
359 | msg['To'] = '%s+%s@%s' % (self.mlist.internal_name(), |
360 | name, |
361 | self.mlist.host_name) |
362 | - for i in (1,2): |
363 | + for i in (1, 2): |
364 | # different footers for different prefs, so we need to queue separately |
365 | if(i==1): |
366 | #For condition where preference = True |
367 | pref=True |
368 | - # command = "lists = [(subscriber.mailman_key.encode('utf-8')) for subscriber in result_new_sql]\n" |
369 | - # if DEBUG_MODE: |
370 | - # syslog('info', 'DlistUtils:(newThread)executing query:\n%sfor pref = true\n', command) |
371 | + if DEBUG_MODE: |
372 | + syslog('info', 'DlistUtils:(newThread)executing query:\nfor pref = true\n\n') |
373 | if(i==2): |
374 | #For condition where preference = False |
375 | pref=False |
376 | - # command = "lists = [(subscriber.mailman_key.encode('utf-8')) for subscriber in result_new_sql]\n" |
377 | - # if DEBUG_MODE: |
378 | - # syslog('info', 'DlistUtils:(newThread)executing query:\n%sfor pref = false\n', command) |
379 | + if DEBUG_MODE: |
380 | + syslog('info', 'DlistUtils:(newThread)executing query:\nfor pref = false\n\n') |
381 | |
382 | #Execute a SELECT statement, to find the list of matching subscribers. |
383 | result_new_sql = self.store.find(Subscriber,And(Subscriber.preference == pref,Subscriber.deleted == False,Subscriber.suppress == 0)) |
384 | lists = [(subscriber.mailman_key.encode('utf-8')) for subscriber in result_new_sql] |
385 | if DEBUG_MODE: |
386 | - syslog('info', 'value of lists: %s\n', lists) |
387 | + syslog('info','value of lists: %s\n', lists) |
388 | self.email_recipients(msg, msgdata, lists, pref) |
389 | |
390 | # Make original message go to nobody (but be archived) |
391 | @@ -514,12 +519,12 @@ |
392 | override = Override(self.mlist) |
393 | override.override(msg, msgdata, 0) |
394 | |
395 | - def alphanumericOnly(self,s): |
396 | + def alphanumericOnly(self, s): |
397 | """Filter any non-letter characters from a string""" |
398 | result = [letter for letter in s if letter in string.ascii_letters or letter in string.digits] |
399 | return string.join(result, '') |
400 | |
401 | - def subjectToName(self,subject, threadID): |
402 | + def subjectToName(self, subject, threadID): |
403 | """Return a lower-case name for a new thread based on the subject, if present, or on the threadID""" |
404 | result = None |
405 | |
406 | @@ -589,9 +594,9 @@ |
407 | __storm_table__ = "alias" |
408 | pseudonym = Unicode(primary = True) |
409 | subscriber_id = Int() |
410 | - subscriber = Reference(subscriber_id,Subscriber.subscriber_id) |
411 | + subscriber = Reference(subscriber_id, Subscriber.subscriber_id) |
412 | |
413 | - def __init__(self,mlist): |
414 | + def __init__(self, mlist): |
415 | self.mlist = mlist |
416 | self.database = getConn(mlist) |
417 | |
418 | @@ -604,8 +609,8 @@ |
419 | syslog('info', 'DlistUtils(canonicalize_sender)Executing query:\n%s', command) |
420 | |
421 | for alias in aliases: |
422 | - #if DEBUG_MODE: |
423 | - #syslog('info', 'Checking if <%s> is an alias', alias) |
424 | + if DEBUG_MODE: |
425 | + syslog('info', 'Checking if <%s> is an alias', alias) |
426 | result = self.store.find((Subscriber,Alias),And(Alias.pseudonym == unicode(alias,'utf-8'),Subscriber.subscriber_id == Alias.subscriber_id)) |
427 | lists = [(subscriber.mailman_key.encode('utf-8')) for (subscriber,alias) in result] |
428 | |
429 | @@ -654,12 +659,12 @@ |
430 | __storm_table__ = "override" |
431 | __storm_primary__ = "subscriber_id", "thread_id" |
432 | subscriber_id = Int() |
433 | - subscriber = Reference(subscriber_id,Subscriber.subscriber_id) |
434 | + subscriber = Reference(subscriber_id, Subscriber.subscriber_id) |
435 | thread_id = Int() |
436 | - thread = Reference(thread_id,Thread.thread_id) |
437 | + thread = Reference(thread_id, Thread.thread_id) |
438 | preference = Int() |
439 | |
440 | - def __init__(self,mlist): |
441 | + def __init__(self, mlist): |
442 | self.mlist = mlist |
443 | self.database = getConn(mlist) |
444 | |
445 | @@ -709,10 +714,9 @@ |
446 | |
447 | return 1 |
448 | |
449 | - def overrideURL(self,list_name, host_name, thread_reference, preference): |
450 | + def overrideURL(self, list_name, host_name, thread_reference, preference): |
451 | return 'http://%s/mailman/options/%s?override=%s&preference=%d' % (host_name, list_name, thread_reference, preference) |
452 | |
453 | - |
454 | #Functions Independent of the database tables in DlistUtils |
455 | |
456 | def GetEmailAddresses(mlist, subscribers): |
457 | @@ -752,13 +756,22 @@ |
458 | |
459 | def _create_database(name): |
460 | """Create a database. This requires us to not be in a transaction.""" |
461 | - conn = pgdb.connect(host='localhost', database='postgres',user='mailman', password='mailman') |
462 | + conn = pgdb.connect(host='localhost', database='postgres', user='mailman', password='mailman') |
463 | old_iso_lvl = conn.isolation_level |
464 | conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) |
465 | cursor = conn.cursor() |
466 | cursor.execute('create database "%s"' % name) |
467 | conn.set_isolation_level(old_iso_lvl) |
468 | |
469 | +def _remove_database(name): |
470 | + """Remove a database. This requires us to not be in a transaction.""" |
471 | + conn = pgdb.connect(host='localhost', database='postgres', user='mailman', password='mailman') |
472 | + old_iso_lvl = conn.isolation_level |
473 | + conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) |
474 | + cursor = conn.cursor() |
475 | + cursor.execute('DROP DATABASE "%s"' % name) |
476 | + conn.set_isolation_level(old_iso_lvl) |
477 | + |
478 | def executeSQL(mlist, commands): |
479 | """Execute a sequence of SQL commands that create tables in the database.""" |
480 | database = getConn(mlist) |
481 | @@ -834,3 +847,9 @@ |
482 | mlist.Save() |
483 | if alreadyLocked == 0: |
484 | mlist.Unlock() |
485 | + |
486 | +def remove_dlist(listname): |
487 | + """ Deletes the corresponding postgres database and tables.""" |
488 | + _remove_database(listname) |
489 | + if DEBUG_MODE: |
490 | + syslog('info', "Database %s removed\n", listname) |
491 | |
492 | === modified file 'bin/rmlist' |
493 | --- bin/rmlist 2009-07-31 10:49:01 +0000 |
494 | +++ bin/rmlist 2012-06-27 11:21:20 +0000 |
495 | @@ -152,12 +152,7 @@ |
496 | |
497 | # Remove the database in PostgreSQL if it was a dynamic list. Added by Systers. |
498 | try: |
499 | - conn = DlistUtils.getConn(None) |
500 | - old_iso_lvl = conn.isolation_level |
501 | - conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT) |
502 | - cursor = conn.cursor() |
503 | - cursor.execute('DROP DATABASE "%s"' % listname) |
504 | - conn.set_isolation_level(old_iso_lvl) |
505 | + DlistUtils.remove_dlist(listname) |
506 | except: |
507 | syslog('error', 'Tried to remove the database for %s, no such database (ok if it was a non dlist). If it was a dlist, the postgreSQL database for this list needs to be removed manually.' % listname) |
508 |
A suggestion for the future: when you put in a syslog statement, put in some identifying text, preferably the file that the message came from and what the data is. e.g.,
syslog('info', "listinfo.py: essay question data for question %d = %s", i, mlist.questions [i][i+1] [2])
In listinfo.py
I'm confused by your parameters --can you remind me what the datastructure is for mlist.questions (what the columns are? I don't understand how you can do things with mlist.questions [i][i+1] [0] etc. I think this must have worked "by accident". )
I believe that mailman coding style requires 80 column line lengths. Can you shorten the long lines? (you may need to add some extra parens to make python understand that your new lines are continuation lines).
For things you are planning to do later (even if later is in the indefinite future, please start the comment with:
#TODO (your name):
that way it's easy to grep the code and find things you left for later.
As best I can tell, you didn't actually make any changes to DlistUtils.py. Is that correct? If not, can you point out the places you made changes (it looks like these were the changes to fix our nasty lower case bug; maybe you had to import that file onto your branch?)
Where do you define mlist.questions? (presumably in MailList.py, but why wasn't that included in your merge?) If you just manually created a mailing list with questions, please put that in the description of the change, showing exactly what is in that faked data structure.
Use the description of the change to tell your reviewers the things they need to know to understand this code (like the mlist.questions data structure)