コード例 #1
0
ファイル: frontend.py プロジェクト: Dev-Engine/Dev_Blog2
def tag_paging(tag_name, page_num):
    """ TagList Paging.

    used for list diaries with the same tag_name with 5 diaries each page.

    Args:
        tag_name: string
        page_num: page_num

    Return:
        categories: used for sidebar list
        next_page: bool True or False
        diaries: sorted diaries_object by publish_time with 5 each page
        page_num: now page_num
        tag: tag_name used for title
        pages: used for top-nav
        profile: user object
    """
    next_page = False
    diary_num = len(Tag.objects(name=tag_name)[0].diaries)
    if diary_num > int(page_num) * 5:
        next_page = True

    profile = User.objects.first()
    categories = Category.objects.order_by('-publish_time')
    pages = StaticPage.objects.all()
    diaries = sorted(Tag.objects(name=tag_name)[0].diaries,
                     key=attrgetter('publish_time'),
                     reverse=True)[(int(page_num) - 1) * 5:int(page_num) * 5]

    return render_template('frontend/tag/list.html', diaries=diaries,
                           categories=categories, tag=tag_name,
                           next_page=next_page, page_num=page_num, pages=pages,
                           profile=profile)
コード例 #2
0
ファイル: frontend.py プロジェクト: Dev-Engine/Dev_Blog2
def tag_list(tag_name):
    """ TagList Page.

    used for list diaries with the same tag_name with 5 diaries each page.

    Args:
        tag_name: string

    Return:
        categories: used for sidebar list
        pages: used for top-nav
        diaries: sorted diaries_object by publish_time
        page_num: 1
        tag: tag_name used for title
        profile: user object
    """
    tags = Tag.objects.get_or_404(name=tag_name)
    profile = User.objects.first()
    next_page = False
    diary_num = len(tags.diaries)
    if diary_num > 5:
        next_page = True

    categories = Category.objects.order_by('-publish_time')
    pages = StaticPage.objects.all()
    diaries = sorted(Tag.objects(name=tag_name)[0].diaries,
                     key=attrgetter('publish_time'),
                     reverse=True)[:5]

    return render_template('frontend/tag/list.html', diaries=diaries,
                           categories=categories, tag=tag_name,
                           next_page=next_page, page_num=1, pages=pages,
                           profile=profile)
コード例 #3
0
    def get(self):
        groupId=self.request.get("GroupId",0)
#        username=
        group={}
        if groupId:
#            group=Group.get_by_id(int(groupId))
            group=getGroup(int(groupId))
        self.render('templates/groupAdd.html',{'group':group,'taglist':Tag.all()})
コード例 #4
0
ファイル: __init__.py プロジェクト: uniblackfire/Dev_Blog2
    def add_new_tag(self, tag_name):
        """Tag add new.
        Will check if the cat_name is unique, otherwise will return an error.

        Args:
            tag_name: string category name.

        Return:
            None
        """
        tag_name = SiteHelpers().secure_filename(tag_name)

        try:
            category = Tag(name=tag_name)
            return category.save()
        except NotUniqueError:
            return "tag name not unique"
コード例 #5
0
ファイル: __init__.py プロジェクト: uniblackfire/Dev_Blog2
    def add_new_tag(self, tag_name):
        """Tag add new.
        Will check if the cat_name is unique, otherwise will return an error.

        Args:
            tag_name: string category name.

        Return:
            None
        """
        tag_name = SiteHelpers().secure_filename(tag_name)

        try:
            category = Tag(name=tag_name)
            return category.save()
        except NotUniqueError:
            return 'tag name not unique'
コード例 #6
0
def getAllTags():
    tagslist=memcache.get('alltags')
    if not tagslist:
        tagslist=[]
        for tag in Tag.all():
            tagslist.append({'id':tag.key().id(),'name':tag.name})
        memcache.set('alltags',tagslist,36000)
    return tagslist
コード例 #7
0
ファイル: __init__.py プロジェクト: uniblackfire/Dev_Blog2
    def get_tag_detail(self, tag_name):
        """Tag detail.
        will return tag detail by tag name.

        Args:
            tag_name: string tag name.

        Return:
            tag: tag object
        """
        return Tag.objects(name=tag_name).first()
コード例 #8
0
ファイル: __init__.py プロジェクト: uniblackfire/Dev_Blog2
    def get_tag_detail(self, tag_name):
        """Tag detail.
        will return tag detail by tag name.

        Args:
            tag_name: string tag name.

        Return:
            tag: tag object
        """
        return Tag.objects(name=tag_name).first()
コード例 #9
0
def getTagName(id):
    name=memcache.get('tag'+str(id))
    if name:
        return name
    else:
        name=Tag.get_by_id(id)
        if name:
            name=name.name
            memcache.set('tag'+str(id),name,3600)
            return name
        else:
            return ''
コード例 #10
0
def tag_paging(tag_name, page_num):
    """ TagList Paging.

    used for list diaries with the same tag_name with 5 diaries each page.

    Args:
        tag_name: string
        page_num: page_num

    Return:
        categories: used for sidebar list
        next_page: bool True or False
        diaries: sorted diaries_object by publish_time with 5 each page
        page_num: now page_num
        tag: tag_name used for title
        pages: used for top-nav
        profile: user object
    """
    next_page = False
    diary_num = len(Tag.objects(name=tag_name)[0].diaries)
    if diary_num > int(page_num) * 5:
        next_page = True

    profile = User.objects.first()
    categories = Category.objects.order_by('-publish_time')
    pages = StaticPage.objects.all()
    diaries = sorted(Tag.objects(name=tag_name)[0].diaries,
                     key=attrgetter('publish_time'),
                     reverse=True)[(int(page_num) - 1) * 5:int(page_num) * 5]

    return render_template('frontend/tag/list.html',
                           diaries=diaries,
                           categories=categories,
                           tag=tag_name,
                           next_page=next_page,
                           page_num=page_num,
                           pages=pages,
                           profile=profile)
コード例 #11
0
    def get(self):
        groupid=self.request.get('groupid')
        tagmap={}
        for tag in Tag.all():
            tagmap[str(tag.key().id())]=tag.name

        username=get_current_user(self)
        user=getorAddUser(username)
        if groupid:
            groupid=int(groupid)
#            group=Group.get_by_id(groupid)
            group=getGroup(groupid)
            if group.author==username:
                group.delete()
                nlist=[]
                rnlist=[]
                for n in Note.all().filter('group =',groupid):
                    nlist.append(n)
                    rnlist.append('r'+str(n.key().id()))
                db.delete(Replay.get_by_key_name(rnlist))
                db.delete(nlist)
                if groupid in user.createGroup:
                    user.createGroup.remove(groupid)
                    user.put()
                if groupid in user.createGroupAdd:
                    user.createGroupAdd.remove(groupid)
                    user.put()


        groupidlist=user.createGroup+user.createGroupAdd
        list=Group.get_by_id(groupidlist)
#        list=Group.all().filter('author =',username)
        listgroup=[]
        ischange=False
        for i,group in enumerate(list):
            if not group:
                if groupidlist[i] in user.createGroup:
                    user.createGroup.remove(groupidlist[i])
                    ischange=True
                if groupidlist[i] in user.createGroupAdd:
                    user.createGroupAdd.remove(groupidlist[i])
                    ischange=True
            else:
                group.tagname=tagmap.get(str(group.tag),'')
                listgroup.append(group)
        if ischange:
            user.put()
        self.render('templates/removegroupList.html',{'list':listgroup})
コード例 #12
0
 def post(self):
     tagmap={}
     for tag in Tag.all():
         tagmap[str(tag.key().id())]=tag.name
     username=get_current_user(self)
     if '000'==username:
         type=self.request.get('type','')
         value=self.request.get('value',0)
         list=[]
         if type=='username':
             list=Group.all().filter('author =',str(value))
         if type=='groupid':
             list=Group.get_by_id([int(value)])
     else:
         list=Group.all().filter('author =',username)
     listgroup=[]
     for group in list:
         group.tagname=tagmap.get(str(group.tag),'')
         listgroup.append(group)
     self.render('templates/groupList.html',{'list':listgroup,'tagmap':tagmap,'isadmin':('000'==username and [True] or [False])[0]})
コード例 #13
0
def tag_list(tag_name):
    """ TagList Page.

    used for list diaries with the same tag_name with 5 diaries each page.

    Args:
        tag_name: string

    Return:
        categories: used for sidebar list
        pages: used for top-nav
        diaries: sorted diaries_object by publish_time
        page_num: 1
        tag: tag_name used for title
        profile: user object
    """
    tags = Tag.objects.get_or_404(name=tag_name)
    profile = User.objects.first()
    next_page = False
    diary_num = len(tags.diaries)
    if diary_num > 5:
        next_page = True

    categories = Category.objects.order_by('-publish_time')
    pages = StaticPage.objects.all()
    diaries = sorted(Tag.objects(name=tag_name)[0].diaries,
                     key=attrgetter('publish_time'),
                     reverse=True)[:5]

    return render_template('frontend/tag/list.html',
                           diaries=diaries,
                           categories=categories,
                           tag=tag_name,
                           next_page=next_page,
                           page_num=1,
                           pages=pages,
                           profile=profile)
コード例 #14
0
ファイル: interface.py プロジェクト: wangjian2254/moguim
 def get(self):
     self.render('templates/group.html',{'grouplist':Group.all(),'taglist':Tag.all()})
コード例 #15
0
ファイル: __init__.py プロジェクト: uniblackfire/Dev_Blog2
    def edit_diary(self, diary_id, title, html, category, tags):
        """ Edit diary from admin

        receives title, content(html), tags and cagetory
        save title, content(html), pure content(further use), tags and cagetory
        also auto save author as current_user.

        this method will auto save new Category or Tag if not exist otherwise
        save in existed none with push only diary_object

        Args:
            diary_id: diary_id
            title: string
            html: string
            cagetory: string
            tags: list

        Save:
            title: string
            html: string
            content: string without html tags
            category: string
            tags: list
            summary: first 80 characters in content with 3 dots in the end
            author: current_user_object
        """
        title = SiteHelpers().secure_filename(title)
        category = SiteHelpers().secure_filename(category)
        content = SiteHelpers().strip_html_tags(html)
        splited_tags = tags.split(",")

        author = UserDispatcher().get_profile()

        try:
            diary = Diary.objects(pk=diary_id).first()
        except:
            diary = Diary(title=title)

        old_cat = diary.category
        old_tags = diary.tags

        diary.title = title
        diary.content = content
        diary.category = category
        diary.summary = content[0:80] + "..."
        diary.html = html
        diary.author = author
        diary.tags = splited_tags
        diary.save()

        a, cat = Category.objects.get_or_create(name=category, defaults={"diaries": [diary]})
        if not cat:
            Category.objects(name=category).update_one(push__diaries=diary)
            if old_cat is not None:
                Category.objects(name=old_cat).update_one(pull__diaries=diary)

        for t in old_tags:
            Tag.objects(name=t).update_one(pull__diaries=diary)

        for i in splited_tags:
            b, tag = Tag.objects.get_or_create(name=i, defaults={"diaries": [diary]})
            if not tag:
                Tag.objects(name=i).update_one(push__diaries=diary)

        return
コード例 #16
0
ファイル: admin.py プロジェクト: Dev-Engine/Dev_Blog2
def diary_edit(diary_id=None):
    """ Edit diary from admin

    receives title, content(html), tags and cagetory
    save title, content(html), pure content(further use), tags and cagetory
    also auto save author as current_user.

    this method will auto save new Category or Tag if not exist otherwise save
    in existed none with push only diary_object

    Args:
        diary_id: diary_id
        title: string
        html: string
        cagetory: string
        tags: list

    Save:
        title: string
        html: string
        content: string without html tags
        category: string
        tags: list
        summary: first 80 characters in content with 3 dots in the end
        author: current_user_object
    """
    if request.method == 'POST' and 'title' and 'content' in request.form:
        re_helper = ReHelper()

        title = re_helper.r_slash(request.form["title"])
        html = request.form["content"]
        category = re_helper.r_slash(request.form["category"])
        tags = request.form["tags"]

        ''' save simple data for further use'''
        parser = MyHTMLParser()
        parser.feed(html)
        content = parser.html  # the pure content without html tags

        splited_tags = tags.split(',')

        author = UserModel.objects.first()

        try:
            diary = Diary.objects(pk=diary_id).first()
        except:
            diary = Diary(title=title)

        old_cat = diary.category
        old_tags = diary.tags

        diary.title = title
        diary.content = content
        diary.category = category
        diary.summary = content[0:80] + '...'
        diary.html = html
        diary.author = author
        diary.tags = splited_tags
        diary.save()

        a, cat = Category.objects.get_or_create(name=category,
                                                defaults={'diaries': [diary]})
        if not cat:
            Category.objects(name=category).update_one(push__diaries=diary)
            if old_cat is not None:
                Category.objects(name=old_cat).update_one(pull__diaries=diary)

        for t in old_tags:
            Tag.objects(name=t).update_one(pull__diaries=diary)

        for i in splited_tags:
            b, tag = Tag.objects.get_or_create(name=i,
                                               defaults={'diaries': [diary]})
            if not tag:
                Tag.objects(name=i).update_one(push__diaries=diary)

        return redirect(url_for("admin.diary_list"))

    else:
        try:
            diary = Diary.objects(pk=diary_id).first()
        except:
            diary = None
        categories = Category.objects.all()

        return render_template('admin/diary/edit.html', diary=diary,
                               categories=categories)
コード例 #17
0
def diary_edit(diary_id=None):
    """ Edit diary from admin

    receives title, content(html), tags and cagetory
    save title, content(html), pure content(further use), tags and cagetory
    also auto save author as current_user.

    this method will auto save new Category or Tag if not exist otherwise save
    in existed none with push only diary_object

    Args:
        diary_id: diary_id
        title: string
        html: string
        cagetory: string
        tags: list

    Save:
        title: string
        html: string
        content: string without html tags
        category: string
        tags: list
        summary: first 80 characters in content with 3 dots in the end
        author: current_user_object
    """
    if request.method == 'POST' and 'title' and 'content' in request.form:
        re_helper = ReHelper()

        title = re_helper.r_slash(request.form["title"])
        html = request.form["content"]
        category = re_helper.r_slash(request.form["category"])
        tags = request.form["tags"]
        ''' save simple data for further use'''
        parser = MyHTMLParser()
        parser.feed(html)
        content = parser.html  # the pure content without html tags

        splited_tags = tags.split(',')

        author = UserModel.objects.first()

        try:
            diary = Diary.objects(pk=diary_id).first()
        except:
            diary = Diary(title=title)

        old_cat = diary.category
        old_tags = diary.tags

        diary.title = title
        diary.content = content
        diary.category = category
        diary.summary = content[0:80] + '...'
        diary.html = html
        diary.author = author
        diary.tags = splited_tags
        diary.save()

        a, cat = Category.objects.get_or_create(name=category,
                                                defaults={'diaries': [diary]})
        if not cat:
            Category.objects(name=category).update_one(push__diaries=diary)
            if old_cat is not None:
                Category.objects(name=old_cat).update_one(pull__diaries=diary)

        for t in old_tags:
            Tag.objects(name=t).update_one(pull__diaries=diary)

        for i in splited_tags:
            b, tag = Tag.objects.get_or_create(name=i,
                                               defaults={'diaries': [diary]})
            if not tag:
                Tag.objects(name=i).update_one(push__diaries=diary)

        return redirect(url_for("admin.diary_list"))

    else:
        try:
            diary = Diary.objects(pk=diary_id).first()
        except:
            diary = None
        categories = Category.objects.all()

        return render_template('admin/diary/edit.html',
                               diary=diary,
                               categories=categories)
コード例 #18
0
ファイル: __init__.py プロジェクト: uniblackfire/Dev_Blog2
    def edit_diary(self, diary_id, title, html, category, tags):
        """ Edit diary from admin

        receives title, content(html), tags and cagetory
        save title, content(html), pure content(further use), tags and cagetory
        also auto save author as current_user.

        this method will auto save new Category or Tag if not exist otherwise
        save in existed none with push only diary_object

        Args:
            diary_id: diary_id
            title: string
            html: string
            cagetory: string
            tags: list

        Save:
            title: string
            html: string
            content: string without html tags
            category: string
            tags: list
            summary: first 80 characters in content with 3 dots in the end
            author: current_user_object
        """
        title = SiteHelpers().secure_filename(title)
        category = SiteHelpers().secure_filename(category)
        content = SiteHelpers().strip_html_tags(html)
        splited_tags = tags.split(',')

        author = UserDispatcher().get_profile()

        try:
            diary = Diary.objects(pk=diary_id).first()
        except:
            diary = Diary(title=title)

        old_cat = diary.category
        old_tags = diary.tags

        diary.title = title
        diary.content = content
        diary.category = category
        diary.summary = content[0:80] + '...'
        diary.html = html
        diary.author = author
        diary.tags = splited_tags
        diary.save()

        a, cat = Category.objects.get_or_create(name=category,
                                                defaults={'diaries': [diary]})
        if not cat:
            Category.objects(name=category).update_one(push__diaries=diary)
            if old_cat is not None:
                Category.objects(name=old_cat).update_one(pull__diaries=diary)

        for t in old_tags:
            Tag.objects(name=t).update_one(pull__diaries=diary)

        for i in splited_tags:
            b, tag = Tag.objects.get_or_create(name=i,
                                               defaults={'diaries': [diary]})
            if not tag:
                Tag.objects(name=i).update_one(push__diaries=diary)

        return