예제 #1
0
파일: views.py 프로젝트: cyplp/wsgiwar2013
def tagrss(request):
    """
    """
    links = Link.view('viewTag/all', limit=10, descending=True,
                      startkey=[request.matchdict['tag'], {}],
                      endkey=[request.matchdict['tag']])
    return {'links': links}
예제 #2
0
def rmlink(request):
    """
    Delete a link.
    """
    link = Link.get(request.matchdict['link'])
    link.delete()
    return HTTPFound(location=request.route_path('mylinks'))
예제 #3
0
파일: views.py 프로젝트: cyplp/wsgiwar2013
def link(request):
    """
    """
    link = Link.get(request.matchdict['link'])

    if link.private:
        raise HTTPNotFound()

    return {'link': link}
예제 #4
0
파일: views.py 프로젝트: cyplp/wsgiwar2013
def home(request):
    """
    """
    limit, page = limitAndPage(request)

    links = Link.view('public/all',  limit=limit, descending=True, \
                      skip=limit*page)

    return {'links': links, 'page': page, 'limit':limit}
예제 #5
0
파일: utils.py 프로젝트: cyplp/wsgiwar2013
def delAndPurge():
    """
    """
    parser = argparse.ArgumentParser()
    parser.add_argument('--conf',
                        help='wsgi conf file')

    parser.add_argument('--userid',
                        help='user id')

    args = parser.parse_args()

    config = ConfigParser.RawConfigParser()
    config.read(args.conf)

    server = couchdbkit.Server(config.get('app:main', 'couchdb.url'))
    db = server.get_or_create_db(config.get('app:main','couchdb.db'))

    User.set_db(db)
    Link.set_db(db)


    push('couchdb/_design/purge', db)

    try:
        user = User.get(args.userid)
        user.delete()

        print "%s is now deleted" % args.userid
    except couchdbkit.exceptions.ResourceNotFound:
        print "%s not found" % args.userid

    links = Link.view('purge/all',
                      key=args.userid,
                      include_docs=True)

    print "%d links found" % len(links)

    for link in links:
        link.delete()

    print "job done"
예제 #6
0
파일: views.py 프로젝트: cyplp/wsgiwar2013
def tag(request):
    """
    Tag page.
    """
    limit, page = limitAndPage(request)

    links = Link.view('viewTag/all', limit=limit,
                      descending=True, skip=page*limit,
                      startkey=[request.matchdict['tag'], {}],
                      endkey=[request.matchdict['tag']])
    return {'links': links, 'limit': limit, 'page': page}
예제 #7
0
파일: views.py 프로젝트: cyplp/wsgiwar2013
def rmComment(request):
    """
    Delete a comment.
    """
    link = Link.get(request.matchdict['link'])
    comment = [comment for comment in link.comments if \
            comment['author'] == request.session['login'] and \
            str(comment['date']) == request.matchdict['date']][0]
    link.comments.remove(comment)
    link.save()
    #request.session.flash(u"Unknow Error")
    return HTTPFound(location=request.route_path('comment', link=link._id))
예제 #8
0
파일: views.py 프로젝트: cyplp/wsgiwar2013
def contactsLinks(request):
    """
    My contacts links.
    """
    limit, page = limitAndPage(request)

    links = Link.view('contacts_links/all', limit=limit,
                      descending=True, skip=page*limit,
                      startkey=[request.session['login'], {}],
                      endkey=[request.session['login']], include_docs=True)

    return {'links': links, 'limit': limit, 'page': page}
예제 #9
0
파일: views.py 프로젝트: cyplp/wsgiwar2013
def userrss(request):
    """
    """
    try:
        user = User.get(request.matchdict['userid'])
    except couchdbkit.exceptions.ResourceNotFound:
        return HTTPNotFound()

    links = Link.view(
        'user_link/all',  limit=10, descending=True, key=user._id)

    return {'links': links, 'user': user}
예제 #10
0
파일: utils.py 프로젝트: cyplp/wsgiwar2013
def coherence():
    """
    """
    parser = argparse.ArgumentParser()
    parser.add_argument('--conf',
                        help='wsgi conf file')

    parser.add_argument('--userid',
                        help='user id')

    args = parser.parse_args()

    config = ConfigParser.RawConfigParser()
    config.read(args.conf)

    server = couchdbkit.Server(config.get('app:main', 'couchdb.url'))
    db = server.get_or_create_db(config.get('app:main','couchdb.db'))

    User.set_db(db)
    Link.set_db(db)


    users = User.view('user/all', descending=True)

    for user in users:
        print "user %s" % user._id

        links = Link.view('purge/all',
                          key=user._id,
                          include_docs=True)

        for link in links:
            print "checking %s" % link._id
            if link._id not in user.links:
                print "adding %s" % link._id
                user.links[link._id] = link.created

        user.save()
예제 #11
0
파일: views.py 프로젝트: cyplp/wsgiwar2013
def cloudTags(request):
    """
    Cloud Tags.
    """

    tmp = Link.view('tags/all',
                    group=True,
                    group_level=1
        )


    tags = {tag['key']: tag['value'] for tag in tmp}

    return {'tags' :tags}
예제 #12
0
파일: views.py 프로젝트: cyplp/wsgiwar2013
def rmlink(request):
    """
    Delete a link.
    """
    link = Link.get(request.matchdict['link'])

    if not link.private:
        user = User.get(request.session['login'])
        del(user.links[request.matchdict['link']])
        user.save()

    link.delete()

    return HTTPFound(location=request.route_path('mylinks'))
예제 #13
0
파일: views.py 프로젝트: cyplp/wsgiwar2013
def comment(request):
    """
    """
    link = Link.get(request.matchdict['link'])
    if request.method == 'POST':
        comment={
                'author' : request.session['login'],
                'date' : datetime.datetime.now(),
                'comment' : request.POST['comment']
                }
        link.comments.append(comment)
        link.save()
        request.session.flash(u"Comment Added!")
    return{'link': link}
예제 #14
0
파일: views.py 프로젝트: cyplp/wsgiwar2013
def user(request):
    """
    """
    try:
        user = User.get(request.matchdict['userid'])
    except couchdbkit.exceptions.ResourceNotFound:
        return HTTPNotFound()

    limit, page = limitAndPage(request)

    links = Link.view('user_link/all',  limit=limit,
                      skip=limit*page, descending=True,
                      startkey=[user._id, {}], endkey=[user._id],
                      include_docs=True)

    return {'links': links, 'user': user, 'limit': limit, 'page': page}
예제 #15
0
파일: views.py 프로젝트: cyplp/wsgiwar2013
def rss(request):
    """
    """
    links = Link.view('public/all',  limit=10, descending=True)
    return {'links': links}
예제 #16
0
파일: views.py 프로젝트: cyplp/wsgiwar2013
import couchdbkit
from couchdbkit.designer import push

from PIL import Image

from wsgiwars.models.user import User
from wsgiwars.models.link import Link
from wsgiwars.resources import linkAjax

settings = get_current_registry().settings

server = couchdbkit.Server(settings['couchdb.url'])
db = server.get_or_create_db(settings['couchdb.db'])

User.set_db(db)
Link.set_db(db)

for view in ['couchdb/_design/user',
             'couchdb/_design/public',
             'couchdb/_design/user_link',
             'couchdb/_design/my_link',
             'couchdb/_design/viewTag',
             'couchdb/_design/viewFollowers',
             'couchdb/_design/contacts_links',
             'couchdb/_design/tags',
             ]:
    push(view, db)

avatarSize = 128,128

def limitAndPage(request):
예제 #17
0
파일: views.py 프로젝트: cyplp/wsgiwar2013
def submitlink(request):
    """
    Submit a link.
    """
    # TODO check if not already submit by user

    tags = [tag.strip() for tag in request.POST['tags'].split(',')]

    link = Link()
    link.url = request.POST['link'].strip()
    link.title = request.POST['title'].strip()
    link.created = datetime.datetime.now()
    link.comment = request.POST['comment'].strip()
    link.userID = request.session['login']
    link.username = request.session['username']
    link.private = False  # TODO
    link.tags = tags

    if 'private' in request.POST:
        link.private = True

    link.save()

    if not link.private:
        user = User.get(request.session['login'])
        user.links[link._id] = link.created
        user.save()

    request.session.flash("link added !")
    return HTTPFound(location=request.route_path('home'))