Merge lp:~acoconut/systers/flexible_essays into lp:systers

Proposed by Ana Cutillas
Status: Superseded
Proposed branch: lp:~acoconut/systers/flexible_essays
Merge into: lp:systers
Diff against target: 521 lines (+108/-81)
3 files modified
Mailman/Cgi/listinfo.py (+19/-6)
Mailman/DlistUtils.py (+88/-69)
bin/rmlist (+1/-6)
To merge this branch: bzr merge lp:~acoconut/systers/flexible_essays
Reviewer Review Type Date Requested Status
beachbrake Pending
Robin J Pending
Review via email: mp+112331@code.launchpad.net

This proposal supersedes a proposal from 2012-06-26.

This proposal has been superseded by a proposal from 2012-06-28.

Description of the change

I changed the data structure to store the current version of questions. Now it looks like this:

[ ['talk about yourself', 'talk', 'largebox', 300, 'top'], ['Are you a woman?', 'woman', 'checkbox', 0, 'bottom'] ]

And then changed the code to loop through this information.

To post a comment you must log in.
Revision history for this message
Robin J (robin-jeffries) wrote : Posted in a previous version of this proposal

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)

review: Needs Fixing
Revision history for this message
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[i][i+1][2])
>

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[i][i+1][0] etc. I think this must have
> 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://code.launchpad.net/~acoconut/systers/flexible_essays/+merge/111405
> You are the owner of lp:~acoconut/systers/flexible_essays.
>

Revision history for this message
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[i][i+1][2]

the first time through that is mlist.questions[0][1][2] (in line 15 in the diff) -- that would be 'talk' above.)

The next time through it is mlist.questions[1][2][2] -- which doesn't exist, right? shouldn't your test (and other items) be mlist.questions[i][1][2]?

(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.

Revision history for this message
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[i][i+1][2]
>
> the first time through that is mlist.questions[0][1][2] (in line 15 in
> the diff) -- that would be 'talk' above.)
>
> The next time through it is mlist.questions[1][2][2] -- which doesn't
> exist, right? shouldn't your test (and other items) be
> mlist.questions[i][1][2]?
>
> (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://code.launchpad.net/~acoconut/systers/flexible_essays/+merge/111405
> You are the owner of lp:~acoconut/systers/flexible_essays.
>

Revision history for this message
Ana Cutillas (acoconut) wrote : Posted in a previous version of this proposal
Download full text (29.7 KiB)

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://code.launchpad.net/~acoconut/systers/flexible_essays/+merge/112178
>
> 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://code.launchpad.net/~acoconut/systers/flexible_essays/+merge/112178
> You are the owner of lp:~acoconut/systers/flexible_essays.
>
> === modified file 'Mailman/Cgi/listinfo.py'
> --- Mailman/Cgi/listinfo.py 2009-08-14 15:41:17 +0000
> +++ Mailman/Cgi/listinfo.py 2012-06-26 17:45:29 +0000
> @@ -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_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
>
>
> -
> def main():
> parts = Utils.GetPathPieces()
> if not parts:
> @@ -62,7 +62,6 @@
> list_listinfo(mlist, language)
>
>
> -
> def listinfo_overview(msg=''):
> # Present the general listinfo overview
> hostname = Utils.get_domain()
> @@ -152,7 +151,6 @@
> print doc.Format()
>
>
> -
> def list_listinfo(mlist, lang):
> # 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_enabled:
> - replacements['<mm-questions>'] = """<TR>
> - <TD COLSPAN="3">""" + mlist.questions
> - replacements['<mm-essay-box>'] = TextArea('essay', '',
> 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.append("""<TR>
> + <TD COLSPAN="3">""" + question[index][0] + """</TD>""")
> + if (question[index][2] == 'smallbox'):
> + questions.append("""<TD>""" +
> TextArea(question[index][1],\
> + '', rows=1, cols=60).Format() +
> """</TD></TR>""")
> + elif (question[index][2] == 'largebox'):
> + questions.append("""<TD>""" +
> TextArea(question[index][1], \
> + '', rows=8, cols=60).Format() +
> """</TD></TR>""")
> + elif (question[index][2] == 'checkbox'):
> + #TODO (Ana Cutillas): consider creating a class like
> TextArea for checkboxes?
> + questions.append("""<TD><input type='checkbox'
> name='""" + \
> + question[index][1] + """' value ='""" + \
> + ...

Revision history for this message
Robin J (robin-jeffries) wrote : Posted in a previous version of this proposal
Download full text (3.2 KiB)

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[i][i+1][2]
> >
> > the first time through that is mlist.questions[0][1][2] (in line 15 in
> > the diff) -- that would be 'talk' above.)
> >
> > The next time through it is mlist.questions[1][2][2] -- which doesn't
> > exist, right? shouldn't your test (and other items) be
> > mlist.questions[i][1][2]?
> >
> > (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://code.launchpad.net/~acoconut/systers/flexible_essays/+merge/111405
> > You are the owner of lp:~acoconut/systers/flexible_essays.
> >
>
> --
> https://code.launchpad.net/~acoconut/systers/flexible_essays/+merge/111405
> You are reviewing the pro...

Read more...

Revision history for this message
Robin J (robin-jeffries) wrote : Posted in a previous version of this proposal
Download full text (32.0 KiB)

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://code.launchpad.net/~acoconut/systers/flexible_essays/+merge/112178
>>
>> 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://code.launchpad.net/~acoconut/systers/flexible_essays/+merge/112178
>> You are the owner of lp:~acoconut/systers/flexible_essays.
>>
>> === modified file 'Mailman/Cgi/listinfo.py'
>> --- Mailman/Cgi/listinfo.py 2009-08-14 15:41:17 +0000
>> +++ Mailman/Cgi/listinfo.py 2012-06-26 17:45:29 +0000
>> @@ -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_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
>>
>>
>> -
>> def main():
>> parts = Utils.GetPathPieces()
>> if not parts:
>> @@ -62,7 +62,6 @@
>> list_listinfo(mlist, language)
>>
>>
>> -
>> def listinfo_overview(msg=''):
>> # Present the general listinfo overview
>> hostname = Utils.get_domain()
>> @@ -152,7 +151,6 @@
>> print doc.Format()
>>
>>
>> -
>> def list_listinfo(mlist, lang):
>> # 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_enabled:
>> - replacements['<mm-questions>'] = """<TR>
>> - <TD COLSPAN="3">""" + mlist.questions
>> - replacements['<mm-essay-box>'] = TextArea('essay', '',
>> 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...

Revision history for this message
Ana Cutillas (acoconut) wrote : Posted in a previous version of this proposal
Download full text (34.4 KiB)

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://code.launchpad.net/~acoconut/systers/flexible_essays/+merge/112178
> >>
> >> 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://code.launchpad.net/~acoconut/systers/flexible_essays/+merge/112178
> >> You are the owner of lp:~acoconut/systers/flexible_essays.
> >>
> >> === modified file 'Mailman/Cgi/listinfo.py'
> >> --- Mailman/Cgi/listinfo.py 2009-08-14 15:41:17 +0000
> >> +++ Mailman/Cgi/listinfo.py 2012-06-26 17:45:29 +0000
> >> @@ -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_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
> >>
> >>
> >> -
> >> def main():
> >> parts = Utils.GetPathPieces()
> >> if not parts:
> >> @@ -62,7 +62,6 @@
> >> list_listinfo(mlist, language)
> >>
> >>
> >> -
> >> def listinfo_overview(msg=''):
> >> # Present the general listinfo overview
> >> hostname = Utils.get_domain()
> >> @@ -152,7 +151,6 @@
> >> print doc.Format()
> >>
> >>
> >> -
> >> def list_listinfo(mlist, lang):
> >> # 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_enabled:
> >> - replacements['<mm-questions>'] = """<TR>
> >> - ...

Revision history for this message
Robin J (robin-jeffries) wrote :

OK, we are definitely making progress. Some questions and one change request:
   - what do fields 3 and 4 mean in your data structure (0, and 'bottom' for the checkbox?)
   - I'm not sure what you are doing for the checkbox (because I don't really understand that html). The part that confuses me is that you are using question[1] there twice. One part I think you are naming the checkbox, but why the second time? It seems to also be the value?

My requested change is that questions is too similar to mlist.questions. I think the code will be much easier for someone else to read if you change that to something like html_questions

Revision history for this message
Ana Cutillas (acoconut) wrote :

On Thu, Jun 28, 2012 at 6:51 AM, Robin J <email address hidden> wrote:

> OK, we are definitely making progress. Some questions and one change
> request:
> - what do fields 3 and 4 mean in your data structure (0, and 'bottom'
> for the checkbox?)
>

I am not really doing anything with them yet. They are there for when I
start adding options to make the forms beautiful and let the admin move the
boxes around. Field 3 is the size of the box, a checkbox would look the
same with size 3000 or 0, so we can leave it to 0. Field 4 is the relative
position, I haven't really given it a lot of thought yet, I am currently
printing them in the order they appear in the list. Do you think it would
be better if I took those fields out of the data structure for now if I'm
not using them yet?

  - I'm not sure what you are doing for the checkbox (because I don't
> really understand that html). The part that confuses me is that you are
> using question[1] there twice. One part I think you are naming the
> checkbox, but why the second time? It seems to also be the value?
>
> According to what I read on the internet, there are two fields in the html
syntax to add checkboxes: name and value. Name is just the name of the
checkbox, and value is the value that is submitted if the checkbox is
checked. That's why I'm using the same string for both.

So the HTML code for a checkbox would look like this:

<TD><input type='checkbox' name='woman' value='woman'></TD>

> My requested change is that questions is too similar to mlist.questions.
> I think the code will be much easier for someone else to read if you
> change that to something like html_questions
>

Ok, changed! Let me know what you think about the extra 3 and 4 fields so I
can either change that or resubmit this again.

> --
> https://code.launchpad.net/~acoconut/systers/flexible_essays/+merge/112331
> You are the owner of lp:~acoconut/systers/flexible_essays.
>

Revision history for this message
Robin J (robin-jeffries) wrote :

On Thu, Jun 28, 2012 at 3:41 AM, Ana Cutillas <email address hidden> wrote:

> On Thu, Jun 28, 2012 at 6:51 AM, Robin J <email address hidden> wrote:
>
> > OK, we are definitely making progress. Some questions and one change
> > request:
> > - what do fields 3 and 4 mean in your data structure (0, and 'bottom'
> > for the checkbox?)
> >
>
> I am not really doing anything with them yet. They are there for when I
> start adding options to make the forms beautiful and let the admin move the
> boxes around. Field 3 is the size of the box, a checkbox would look the
> same with size 3000 or 0, so we can leave it to 0. Field 4 is the relative
> position, I haven't really given it a lot of thought yet, I am currently
> printing them in the order they appear in the list. Do you think it would
> be better if I took those fields out of the data structure for now if I'm
> not using them yet?
>

No, feel free to keep them, since it doesn't change the way you interact
with the rest of the data structure. My guess is that you may need to
change some of them (probably a relative position than an absolute one),
but that can happen later.

>
> - I'm not sure what you are doing for the checkbox (because I don't
> > really understand that html). The part that confuses me is that you are
> > using question[1] there twice. One part I think you are naming the
> > checkbox, but why the second time? It seems to also be the value?
> >
> > According to what I read on the internet, there are two fields in the
> html
> syntax to add checkboxes: name and value. Name is just the name of the
> checkbox, and value is the value that is submitted if the checkbox is
> checked. That's why I'm using the same string for both.
>
> So the HTML code for a checkbox would look like this:
>
> <TD><input type='checkbox' name='woman' value='woman'></TD>
>

OK, get it now. I can't see any harm in using the same value for both of
them, but you might keep this in mind if you run into a bug -- that the
wrong field maybe is being addressed.

>
> > My requested change is that questions is too similar to mlist.questions.
> > I think the code will be much easier for someone else to read if you
> > change that to something like html_questions
> >
>
> Ok, changed! Let me know what you think about the extra 3 and 4 fields so I
> can either change that or resubmit this again.
>
> Go for it.

>
> > --
> >
> https://code.launchpad.net/~acoconut/systers/flexible_essays/+merge/112331
> > You are the owner of lp:~acoconut/systers/flexible_essays.
> >
>
> --
> https://code.launchpad.net/~acoconut/systers/flexible_essays/+merge/112331
> You are requested to review the proposed merge of
> lp:~acoconut/systers/flexible_essays into lp:systers.
>

lp:~acoconut/systers/flexible_essays updated
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

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
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-28 22:40:23 +0000
4@@ -22,6 +22,7 @@
5 import os
6 import cgi
7
8+from Mailman import DlistUtils
9 from Mailman import mm_cfg
10 from Mailman import Utils
11 from Mailman import MailList
12@@ -36,7 +37,6 @@
13 i18n.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
14
15
16-
17
18 def main():
19 parts = Utils.GetPathPieces()
20 if not parts:
21@@ -53,6 +53,8 @@
22 syslog('error', 'No such list "%s": %s', listname, e)
23 return
24
25+ ##acoconut formquestion = DlistUtils.FormQuestion(mlist)
26+ ##acoconut formquestion.recordAnswer("coconut@coconut.net", 1, "yes, i am", 1)
27 # See if the user want to see this page in other language
28 cgidata = cgi.FieldStorage()
29 language = cgidata.getvalue('language')
30@@ -62,7 +64,6 @@
31 list_listinfo(mlist, language)
32
33
34-
35
36 def listinfo_overview(msg=''):
37 # Present the general listinfo overview
38 hostname = Utils.get_domain()
39@@ -152,7 +153,6 @@
40 print doc.Format()
41
42
43-
44
45 def list_listinfo(mlist, lang):
46 # Generate list specific listinfo
47 doc = HeadlessDocument()
48@@ -190,9 +190,22 @@
49 # If activated, the content and presence of questions and a field to answer them. Added by Systers.
50 try:
51 if mlist.essay_enabled:
52- replacements['<mm-questions>'] = """<TR>
53- <TD COLSPAN="3">""" + mlist.questions
54- replacements['<mm-essay-box>'] = TextArea('essay', '', rows=8, cols=60).Format() + """ </TD></TR>"""# Added to support subscribe essays
55+ html_questions = [] # Added to support subscribe essays
56+ for question in mlist.questions:
57+ html_questions.append("""<TR>
58+ <TD COLSPAN="3">""" + question[0] + """</TD>""")
59+ if (question[2] == 'smallbox'):
60+ html_questions.append("""<TD>""" + TextArea(question[1],\
61+ '', rows=1, cols=60).Format() + """</TD></TR>""")
62+ elif (question[2] == 'largebox'):
63+ html_questions.append("""<TD>""" + TextArea(question[1], \
64+ '', rows=8, cols=60).Format() + """</TD></TR>""")
65+ elif (question[2] == 'checkbox'):
66+ #TODO (Ana Cutillas): consider creating a class like TextArea for checkboxes?
67+ html_questions.append("""<TD><input type='checkbox' name='""" + \
68+ question[1] + """' value ='""" + \
69+ question[1] + """'></TD></TR>""")
70+ replacements['<mm-questions>'] = ''.join(html_questions)
71 else:
72 replacements['<mm-questions>'] = ''
73 replacements['<mm-essay-box>'] = ''
74
75=== modified file 'Mailman/DlistUtils.py'
76--- Mailman/DlistUtils.py 2010-01-31 20:29:48 +0000
77+++ Mailman/DlistUtils.py 2012-06-28 22:40:23 +0000
78@@ -40,17 +40,17 @@
79 if self == classObject:
80 if self.store == None:#for the case when same object is used for calling more than one functions
81 self.store = Store(self.database)
82- result = f(self,*args)
83+ result = f(self, *args)
84 self.store.commit()
85 self.store.close()
86 self.store = None
87 else:#To handle the nesting issue
88- result = f(self,*args)
89+ result = f(self, *args)
90 self.store.commit()
91 else:#for the case whenever a new object calls its decorated member function
92 classObject = self
93 self.store = Store(self.database)
94- result = f(self,*args)
95+ result = f(self, *args)
96 self.store.commit()
97 self.store.close()
98 self.store = None
99@@ -60,14 +60,14 @@
100 #Define all the classes corresponding to the tables in the database
101 class Subscriber(object):
102 __storm_table__ = "subscriber"
103- subscriber_id = Int(primary = True,default = AutoReload)
104+ subscriber_id = Int(primary = True, default = AutoReload)
105 mailman_key = Unicode()
106 preference = Int(default = 1)
107 format = Int(default = 3)
108 deleted = Bool(default = False)
109 suppress = Int(default = 0)
110
111- def __init__(self,mlist):
112+ def __init__(self, mlist):
113 self.mlist = mlist
114 self.database = getConn(mlist)
115
116@@ -76,11 +76,11 @@
117 if addr == None:
118 return None
119
120- command = "result = self.store.find(Subscriber,Subscriber.mailman_key == unicode(addr.lower(),'utf-8'))\na = [(subscriber.subscriber_id) for subscriber in result]\n"
121+ command = "result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(addr.lower(),'utf-8'))\na = [(subscriber.subscriber_id) for subscriber in result]\n"
122 if DEBUG_MODE:
123 syslog('info', "DlistUtils:(getSubscriber_id_raw)executing query:\n%s", command)
124 #storm recognizes unicode only
125- result = self.store.find(Subscriber,Subscriber.mailman_key == unicode(addr.lower(),"utf-8"))
126+ result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(addr,"utf-8"))
127 a = [(subscriber.subscriber_id) for subscriber in result]
128 if DEBUG_MODE:
129 syslog('info', 'value of a is: %s\n', a)
130@@ -136,70 +136,70 @@
131 @decfunc
132 def setDisable(self, member, flag):
133 """Disable/enable delivery based on mm_cfg.DisableDelivery"""
134- command = "result = self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,'utf-8'))\noldval = [(subscriber.suppress) for subscriber in result]\n"
135+ command = "result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,'utf-8'))\noldval = [(subscriber.suppress) for subscriber in result]\n"
136 if DEBUG_MODE:
137- syslog('info', 'DlistUtils(setDisable):Executing query:\n%s\n Member whoes suppress value is to be found \n %s', command,member)
138- result = self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,"utf-8"))
139+ syslog('info', 'DlistUtils(setDisable):Executing query:\n%s\n Member whose suppress value is to be found \n %s', command, member)
140+ result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,"utf-8"))
141 oldval = [(subscriber.suppress) for subscriber in result]
142 if oldval == []:
143 if DEBUG_MODE:
144 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)')
145 oldval = oldval[0]
146 if DEBUG_MODE:
147- syslog('info','the value of oldval is %s:',oldval)
148+ syslog('info','the value of oldval is %s:', oldval)
149
150 if flag:
151 newval = oldval | 1 # Disable delivery
152 else:
153 newval = oldval & ~1 # Enable delivery
154 if DEBUG_MODE:
155- syslog('info','the value of newval is %s:',newval)
156- command = "self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,'utf-8')).set(suppress = newval)\n"
157+ syslog('info','the value of newval is %s:', newval)
158+ command = "self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,'utf-8')).set(suppress = newval)\n"
159 if DEBUG_MODE:
160 syslog('info', 'DlistUtils(setDisable):Executing query:\n%s', command)
161- self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,"utf-8")).set(suppress = newval)
162+ self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,"utf-8")).set(suppress = newval)
163
164 @decfunc
165 def setDigest(self, member, flag):
166 """Disable/enable delivery based on user digest status"""
167
168- command = "result = self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,'utf-8'))\noldval = [(subscriber.suppress) for subscriber in result]\n"
169+ command = "result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,'utf-8'))\noldval = [(subscriber.suppress) for subscriber in result]\n"
170 if DEBUG_MODE:
171 syslog('info', 'DlistUtils(setDigest):Executing query:\n%s', command)
172- result = self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,"utf-8"))
173+ result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,"utf-8"))
174 oldval = [(subscriber.suppress) for subscriber in result]
175 if oldval == []:
176 if DEBUG_MODE:
177 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)')
178 oldval = oldval[0]
179 if DEBUG_MODE:
180- syslog('info','value of oldval %s:',oldval)
181+ syslog('info','value of oldval %s:', oldval)
182
183 if flag:
184 newval = oldval | 2 # Suppress delivery (in favor of digests)
185 else:
186 newval = oldval & ~2 # Enable delivery (instead of digests)
187
188- command = "self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,'utf-8')).set(suppress = newval)\n"
189+ command = "self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,'utf-8')).set(suppress = newval)\n"
190 if DEBUG_MODE:
191 syslog('info', 'DlistUtils(setDigest):Executing query:\n%s', command)
192- self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,"utf-8")).set(suppress = newval)
193+ self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,"utf-8")).set(suppress = newval)
194
195 @decfunc
196 def changePreference(self, member, preference):
197 """Change a user's default preference for new threads."""
198- command = "self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,'utf-8')).set(preference = preference)\n"
199+ command = "self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,'utf-8')).set(preference = preference)\n"
200 if DEBUG_MODE:
201 syslog('info', 'DlistUtils(changePreference):Executing query:\n%s', command)
202- self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,"utf-8")).set(preference = preference)
203+ self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,"utf-8")).set(preference = preference)
204
205 @decfunc
206 def changeFormat(self, member, format):
207 """Change a user's preferred delivery format (plain text and/or html)"""
208- command = "self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,'utf-8')).set(format = format)\n"
209+ command = "self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,'utf-8')).set(format = format)\n"
210 if DEBUG_MODE:
211 syslog('info', 'DlistUtils(changeFormat):Executing query:\n%s', command)
212- self.store.find(Subscriber,Subscriber.mailman_key == unicode(member,"utf-8")).set(format = format)
213+ self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(member,"utf-8")).set(format = format)
214
215 ### We have to watch out for a tricky case (that actually happened):
216 ### User foo@bar.com changes her address to something already in the
217@@ -207,32 +207,32 @@
218 @decfunc
219 def changeAddress(self, oldaddr, newaddr):
220 """Change email address in SQL database"""
221- #if DEBUG_MODE:
222- #syslog('info', "Changing email address on %s from '%s' to '%s'", self.mlist.internal_name(), oldaddr, newaddr)
223+ if DEBUG_MODE:
224+ syslog('info', "Changing email address on %s from '%s' to '%s'", self.mlist.internal_name(), oldaddr, newaddr)
225 ## Check if newaddr is in sql database
226- num_matches = self.store.find(Subscriber,Subscriber.mailman_key == unicode(newaddr,"utf-8")).count()
227+ num_matches = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(newaddr.lower(),"utf-8")).count()
228
229 if num_matches > 1:
230- #syslog('error', 'Multiple users with same key (%s): %s', self.mlist.internal_name(), newaddr)
231+ syslog('error', 'Multiple users with same key (%s): %s', self.mlist.internal_name(), newaddr)
232 return
233 if num_matches == 1:
234 self.mergeSubscribers(oldaddr, newaddr)
235
236- 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"
237+ 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"
238 if DEBUG_MODE:
239 syslog('info', 'DlistUtils(changeAddress):Executing query:\n%s', command)
240- self.store.find(Subscriber,Subscriber.mailman_key == unicode(oldaddr,"utf-8")).set(mailman_key = unicode(newaddr,"utf-8"))
241+ self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(oldaddr,"utf-8")).set(mailman_key = unicode(newaddr,"utf-8"))
242 self.store.commit()
243- self.store.find(Subscriber,Subscriber.mailman_key == unicode(newaddr,"utf-8")).set(deleted = False)
244+ self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(newaddr.lower(),"utf-8")).set(deleted = False)
245
246 @decfunc
247 def unsubscribeFromList(self, key):
248 """Indicate that a user has unsubscribed by setting the deleted flag in the subscriber table."""
249
250- 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"
251+ 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"
252 if DEBUG_MODE:
253 syslog('info', 'DlisUtils(unsubscribeFromList):Executing query:\n%s', command)
254- self.store.find(Subscriber,Subscriber.mailman_key == unicode(key,"utf-8")).set(deleted = True)
255+ self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(key,"utf-8")).set(deleted = True)
256 # get the subscriber id from the mailman_key & delete all aliases
257 subscriber_id = self.getSubscriber_id_raw(key)
258
259@@ -245,20 +245,27 @@
260 def subscribeToList(self, key):
261 """Add a member to the subscriber database, or change the record from deleted if it was already present."""
262
263- command = "count = (self.store.find(Subscriber,Subscriber.mailman_key == unicode(key,'utf-8'))).count()\n"
264+ command = "count = (self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(key.lower(),'utf-8'))).count()\n"
265 if DEBUG_MODE:
266 syslog('info', 'DlistUtils(subscribeToList):Executing query:\n%s', command)
267 # First see if member is subscribed with deleted field = false
268- count = (self.store.find(Subscriber,Subscriber.mailman_key == unicode(key,"utf-8"))).count()
269+ count = (self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(key.lower(),"utf-8"))).count()
270
271 if count:
272- command = "self.store.find(Subscriber,Subscriber.mailman_key == unicode(key,'utf-8')).set(deleted = False)"
273+ command = "self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(key.lower(),'utf-8')).set(deleted = False)"
274 if DEBUG_MODE:
275 syslog('info', 'DlistUtils(subscribeToList):Executing query:\n%s', command)
276- self.store.find(Subscriber,Subscriber.mailman_key == unicode(key,"utf-8")).set(deleted = False)
277+ self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(key.lower(),"utf-8")).set(deleted = False)
278+
279+ result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(key.lower(),"utf-8"))
280+ Email = [(subscriber.mailman_key) for subscriber in result]
281+ Email = Email[0]
282+ if Email != key: #That is if one was in lowercase and other in uppercase then update mailman_key with case sensitivity same as key
283+ self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(key.lower(),"utf-8")).set(mailman_key = unicode(key,"utf-8"))
284+
285 else:
286 # format is text-only (1) by default
287- 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"
288+ command = "subscriber = self.store.add(Subscriber())\nmailman_key = unicode(key,'utf-8')\npreference = 1\ndeleted = False\nformat = 1\nsuppress = 0"
289 if DEBUG_MODE:
290 syslog('info', 'DlistUtils(subscribeToList)Executing query:\n%s', command)
291 self.mailman_key = unicode(key,"utf-8")
292@@ -273,12 +280,12 @@
293 # use the original subscriber id as the ID going forward
294 if DEBUG_MODE:
295 syslog('info', 'Executing commands of mergeSubscribers:')
296- result = self.store.find(Subscriber,Subscriber.mailman_key == unicode(oldaddr,"utf-8"))
297+ result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(oldaddr,"utf-8"))
298 new_id = [(subscriber.subscriber_id) for subscriber in result]
299 new_id = new_id[0]
300 if DEBUG_MODE:
301 syslog('info', 'the value of new_id: %s', new_id)
302- result = self.store.find(Subscriber,Subscriber.mailman_key == unicode(newaddr,"utf-8"))
303+ result = self.store.find(Subscriber,Subscriber.mailman_key.lower() == unicode(newaddr.lower(),"utf-8"))
304 obsolete_id = [(subscriber.subscriber_id) for subscriber in result]
305 obsolete_id = obsolete_id[0]
306 if DEBUG_MODE:
307@@ -291,13 +298,13 @@
308
309 class Message(object):
310 __storm_table__ = "message"
311- message_id = Int(primary = True,default = AutoReload)
312+ message_id = Int(primary = True, default = AutoReload)
313 sender_id = Int()
314- subscriber = Reference(sender_id,Subscriber.subscriber_id)
315+ subscriber = Reference(sender_id, Subscriber.subscriber_id)
316 subject = Unicode()
317 thread_id = Int()
318
319- def __init__(self,mlist):
320+ def __init__(self, mlist):
321 self.mlist = mlist
322 self.database = getConn(mlist)
323
324@@ -314,7 +321,7 @@
325 threadID = -1
326 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"
327 if DEBUG_MODE:
328- syslog('info','DlistUtils:(createMessage)executing query:\n%s',command)
329+ syslog('info','DlistUtils:(createMessage)executing query:\n%s', command)
330 #message_id has autoreload set,its value will be serially updated in database
331 self.sender_id = senderID
332 self.thread_id = threadID
333@@ -322,19 +329,19 @@
334 self.store.add(self)
335 messageID = self.store.find(Message).max(Message.message_id)
336 if DEBUG_MODE:
337- syslog('info','Result of query(messageID) is: %s\n',messageID)
338+ syslog('info','Result of query(messageID) is: %s\n', messageID)
339 return messageID
340
341 class Thread(object):
342 __storm_table__ = "thread"
343- thread_id = Int(primary = True,default = AutoReload)
344+ thread_id = Int(primary = True, default = AutoReload)
345 thread_name = Unicode()
346 base_message_id = Int()
347- message = Reference(base_message_id,Message.message_id)
348+ message = Reference(base_message_id, Message.message_id)
349 status = Int(default = 0)
350 parent = Int()
351
352- def __init__(self,mlist):
353+ def __init__(self, mlist):
354 self.mlist = mlist
355 self.database = getConn(mlist)
356
357@@ -347,7 +354,7 @@
358 senderID = subscriber.getSubscriber_id(msg, msgdata, safe=1, loose=1)
359 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"
360 if DEBUG_MODE:
361- syslog('info','DlistUtils:(createThread)executing query:\n%s',command)
362+ syslog('info','DlistUtils:(createThread)executing query:\n%s', command)
363 self.base_message_id = msgdata['message_id']
364 self.store.add(self)
365 threadID = self.store.find(Thread).max(Thread.thread_id)
366@@ -370,7 +377,7 @@
367 threadBase = threadBase[:13]
368 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"
369 if DEBUG_MODE:
370- syslog('info','DlistUtils:(createThread)executing query:\n%s',command)
371+ syslog('info','DlistUtils:(createThread)executing query:\n%s', command)
372 # If the threadBase is not unique, make threadBase unique by appending a number
373 num = self.store.find(Thread,Thread.thread_name.like(unicode(threadBase + "%","utf-8"))).count()
374 if not num:
375@@ -405,26 +412,24 @@
376 msg['To'] = '%s+%s@%s' % (self.mlist.internal_name(),
377 name,
378 self.mlist.host_name)
379- for i in (1,2):
380+ for i in (1, 2):
381 # different footers for different prefs, so we need to queue separately
382 if(i==1):
383 #For condition where preference = True
384 pref=True
385- # command = "lists = [(subscriber.mailman_key.encode('utf-8')) for subscriber in result_new_sql]\n"
386- # if DEBUG_MODE:
387- # syslog('info', 'DlistUtils:(newThread)executing query:\n%sfor pref = true\n', command)
388+ if DEBUG_MODE:
389+ syslog('info', 'DlistUtils:(newThread)executing query:\nfor pref = true\n\n')
390 if(i==2):
391 #For condition where preference = False
392 pref=False
393- # command = "lists = [(subscriber.mailman_key.encode('utf-8')) for subscriber in result_new_sql]\n"
394- # if DEBUG_MODE:
395- # syslog('info', 'DlistUtils:(newThread)executing query:\n%sfor pref = false\n', command)
396+ if DEBUG_MODE:
397+ syslog('info', 'DlistUtils:(newThread)executing query:\nfor pref = false\n\n')
398
399 #Execute a SELECT statement, to find the list of matching subscribers.
400 result_new_sql = self.store.find(Subscriber,And(Subscriber.preference == pref,Subscriber.deleted == False,Subscriber.suppress == 0))
401 lists = [(subscriber.mailman_key.encode('utf-8')) for subscriber in result_new_sql]
402 if DEBUG_MODE:
403- syslog('info', 'value of lists: %s\n', lists)
404+ syslog('info','value of lists: %s\n', lists)
405 self.email_recipients(msg, msgdata, lists, pref)
406
407 # Make original message go to nobody (but be archived)
408@@ -514,12 +519,12 @@
409 override = Override(self.mlist)
410 override.override(msg, msgdata, 0)
411
412- def alphanumericOnly(self,s):
413+ def alphanumericOnly(self, s):
414 """Filter any non-letter characters from a string"""
415 result = [letter for letter in s if letter in string.ascii_letters or letter in string.digits]
416 return string.join(result, '')
417
418- def subjectToName(self,subject, threadID):
419+ def subjectToName(self, subject, threadID):
420 """Return a lower-case name for a new thread based on the subject, if present, or on the threadID"""
421 result = None
422
423@@ -589,9 +594,9 @@
424 __storm_table__ = "alias"
425 pseudonym = Unicode(primary = True)
426 subscriber_id = Int()
427- subscriber = Reference(subscriber_id,Subscriber.subscriber_id)
428+ subscriber = Reference(subscriber_id, Subscriber.subscriber_id)
429
430- def __init__(self,mlist):
431+ def __init__(self, mlist):
432 self.mlist = mlist
433 self.database = getConn(mlist)
434
435@@ -604,8 +609,8 @@
436 syslog('info', 'DlistUtils(canonicalize_sender)Executing query:\n%s', command)
437
438 for alias in aliases:
439- #if DEBUG_MODE:
440- #syslog('info', 'Checking if <%s> is an alias', alias)
441+ if DEBUG_MODE:
442+ syslog('info', 'Checking if <%s> is an alias', alias)
443 result = self.store.find((Subscriber,Alias),And(Alias.pseudonym == unicode(alias,'utf-8'),Subscriber.subscriber_id == Alias.subscriber_id))
444 lists = [(subscriber.mailman_key.encode('utf-8')) for (subscriber,alias) in result]
445
446@@ -654,12 +659,12 @@
447 __storm_table__ = "override"
448 __storm_primary__ = "subscriber_id", "thread_id"
449 subscriber_id = Int()
450- subscriber = Reference(subscriber_id,Subscriber.subscriber_id)
451+ subscriber = Reference(subscriber_id, Subscriber.subscriber_id)
452 thread_id = Int()
453- thread = Reference(thread_id,Thread.thread_id)
454+ thread = Reference(thread_id, Thread.thread_id)
455 preference = Int()
456
457- def __init__(self,mlist):
458+ def __init__(self, mlist):
459 self.mlist = mlist
460 self.database = getConn(mlist)
461
462@@ -709,10 +714,9 @@
463
464 return 1
465
466- def overrideURL(self,list_name, host_name, thread_reference, preference):
467+ def overrideURL(self, list_name, host_name, thread_reference, preference):
468 return 'http://%s/mailman/options/%s?override=%s&preference=%d' % (host_name, list_name, thread_reference, preference)
469
470-
471 #Functions Independent of the database tables in DlistUtils
472
473 def GetEmailAddresses(mlist, subscribers):
474@@ -752,13 +756,22 @@
475
476 def _create_database(name):
477 """Create a database. This requires us to not be in a transaction."""
478- conn = pgdb.connect(host='localhost', database='postgres',user='mailman', password='mailman')
479+ conn = pgdb.connect(host='localhost', database='postgres', user='mailman', password='mailman')
480 old_iso_lvl = conn.isolation_level
481 conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
482 cursor = conn.cursor()
483 cursor.execute('create database "%s"' % name)
484 conn.set_isolation_level(old_iso_lvl)
485
486+def _remove_database(name):
487+ """Remove a database. This requires us to not be in a transaction."""
488+ conn = pgdb.connect(host='localhost', database='postgres', user='mailman', password='mailman')
489+ old_iso_lvl = conn.isolation_level
490+ conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
491+ cursor = conn.cursor()
492+ cursor.execute('DROP DATABASE "%s"' % name)
493+ conn.set_isolation_level(old_iso_lvl)
494+
495 def executeSQL(mlist, commands):
496 """Execute a sequence of SQL commands that create tables in the database."""
497 database = getConn(mlist)
498@@ -834,3 +847,9 @@
499 mlist.Save()
500 if alreadyLocked == 0:
501 mlist.Unlock()
502+
503+def remove_dlist(listname):
504+ """ Deletes the corresponding postgres database and tables."""
505+ _remove_database(listname)
506+ if DEBUG_MODE:
507+ syslog('info', "Database %s removed\n", listname)
508
509=== modified file 'bin/rmlist'
510--- bin/rmlist 2009-07-31 10:49:01 +0000
511+++ bin/rmlist 2012-06-28 22:40:23 +0000
512@@ -152,12 +152,7 @@
513
514 # Remove the database in PostgreSQL if it was a dynamic list. Added by Systers.
515 try:
516- conn = DlistUtils.getConn(None)
517- old_iso_lvl = conn.isolation_level
518- conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
519- cursor = conn.cursor()
520- cursor.execute('DROP DATABASE "%s"' % listname)
521- conn.set_isolation_level(old_iso_lvl)
522+ DlistUtils.remove_dlist(listname)
523 except:
524 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)
525

Subscribers

People subscribed via source and target branches