[albatross-users] unscriptable object

Eric S. Johansson esj at harvee.org
Tue Jul 15 00:36:01 EST 2003


Sheila King wrote:

> --On Monday, July 14, 2003 9:35 AM -0400 "Eric S. Johansson" 
> <esj at harvee.org> wrote:
> 
>> Traceback (most recent call last):
>>    File "/usr/lib/python2.2/site-packages/albatross/app.py", line
>> 221, in run      self.merge_request(ctx)
>>    File "/usr/lib/python2.2/site-packages/albatross/app.py", line
>> 301, in  merge_request
>>      ctx.merge_request()
>>    File "/usr/lib/python2.2/site-packages/albatross/context.py",
>> line 306, in  merge_request
>>      self.set_value(name, value)
>>    File "/usr/lib/python2.2/site-packages/albatross/context.py",
>> line 336, in  set_value
>>      if name[0] == '_':
>> TypeError: unsubscriptable object
>>
>>
>>
>> the Q is where and why?  _ is a legal character and used in other
>> places.
> 
> 
> When I have received this error in the past, it is usually because the 
> object was a None type.
> 
> I bet that your name sequence is empty (i.e. None). OK, well that is my 
> guess.

OK, I missing something here.  What name sequence are you talking about?

and as for missing names on form elements, I have all input types named. 
Especially the submit buttons.

FYI, here's the essential form elements and the albatross glue code I used to 
connect to my data extraction code.


<h2>Instructions:</h2>

<p>Red messages strongly suspected to be spam.  Green messages are strongly 
suspected to be not spam.</p>

<p>Your job is: Correct message with wrong classification.</p>


<p>There are only two ways a message can have the wrong classification.  Either:

<ul>
<li>The email <b>is</b> spam, and was classified as good e-mail</li>
<li>Or the email <b>is not</b> spam, and was classified as spam.</li>
<li>If you are not sure, check the message detail by following the subject 
link.</li>
</ul>

In order to change the classification, press the button on the line
labeled "change classification".  Repeat until all messages have been
processed.

</p>

<al-form action="reclaim.cgi" method="post">

<p>
The dumpster contains <b><al-value expr="spamtrap_size"></b>  messages.
</p>

<p>
Sort display by: <al-select name="sort_selection" optionexpr="sort_list"/> 
<al-input type="submit" name="sort_action" value="Change Sort" >
</p>

<p>
go to <al-input type="submit" name="pagedirection"  value="next" > or <al-input 
type="submit" name="pagedirection"  value="previous" > page
</p>

<table width=<al-value expr="page_width">
<tr align=left>
<th width=37>Select</th>
<th width=50 align=right>Score</th>
<th width=50 align=center>To</th>
<th>From</th>
<th>Subject (for detail follow link)
</tr>
<al-for iter="line" expr="display_list">

<tr class=<al-value expr="line.value().style">>
<td  bgcolor="#ffffff" align=center >

<al-if expr="line.value().priority == 3">
<al-exec expr="categorize='was_green'">
<al-else>
<al-exec expr="categorize='was_red'">
</al-if>

<al-input type="submit" nameexp="categorize"  value="change classification" >
<td>
<al-value expr="line.value().truncated_score()">
<al-if expr="line.value().list_type != None">
<br>
<al-value expr="line.value().list_type">
</al-if>
</td>

<td><al-value expr="line.value().destination"></td>
<td><al-value expr="line.value().from_address"></td>
<td><!--- <al-value expr="line.value().token"><br> --->
<al-a 
expr="'spamtrap_display.cgi?repository=dumpster&token='+line.value().token" 
target="spamtrap_display">
<al-value expr="line.value().subject"></al-a></td>
</tr>
</al-for>
</table>
</al-form>
<p>
aaaa
</p>


class correction:
     def page_enter(self, context):

         if not configuration_data['is_global_spamtrap']:
             user =  os.environ["REMOTE_USER"]
         else:
             user = None

         syslog.syslog("page_enter")

         context.locals.screen_buffer = {}
         context.add_session_vars('screen_buffer')

         context.locals.current_line_index = 0
         context.add_session_vars('current_line_index')

         context.locals.spamtrap_size = 0
         context.add_session_vars('spamtrap_size')

         context.locals.sort_item = "Date"
         context.add_session_vars('sort_item')

         context.locals.sort_list = [ 'Date', 'From', 'To', 'Subject' ]

         context.locals.spamtrap_size, context.locals.screen_buffer = 
generate_spamtrap_matrix(user)

         #syslog.syslog("spamtrap_size, screen_buffer %s %s" % 
(context.locals.spamtrap_size, context.locals.screen_buffer))

     def page_process(self, context):

         if not configuration_data['is_global_spamtrap']:
             user =  os.environ["REMOTE_USER"]
         else:
             user = None

         #if context.locals.train:
         #    syslog.syslog("train button pressed")
         syslog.syslog("any? button pressed")
         for entry in context.locals.__dict__:
             syslog.syslog("key %s" % (entry))

	# old code remnant
         if context.req_equals("submitaction"):
             if os.environ["REMOTE_USER"] == "e.johansson" and \
                    os.environ["REMOTE_ADDR"] == "192.168.25.1" or \
                    os.environ["REMOTE_USER"] == "albatross" :
                 context.locals.action_denied= "no-go"
             else:
                 context.locals.action_denied= "go-go"
                 pass

         #if context.req_equals("sort_item"):

     def page_display (self, context):

         context.locals.page_width="100%"
         syslog.syslog("type = %s" % type(context.locals.screen_buffer))
         sort_buffer = []
         for token in context.locals.screen_buffer.keys():
             line = context.locals.screen_buffer[token]

             #syslog.syslog("page_display line == %s" %line)
             if context.locals.sort_item  == "Date":
                 sort_buffer.append(str(line.date)+":"+token)

             elif context.locals.sort_item  == "To":
                 sort_buffer.append(str(line.destination)+":"+token)

             elif context.locals.sort_item  == "From":
                 sort_buffer.append(str(line.from_address)+":"+token)

             elif context.locals.sort_item  == "Subject":
                 sort_buffer.append(str(line.destination)+":"+token)
             else:
                 syslog.syslog("no such item on select list %s" % 
context.locals.sort_item)
                 sort_buffer.append(str(line.date)+":"+token)

         sort_buffer.sort()

         display_limit = 0
         display_list = []
         for index in sort_buffer:
             display_limit = display_limit + 1
             if display_limit > configuration_data['spamtrap_display_lines']:
                 break

             # extract items from screen_buffer according to the sort_buffer
             (junk,token) = index.split(":")

             display_list.append(context.locals.screen_buffer[token])

         # transfer display list of X lines to template variable space
         context.locals.display_list = display_list

         context.run_template("reclaim.html")
         syslog.syslog("emd of display")

app = SimpleApp(base_url = 'reclaim.py',
                 template_path = '.',
                 start_page = 'reclaim',
                 secret = '-=-secret-=-')

app.register_page('reclaim', correction())

app.run(Request())






More information about the Albatross-users mailing list