예제 #1
0
파일: main.py 프로젝트: sthtodo/bitsbang
 def get(self, spamid = None):
     if spamid is None:
         spams = Spam.all().order('-updated_at').fetch(10)
         self.template_value['spams'] = spams
         self.template_value['can_spam'] = True
         if self.user is None:
             self.template_value['can_spam'] = False
         return self.render('spam/index.html')
     else:
         spam = Spam.get_by_id(int(spamid))
         self.template_value['spam'] = spam
         subspams = SubSpam.all().filter("parent_spam = ", spam).order('created_at')
         self.template_value['subspams'] = subspams
         
         self.template_value['can_spam'] = can_spam(self, spam)
         return self.render('spam/show.html')
예제 #2
0
파일: main.py 프로젝트: sthtodo/bitsbang
    def post(self, spamid = None):
        self.template_value['this_url'] = '/spam/new/'
        title = self.request.get('title').strip()
        parent_spam = None
        if not spamid is None:
            parent_spam = find_spam(self, spamid)
            # if self.user.key() == parent_spam.user.key():
            #     return self.redirect('/spam/%s/' % spamid)
            if can_spam(self, parent_spam) is False:
                return self.redirect('/spam/%s/' % spamid)
            self.template_value['spam'] = parent_spam
            self.template_value['this_url'] = '/spam/%s/new/' % spamid
            title = parent_spam.title

        sub_title = self.request.get('sub_title').strip()
        comment = self.request.get('comment').strip()

        ui_interact = self.request.get('ui_interact').strip()
        gameplay = self.request.get('gameplay').strip()
        replicability = self.request.get('replicability').strip()
        highlight = self.request.get('highlight').strip()
        
        errors = 0
        
        # if len(title) == 0 and spamid is None:
        #     errors += 1
        #     self.template_value['title_error'] = 'can\'t be blank'
        # else:
        #     self.template_value['title_error'] = 'ok'
        #     
        # if len(comment) == 0:
        #     errors += 1
        #     self.template_value['comment_error'] = 'can\'t be blank'
        # else:
        #     self.template_value['comment_error'] = 'ok'
        
        mandatoryList = ['title', 'comment']
        for varname in mandatoryList:
            var = eval(varname)
            self.template_value[varname] = var
            if len(var) == 0:
                errors += 1
                self.template_value[varname + '_error'] = 'can\'t be blank'
            else:
                self.template_value[varname + '_error'] = 'ok'
                
        varList = ['title', 'sub_title', 'comment']
        for varname in varList:
            var = eval(varname)
            self.template_value[varname] = var
        
        ratingList = ['ui_interact', 'gameplay', 'replicability', 'highlight']

        for rating in ratingList:
            var = eval(rating)
            self.template_value[rating] = var
            if var.isdigit():
                self.template_value[rating + '_error'] = 'ok'
            else:
                errors += 1
                self.template_value[rating + '_error'] = 'is empty or not digit'

        if errors > 0:
            return self.render('/spam/new.html')
            
        ui_interact = int(ui_interact)
        gameplay = int(gameplay)
        replicability = int(replicability)
        highlight = int(highlight)

        if parent_spam is None:
            spam = Spam.new(title, sub_title, comment, self.user, ui_interact, gameplay, replicability, highlight)
            self.redirect('/spam/')
        else:
            spam = SubSpam.new(sub_title, comment, self.user, ui_interact, gameplay, replicability, highlight, parent_spam)
            self.redirect('/spam/%s/' % spamid)
예제 #3
0
def find_spam(self, spamid):
    spam = Spam.get_by_id(int(spamid))
    if spam is None:
        return self.redirect('/')
    return spam