Exemplo n.º 1
0
    def post(self, menu_identifier=None):
            
        if menu_identifier is None or not Menu.isRightIdentifier(menu_identifier):
            self.siteError( SiteErrorType.ERROR_MENU_NOT_EXIST )
            return

        user = self.context['user'].get_current_user()
        if not user:
            self.redirect( users.create_login_url("/write/"+menu_identifier ) )
            
        remote_addr = self.request.remote_addr        
        if not remote_addr:
            self.siteError( getSiteErrorMessage("invalid_access") )
            return
                    
        self.context['menu_id'] = Menu.getMenuIdWithIdentifier( menu_identifier )
        self.context['menu_label'] = Menu.getLabel( self.context['menu_id'] )
        self.context['menu_identifier'] = menu_identifier
        
        if self.context['user'] and User.isUserNeedCaptcha( self.get_current_user() ):
            entry_form = EntryRecaptchaForm(remote_addr, data=self.request.POST)
        else:
            entry_form = EntryForm(data=self.request.POST)
            
        if entry_form.is_valid():
            # insert
            # check user            
            User.insertUser(user, remote_addr)
            menu_id = self.context['menu_id']
            Entry.insert( entry_form.cleaned_data['title'], entry_form.cleaned_data['link'], entry_form.cleaned_data['content'], menu_id, user, remote_addr )
            self.redirect("/list/"+Menu.getMenuIdentifier( menu_id) )
        else:
            self.createCSRFToken()
            self.context['entry_form'] = entry_form
            self.render( "write.html" )
Exemplo n.º 2
0
 def get(self, menu_identifier=None, cursor=None):
     if menu_identifier is None or not Menu.isRightIdentifier(menu_identifier):
         self.siteError( SiteErrorType.ERROR_MENU_NOT_EXIST )
         return
     
     self.context['menu_id'] = Menu.getMenuIdWithIdentifier( menu_identifier )
     self.context['menu_label'] = Menu.getLabel( self.context['menu_id'] )
     self.context['menu_identifier'] = menu_identifier
     
     LIST_NUMS = 5
     
     if cursor:
         cursor = urllib.unquote(cursor).decode('utf-8')
         
     query = Entry.all()
     query.filter("menu_id", self.context['menu_id'] )
     query.filter("is_removed", False)
     query.order("-created_on")
     
     paging = Paging( query )
     paging.setCurrentCursor( cursor )
     paging.setLimit( LIST_NUMS )
     paging.execute()
 
     self.context['paging'] = paging
             
     self.render( "list.html" )
Exemplo n.º 3
0
    def get(self, menu_identifier=None):
        if menu_identifier is None or not Menu.isRightIdentifier(menu_identifier):
            self.siteError( SiteErrorType.ERROR_MENU_NOT_EXIST )
            return

        
        self.context['menu_id'] = Menu.getMenuIdWithIdentifier( menu_identifier )
        self.context['menu_label'] = Menu.getLabel( self.context['menu_id'] )
        self.context['menu_identifier'] = menu_identifier
        
        
        
        self.createCSRFToken()

        if self.context['user'] and User.isUserNeedCaptcha( self.get_current_user() ):
            entry_form = EntryRecaptchaForm(self.request.remote_addr)
        else:
            entry_form = EntryForm()
        
        
        self.context['entry_form'] = entry_form
        

        self.render( "write.html" )
Exemplo n.º 4
0
def menu_label(value):
    label = Menu.getLabel( value )
    return label