def write_guest_book(request, module_name, is_secret) : " Guest book write " canonical_module_name = get_canonical_module_name(module_name) module_id = get_module_id(canonical_module_name) if request.GET.has_key('docid'): if isNumber(request.GET['docid']): return save(request, module_name, request.GET['docid']) form = GuestBookForm(request.POST) if form.is_valid() : doc = Document( user = request.user, module_id=module_id, module_name=canonical_module_name, content = form.cleaned_data['tx_content'], is_secret = is_secret, ipaddress = get_ipaddress(request), hit=0) doc.save() if not is_secret : save_tweet(doc) else: form = GuestBookForm() return HttpResponseRedirect("/guest/")
def write_document(request, module_name, is_secret) : " blog, board write " canonical_module_name = get_canonical_module_name(module_name) module_id = get_module_id(canonical_module_name) if request.POST.has_key('is_notice') : is_notice = True else : is_notice = False form = WriteForm(request.POST) if form.is_valid() : category = None category_name = None if request.POST.has_key('tx_article_category') : category = request.POST['tx_article_category'] category_name = get_category_name(canonical_module_name, request.POST['tx_article_category']) doc = Document( user = request.user, module_id=module_id, module_name=canonical_module_name, category = category, category_name = category_name, is_notice = is_notice, title = form.cleaned_data['tx_article_title'], content = form.cleaned_data['tx_content'], is_secret = is_secret, ipaddress = get_ipaddress(request), hit=0) doc.save() # twitter if request.POST.has_key('twitter') : save_tweet(doc) # Save tags # print form.cleaned_data['tags'] tag_names = form.cleaned_data['tags'].split(',') for tag_name in tag_names: tag_name = tag_name.strip() if tag_name == '' : continue tag, dummy = Tag.objects.get_or_create(name=tag_name) doc.tag_set.add(tag) doc.save() handle_uploaded_files(document = doc, file_list = request.POST['attach_files'], file_type = settings.FILE_TYPE) handle_uploaded_files(document = doc, file_list = request.POST['attach_images'], file_type = settings.IMAGE_TYPE) if module_name == 'blog': return HttpResponseRedirect("/%s/?category=%d" % (module_name, int(category))) else: return HttpResponseRedirect("/%s/%s/%d/?category=%d" % (category_name, "view", doc.id, int(category))) else : return HttpResponseRedirect(get_referer(request))
def get_and_save_mentions(since_id, page): mentions = get_mentions(access_token, since_id, page, 200) if mentions: if len(json.loads(mentions)) == 200: get_and_save_mentions(page + 1, since_id) mentions = json.loads(mentions) mentions.reverse() for mention in mentions: m = re.match("^#worry$|^#worry .*$|^.* #worry .*$|^.* #worry$", mention["text"]) content = mention["text"] term = re.search(" *#worry *", content) if term: content = content.replace(term.group(), " ") term = re.search(" *@dontworrycenter *", content) if term: content = content.replace(term.group(), " ") content = content.strip() if m: doc = Document( module_id=2, module_name="board", category=1, category_name="worryboard", title=content[:20] + " ...", content=content, hit=0, ipaddress=mention["id"], username=mention["user"]["screen_name"], ) doc.save() else: doc = Document( module_id=3, module_name="guest", content=content, hit=0, ipaddress=mention["id"], username=mention["user"]["screen_name"], ) doc.save() last_id = mention["id"] return last_id
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()
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()
def submit(request): if request.method == 'POST': form = OrderFormSecond(request.POST) if form.is_valid() : bank_id = form.cleaned_data['bank'] sender_name = form.cleaned_data['sender_name'] sender_phone = form.cleaned_data['sender_phone'] doll_count = form.cleaned_data['doll_count'] phonedoll_count = form.cleaned_data['phonedoll_count'] content = form.cleaned_data['content'] payment_name = form.cleaned_data['payment_name'] receiver_name = form.cleaned_data['receiver_name'] receiver_phone = form.cleaned_data_receiver_phone() receiver_address = form.cleaned_data['receiver_address'] receiver_detail_address = form.cleaned_data['receiver_detail_address'] receiver_address_number = form.cleaned_data['receiver_address_number'] send_issue = form.cleaned_data['send_issue'] is_gift = form.cleaned_data['is_gift'] state = 'before_payment' bank = Bank.objects.get(id=bank_id) module_name = get_canonical_module_name("shop") category = 2 document = Document( user = request.user, module_id = get_module_id(module_name), module_name = module_name, category = category, category_name = get_category_name(module_name, category), is_notice = False, title = make_title(doll_count, phonedoll_count, is_gift), content = "", ipaddress = get_ipaddress(request), hit=0) document.save() order = Order( user = request.user, bank = bank, document = document, sender_name = sender_name, sender_phone = sender_phone, doll_count = doll_count, phonedoll_count = phonedoll_count, content = content, payment_name = payment_name, receiver_name = receiver_name, receiver_phone = receiver_phone, receiver_address = receiver_address, receiver_detail_address = receiver_detail_address, receiver_address_number = receiver_address_number, send_issue = send_issue, is_gift = is_gift, state = state) order.save() return HttpResponseRedirect('/accounts/mypage/') else: variables = RequestContext(request, { 'form': form }) return render_to_response('order_form_second.html', variables, context_instance=RequestContext(request)) else: return HttpResponseRedirect('/intro/')