示例#1
0
def mig_worry(request) :
    docs = Document.objects.filter(category=1)
    for doc in docs :
        doc.delete()

    file_name = "/home/worry/migration/worry.xml"
    t = ElementTree
    tree = t.parse(file_name)
    root = tree.getroot()
    posts = root.getiterator("post")

    for post in posts :
        title = deco(post.find("title").text)

        nick_name = deco(post.find("nick_name").text)

        try:
            username = deco(post.find("user_id").text)
            user = User.objects.get(username=username)
        except Exception,e:
            user = None
            username = nick_name

        password = deco(post.find("password").text)
        pub_date = deco(post.find("regdate").text)
        ipaddress = deco(post.find("ipaddress").text)
        is_secret = str(deco(post.find("is_secret").text)) == 'Y'
        try:
            hit = deco(post.find("readed_count").text)
        except:
            hit = 0
        content = deco(post.find("content").text)

        try :
            if str(deco(post.find("notify_message").text)) == 'Y':
                category=3
                category_name="notice"
            else :
                category=1
                category_name="worryboard"
        except :
            category=1
            category_name="worryboard"

        doc = Document(module_id=2,
                       user=user,
                       username=username,
                       module_name="board", 
                       category=category,
                       category_name=category_name,
                       is_secret=is_secret,
                       title=title,
                       content=content,
                       ipaddress =ipaddress,
                       hit=hit,
                       pub_date = pub_date)
        doc.save()
        doc.pub_date=get_date(deco(post.find('regdate').text))
        doc.save()

        try :
            comments = post.find("comments").getiterator("comment")
        except :
            comments = []

        for comment in comments :
            try :
                cmt = deco(comment.find("password").text)
            except:
                cmt = None
            is_secret = str(deco(comment.find("is_secret").text)) == 'Y'

            username = comment.find("user_id")

            if not username :
                username = comment.find("user_id")
                if not username :
                    username = None
                else : username = deco(username.text)
            else : username = deco(username.text)

            try :
                user = User.objects.get(username=username)
            except :
                user = None


            cmt = Comment(document=doc, 
                          user=user,
                          is_secret=is_secret,
                          content=deco(comment.find("content").text),
                          ipaddress=deco(comment.find("ipaddress").text),
                          username=deco(comment.find("nick_name").text),
                          password=cmt)
            cmt.save()
            cmt.pub_date = get_date(deco(comment.find("regdate").text))
            cmt.save()
示例#2
0
def mig(request) :
    file_name = "/home/worry/migration/blog.xml"
    t = ElementTree
    tree = t.parse(file_name)
    root = tree.getroot()
    posts = root.getiterator("post")

    for post in posts :
        title = post.find("title").text
        try:
            username = post.find("user_id").text
            user = User.objects.get(username=username)
        except Exception,e:
            user = None
        nick_name = post.find("nick_name").text
        password = post.find("password").text
        pub_date = post.find("regdate").text
        ipaddress = post.find("ipaddress").text
        is_secret = str(post.find("is_secret").text) == 'Y'
        try:
            hit = post.find("readed_count").text
        except:
            hit = 0
        content = post.find("content").text
        doc = Document(module_id=1, 
                       user=user,
                       module_name="blog",
                       category=2,
                       category_name='worry',
                       is_secret=is_secret,
                       title=title,
                       content=content,
                       ipaddress =ipaddress,
                       username=username,
                       hit=hit,
                       pub_date = pub_date)
        doc.save()
        doc.pub_date=get_date(post.find('regdate').text)
        tag_name = "κ±±μ •μΈν˜•"
        tag, dummy = Tag.objects.get_or_create(name=tag_name)
        doc.tag_set.add(tag)
        doc.save()

        try :
            comments = post.find("comments").getiterator("comment")
        except :
            comments = []

        for comment in comments :
            try :
                cmt = comment.find("password").text
            except:
                cmt = None
            is_secret = (str(comment.find("is_secret").text) == 'Y')

            
            username = comment.find("user_id")
            if not username :
                username = comment.find("nick_name")
                if not username  :
                    username = '******'
                else :
                    username = username.text
            else :
                username = username.text

            try :
                user = User.objects.get(username=username)
            except :
                user=None

            cmt = Comment(document=doc, 
                          user=user,
                          is_secret=is_secret,
                          content=comment.find("content").text,
                          ipaddress=comment.find("ipaddress").text,
                          username=comment.find("nick_name").text,
                          password=cmt)
            cmt.save()
            cmt.pub_date = get_date(comment.find("regdate").text)
            cmt.save()