示例#1
0
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/")
示例#2
0
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))