示例#1
0
def add_tag(request, mlist_fqdn, threadid):
    """ Add a tag to a given thread. """
    if not request.user.is_authenticated():
        return HttpResponse('You must be logged in to add a tag',
                            content_type="text/plain", status=403)

    if request.method != 'POST':
        raise SuspiciousOperation

    form = AddTagForm(request.POST)
    if not form.is_valid():
        return HttpResponse("Error adding tag: invalid data",
                            content_type="text/plain", status=500)
    tag = form.data['tag']
    try:
        tag_obj = Tag.objects.get(threadid=threadid,
                                  list_address=mlist_fqdn, tag=tag)
    except Tag.DoesNotExist:
        tag_obj = Tag(list_address=mlist_fqdn, threadid=threadid, tag=tag)
        tag_obj.save()

    # Now refresh the tag list
    tags = Tag.objects.filter(threadid=threadid, list_address=mlist_fqdn)
    FakeMList = namedtuple("MailingList", ["name"])
    t = loader.get_template('threads/tags.html')
    html = t.render(RequestContext(request, {
            "tags": tags,
            "mlist": FakeMList(name=mlist_fqdn)}))

    response = {"tags": [ t.tag for t in tags ], "html": html}
    return HttpResponse(json.dumps(response),
                        mimetype='application/javascript')
示例#2
0
def qpool_edit_tag(request, tag):
    tag_obj = get_object_or_404(Tag, pk=tag)
    if request.method == "POST":
        form = AddTagForm(data = request.POST, instance = tag_obj)
        if form.is_valid():
            form.save()
            return redirect('qpool_manage_tags')
    else:
        form = AddTagForm(instance=tag_obj)
    return render_to_response('cpanel/qpool_edit_tag.html', {'form':form, 'tags': tag_obj}, context_instance=RequestContext(request))
示例#3
0
def qpool_add_tag(request):
    form = AddTagForm()
    if request.method == "POST":
        tag = AddTagForm(data=request.POST)
        if tag.is_valid():
            tag.save()
            return redirect('qpool_manage_tags')
        else:
            form = tag
    return render_to_response('cpanel/qpool_add_tag.html',
                              {'form': form},
                              context_instance=RequestContext(request))
示例#4
0
def add_tag():
    '''
        application for adding a tag
    '''
    form = AddTagForm()
    if form.validate_on_submit():
        tag = request.form['tag']
        functions.add_tag(tag, session['id'])
        return redirect('/profile/')
    return render_template('add_tag.html',
                           form=form,
                           username=session['username'])
示例#5
0
def home(folder):
    print "hi"
    folderForm = AddFolderForm()
    picForm = UpdateMetadataForm()
    searchForm = SearchForm()
    tagForm = AddTagForm()
    addTagForm = AddTag2PicForm()
    moveForm = MoveFolderForm()
    batchForm = BatchUpdateForm()
    editFolderForm = EditFolderForm()
    editTagForm = EditTagForm()

    currentFolder = Tag.query.filter((Tag.name == folder)
                                     & (Tag.isFolder == True)).first_or_404()
    folder_hierarchy = Tag_Hierarchy.query.filter_by(
        node_id=currentFolder.id).order_by(Tag_Hierarchy.depth.desc()).all()
    folder_path = [
        Tag.query.filter_by(id=h.parent_id).first() for h in folder_hierarchy
    ]

    moveForm.all_folders.data = currentFolder

    if folderForm.submitFolder.data and folderForm.validate_on_submit():
        name = folderForm.name.data
        new_folder = Tag(name, isFolder=True)
        currentFolder.hierarchy(new_folder.id)

        return redirect(url_for('core.home', folder=folder))
    if tagForm.submitTag.data and tagForm.validate_on_submit():
        name = tagForm.name.data
        new_tag = Tag(name)

    tag_list = Tag.query.filter_by(isFolder=False).all()
    children = currentFolder.get_direct_children()
    pics = Pic.query.filter(Pic.tags.any(id=currentFolder.id)).order_by(
        Pic.name).all()

    return render_template('home.html',
                           editTagForm=editTagForm,
                           editFolderForm=editFolderForm,
                           batchForm=batchForm,
                           moveForm=moveForm,
                           addTagForm=addTagForm,
                           tagForm=tagForm,
                           searchForm=searchForm,
                           picForm=picForm,
                           folderForm=folderForm,
                           tag_list=tag_list,
                           folder_path=folder_path,
                           pics=pics,
                           folders=children)
示例#6
0
def add_tag(request):
    form = AddTagForm(request.POST)
    if form.is_valid():
        tagname = form.cleaned_data.get('tagname')
        # 先判断一下数据库中是否已经存在同名的标签
        resultTag = TagModel.objects.filter(name=tagname).first()
        if not resultTag:
            # 如果没有,说明可以添加
            tagModel = TagModel(name=tagname)
            tagModel.save()
            return myjson.json_result(data={'id': tagModel.id, 'name': tagModel.name})
        else:
            return myjson.json_params_error(message=u'不能设置同名标签!')
    else:
        return form.get_error_response()
示例#7
0
def cms_add_tag(request):
    '''如果tag已经存在,则不允许在添加,否则添加
    '''
    form = AddTagForm(request.POST)
    if form.is_valid():
        tag_name = form.cleaned_data.get('tag_name')
        tag_model = TagModel.objects.filter(name=tag_name).first()
        if tag_model:
            return myjson.json_params_error(u'该标签已存在,请重新设置!')
        else:
            tagModel = TagModel(name=tag_name)
            tagModel.save()
            return myjson.json_result()
    else:
        message = form.errors
        return myjson.json_params_error(message)
示例#8
0
def add_tags(request):
    form = AddTagForm(request.POST)
    if form.is_valid():
        tagname = form.cleaned_data.get('tagname')
        resultTag = TagModel.objects.filter(name=tagname).first()
        if not resultTag:
            tagModel = TagModel(name=tagname)
            tagModel.save()
            return xtjson.json_result(data={
                'id': tagModel.id,
                'name': tagModel.name
            })
        else:
            return xtjson.json_params_error(message=u'名字不能重复')

    else:
        return form.get_error_response()
示例#9
0
文件: views.py 项目: anaion/wouso
def qpool_edit_tag(request, tag):
    tag_obj = get_object_or_404(Tag, pk=tag)
    if request.method == "POST":
        form = AddTagForm(data = request.POST, instance = tag_obj)
        if form.is_valid():
            form.save()
            return redirect('qpool_manage_tags')
    else:
        form = AddTagForm(instance=tag_obj)
    return render_to_response('cpanel/qpool_edit_tag.html', {'form':form, 'tags': tag_obj}, context_instance=RequestContext(request))
示例#10
0
def add_tag(request, mlist_fqdn, threadid):
    """ Add a tag to a given thread. """
    if not request.user.is_authenticated():
        return HttpResponse('You must be logged in to add a tag',
                            content_type="text/plain",
                            status=403)

    if request.method != 'POST':
        raise SuspiciousOperation

    form = AddTagForm(request.POST)
    if not form.is_valid():
        return HttpResponse("Error adding tag: invalid data",
                            content_type="text/plain",
                            status=500)
    tag = form.data['tag']
    try:
        tag_obj = Tag.objects.get(threadid=threadid,
                                  list_address=mlist_fqdn,
                                  tag=tag)
    except Tag.DoesNotExist:
        tag_obj = Tag(list_address=mlist_fqdn, threadid=threadid, tag=tag)
        tag_obj.save()

    # Now refresh the tag list
    tags = Tag.objects.filter(threadid=threadid, list_address=mlist_fqdn)
    FakeMList = namedtuple("MailingList", ["name"])
    t = loader.get_template('threads/tags.html')
    html = t.render(
        RequestContext(request, {
            "tags": tags,
            "mlist": FakeMList(name=mlist_fqdn)
        }))

    response = {"tags": [t.tag for t in tags], "html": html}
    return HttpResponse(json.dumps(response),
                        mimetype='application/javascript')
示例#11
0
def qpool_add_tag(request):
    form = AddTagForm()
    if request.method == "POST":
        tag = AddTagForm(data=request.POST)
        if tag.is_valid():
            tag.save()
            return redirect('qpool_manage_tags')
        else:
            form = tag
    return render_to_response('cpanel/qpool_add_tag.html', {'form': form},
                              context_instance=RequestContext(request))
示例#12
0
def search_for():
    folderForm = AddFolderForm()
    picForm = UpdateMetadataForm()
    searchForm = SearchForm(request.form)
    tagForm = AddTagForm()
    addTagForm = AddTag2PicForm()
    moveForm = MoveFolderForm()
    batchForm = BatchUpdateForm()
    editTagForm = EditTagForm()

    tag_list = Tag.query.filter_by(isFolder=False).all()
    children = []
    pics = []

    if request.method == "POST" and searchForm.submitSearch.data:  # and searchForm.validate():
        print "heeey"
        data = {}
        tb = searchForm.meta.model.__tablename__
        tb_tags = Tag.__table__.name

        tag_lst = []
        # go through searchForm and create a filter dictionary in the form of {"tablename.column": "data",...} to pass through search function located in models.py
        for field in searchForm:
            if field != searchForm.submitSearch and field.data and field.data != "None":
                if field != searchForm.tags and field != searchForm.folder:
                    data[tb + '.' + field.name] = field.data
                else:
                    tag_lst.append(str(field.data.id))
        data[tb_tags + '.id'] = tag_lst

        print data
        if data:
            pics = search(data)
            print pics
        else:
            pics = {}
        return render_template('home.html',
                               editTagForm=editTagForm,
                               moveForm=moveForm,
                               batchForm=batchForm,
                               addTagForm=addTagForm,
                               searchForm=searchForm,
                               picForm=picForm,
                               tagForm=tagForm,
                               folderForm=folderForm,
                               tag_list=tag_list,
                               pics=pics,
                               folders=[])
    '''
        print "searchForm"
        print searchForm.submitSearch.data
        print searchForm.validate()
        '''

    return render_template('home.html',
                           moveForm=moveForm,
                           batchForm=batchForm,
                           editTagForm=editTagForm,
                           searchForm=searchForm,
                           addTagForm=addTagForm,
                           tagForm=tagForm,
                           picForm=picForm,
                           folderForm=folderForm,
                           pics=pics,
                           folders=children)
示例#13
0
def thread_index(request, mlist_fqdn, threadid, month=None, year=None):
    ''' Displays all the email for a given thread identifier '''
    search_form = SearchForm(auto_id=False)
    store = get_store(request)
    thread = store.get_thread(mlist_fqdn, threadid)
    if not thread:
        raise Http404
    prev_thread, next_thread = store.get_thread_neighbors(mlist_fqdn, threadid)

    sort_mode = request.GET.get("sort", "thread")
    set_message_votes(thread.starting_email, request.user)

    from_url = reverse("thread",
                       kwargs={
                           "mlist_fqdn": mlist_fqdn,
                           "threadid": threadid
                       })
    # Tags
    tag_form = AddTagForm(initial={'from_url': from_url})
    try:
        tags = Tag.objects.filter(threadid=threadid, list_address=mlist_fqdn)
    except Tag.DoesNotExist:
        tags = []

    # Favorites
    fav_action = "add"
    if request.user.is_authenticated():
        try:
            Favorite.objects.get(list_address=mlist_fqdn,
                                 threadid=threadid,
                                 user=request.user)
        except Favorite.DoesNotExist:
            pass
        else:
            fav_action = "rm"

    # Extract relative dates
    today = datetime.date.today()
    days_old = today - thread.starting_email.date.date()
    days_inactive = today - thread.last_email.date.date()

    mlist = store.get_list(mlist_fqdn)
    subject = stripped_subject(mlist, thread.starting_email.subject)

    # TODO: eventually move to a middleware ?
    # http://djangosnippets.org/snippets/1865/
    is_bot = True
    user_agent = request.META.get('HTTP_USER_AGENT', None)
    if user_agent:
        is_bot = robot_detection.is_robot(user_agent)

    context = {
        'mlist': mlist,
        'threadid': threadid,
        'subject': subject,
        'tags': tags,
        'search_form': search_form,
        'addtag_form': tag_form,
        'month': thread.date_active,
        'first_mail': thread.starting_email,
        'neighbors': (prev_thread, next_thread),
        'months_list': get_months(store, mlist.name),
        'days_inactive': days_inactive.days,
        'days_old': days_old.days,
        'sort_mode': sort_mode,
        'fav_action': fav_action,
        'reply_form': ReplyForm(),
        'is_bot': is_bot,
        'participants': thread.participants,
    }
    context["participants"].sort(key=lambda x: x[0].lower())

    if is_bot:
        # Don't rely on AJAX to load the replies
        context["replies"] = _get_thread_replies(request, thread)

    return render(request, "thread.html", context)