Exemplo n.º 1
0
    def get(self, did):
        try:
            Category.del_diary(did)
        except Exception as e:
          print str(e)

        self.redirect('/admin/category')
Exemplo n.º 2
0
    def get(self, cid, page):
        try:
            categories = Category.get()
            detail = Category.find_by_id(cid, page)
        except Exception as e:
            self.send_error(404)
            send_error_email('Category List Error', str(e))

        L = detail['diaries']
        sorted_diaries = sorted(L, key=itemgetter('did'), reverse=True) 

        number = len(sorted_diaries)

        if number == 15:
            next_page = True
        elif number < 1:
            self.send_error(404)
            return 
        else:
            next_page = False

        if detail is not None:
            profile = Account.get()
            self.render('Category/list.html', detail=detail, categories=categories, profile=profile, sorted_diaries=sorted_diaries, page=page, next_page=next_page, cid=cid)
        else:
            self.send_error(404)
Exemplo n.º 3
0
    def post(self, *args):
        try:
            keywords = self.get_argument('keywords')
        except:
            keywords = None

        if keywords is not None:
            Calculate.search_add_keyword(keywords)
            try:
                categories = Category.get()
                cate_result = Category.find_by_name(keywords)
                tag_result = Tag.find_by_name(keywords)
            except Exception as e:
                self.send_error(404)
                send_error_email('Search Error', str(e))

            try:
                C = cate_result['diaries']
            except:
                C = []

            try:
                T = tag_result['diaries']
            except:
                T = []

            real_result = list(C+T)

            """
                To combine tag_result and category_result
                first make an empty list to save filtered_result
                and to make faster, make another empty list to save diary_id to ensure not append repeat diary
            """

            filtered_result = []
            cache_did = []

            for i in real_result:
                if cache_did == []:
                    cache_did.append(i['did'])
                    filtered_result.append(i)
                else:
                    if i['did'] not in cache_did:
                        cache_did.append(i['did'])
                        filtered_result.append(i)

            profile = Account.get()

            if filtered_result != []:
                self.render('Search/result.html', detail=filtered_result, categories=categories, profile=profile)
            else:
                filtered_result = None
                self.render('Search/result.html', detail=filtered_result, categories=categories, profile=profile)
        else:
            self.redirect('/')
Exemplo n.º 4
0
    def get(self, _id):
        try:
            categories = Category.get()
            detail = Category.find_by_id(_id)
        except Exception as e:
            self.send_error(404)
            send_error_email('Category List Error', str(e))

        L = detail['diaries']
        sorted_diaries = sorted(L, key=itemgetter('did'), reverse=True) 
        if detail is not None:
            profile = Account.get()
            self.render('Category/list.html', detail=detail, categories=categories, profile=profile, sorted_diaries=sorted_diaries)
        else:
            self.send_error(404)
Exemplo n.º 5
0
    def get(self):
        try:
            categories = Category.get()
        except Exception as e:
            print str(e)

        self.render('Admin/Category/index.html', categories=categories)
Exemplo n.º 6
0
    def get(self):
        try:
            categories = Category.get()
        except Exception as e:
            print str(e)

        self.render('about.html', categories=categories)
Exemplo n.º 7
0
    def get(self, c_id):
        try:
            categories = Category.find_all_by_id(c_id)
        except Exception as e:
          print str(e)

        self.render('Admin/Category/detail.html', categories=categories)
Exemplo n.º 8
0
    def get(self, *args):

        try:
            profile = Account.get()
            categories = Category.get()
        except Exception as e:
            print str(e)

        if profile is None:
            self.redirect("/admin")
            return

        try:
            diaries = Diary.get()
            amount = diaries.count()
        except Exception as e:
            print str(e)
            return

        number = diaries.count(with_limit_and_skip=True)

        if number == 5:
            next_page = True
        elif number < 1:
            self.send_error(404)
            return
        else:
            next_page = False

        self.render("index.html", profile=profile, diaries=diaries, next_page=next_page, categories=categories)
Exemplo n.º 9
0
    def get(self):
        try:
            categories = Category.get()
            content = Page.find_by_property('about')
        except Exception as e:
            print str(e)

        self.render('about.html', categories=categories, content=content)
Exemplo n.º 10
0
    def get(self, _id):

        try:
            detail = Diary.get_detail(_id)
            categories = Category.get()
        except:
            self.redirect('/admin')

        self.render('Admin/Diary/edit.html', detail=detail, categories=categories)
Exemplo n.º 11
0
    def get(self, *args):
        try:
            albums = Gallary.get_all()
            profile = Account.get()
            categories = Category.get()
        except Exception as e:
            self.send_error(404)
            send_error_email('Gallary get Error', str(e))

        self.render('Gallary/index.html', albums=albums, profile=profile, categories=categories)
Exemplo n.º 12
0
    def post(self, *args):
        category = self.get_argument('category')

        try:
          cid = Category.new(category)
        except Exception as e:
          print str(e)

        if cid:
          self.write(json.dumps({'success': 'true', 'cid': cid}))
        else:
          self.write(json.dumps({'success': 'false'}))
Exemplo n.º 13
0
    def post(self, *args):
        
        try:
            did = self.get_argument('did')
            title = self.get_argument('title')
            content = self.get_argument('content')
            c_name = self.get_argument('category_name')
            c_id = self.get_argument('c_id')
        except Exception as e:
            refer = self.request.headers.get('Referer')
            self.redirect(refer)
        
        try:
            tags = self.get_argument('tags')
        except:
            tags = None

        if tags:
            splited_tags = tags.split(',')
        else:
            splited_tags = None

        """" determin whether there is a exist undefine category
             if there is not, create it
             else use its c_id
        """
        if c_id == 'none':
            detail = Category.find_by_name(c_name)
            try:
                c_id = detail.get('_id')
            except:
                c_id = Category.new(c_name) 
        try:
            Diary.update(did, title, content, c_name, c_id, splited_tags)
        except Exception as e:
            print str(e)

        self.redirect('/admin/all-post/1')
Exemplo n.º 14
0
    def get(self, _id):
        try:
            detail = Diary.get_detail(_id)
            categories = Category.get()
        except Exception as e:
            self.send_error(404)
            send_error_email('Diary Detail Error', str(e))

        if detail is not None:
            profile = Account.get()
            try:
               guest_name = self.get_secure_cookie('guest_name')
               guest_email = self.get_secure_cookie('guest_email')
            except:
               guest_name = None
               guest_email = None

            self.render('Diary/detail.html', detail=detail, profile=profile, guest_name=guest_name, guest_email=guest_email, categories=categories)
        else:
            self.send_error(404)
Exemplo n.º 15
0
    def get(self, page):

        try:
            profile = Account.get()
            diaries = Diary.get_diary_list(page)
            categories = Category.get()
        except Exception as e:
            self.send_error(404)
            send_error_email('Diary List Error', str(e))

        number = diaries.count(with_limit_and_skip=True)

        if number == 5:
            next_page = True
        elif number < 1:
            self.send_error(404)
            return 
        else:
            next_page = False

        self.render('Diary/list.html', diaries=diaries, profile=profile, page=page, next_page=next_page, categories=categories)
Exemplo n.º 16
0
 def get(self):
     categories = Category.get()
     self.render('Admin/Diary/add.html', categories=categories)