Beispiel #1
0
def tagrss(request):
    """
    """
    links = Link.view('viewTag/all', limit=10, descending=True,
                      startkey=[request.matchdict['tag'], {}],
                      endkey=[request.matchdict['tag']])
    return {'links': links}
Beispiel #2
0
def rmlink(request):
    """
    Delete a link.
    """
    link = Link.get(request.matchdict['link'])
    link.delete()
    return HTTPFound(location=request.route_path('mylinks'))
Beispiel #3
0
def link(request):
    """
    """
    link = Link.get(request.matchdict['link'])

    if link.private:
        raise HTTPNotFound()

    return {'link': link}
Beispiel #4
0
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}
Beispiel #5
0
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"
Beispiel #6
0
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}
Beispiel #7
0
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))
Beispiel #8
0
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}
Beispiel #9
0
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}
Beispiel #10
0
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()
Beispiel #11
0
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}
Beispiel #12
0
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'))
Beispiel #13
0
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}
Beispiel #14
0
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}
Beispiel #15
0
def rss(request):
    """
    """
    links = Link.view('public/all',  limit=10, descending=True)
    return {'links': links}
Beispiel #16
0
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):
Beispiel #17
0
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'))