예제 #1
0
파일: views.py 프로젝트: Lapeth/timeline
def createEvent(request):
    errors = []
    if request.method == "POST":
        try:
            if 'save' in request.POST or 'publish' in request.POST:
                Query.createEvent(request)
            return HttpResponseRedirect("%s/event/" % pathPrefix)
        except PermissionDenied as e:
            errors.append(e)
    return render(request, "event.html", {
        "nav":"events",
        "user": request.user,
        "new": True,
        "permissions": request.user.get_all_permissions(),
        "errors": errors,
        "languages": Query.listLanguages()
    })
예제 #2
0
파일: views.py 프로젝트: Lapeth/timeline
def editEvent(request, eventId, revision=None):
    
    if request.method == "POST":
        if not 'cancel' in request.POST:
            (event, version) = Query.updateEvent(request, eventId, revision)
            if 'redirect' in request.POST:
                return HttpResponseRedirect(request.POST['redirect'])
            if event is not None:
                revision = version.revision if version is not None else event.publicRevision
                return HttpResponseRedirect("%s/event/%s/%s" % (pathPrefix, event.id, revision))
        return HttpResponseRedirect("%s/event/" % pathPrefix)
    
    if request.method == "DELETE":
        if revision is not None:
            event = Query.deleteEventVersion(request, eventId, revision)
            return HttpResponseRedirect("%s/event/%s/%s" % (pathPrefix, event.id, event.publicRevision))
        else:
            Query.deleteEvent(request, eventId)
            return HttpResponseRedirect("%s/event/" % pathPrefix)
            
            
    
    event = EventBase.objects.filter(id=eventId).get()
        
    if revision is None:
        revision = event.publicRevision
    eventVersion = event.getVersion(revision)
    
    revisions = {}
    for version in event.getVersions():
        revisions[version.revision] = version.created
    
    user = request.user

    return render(request, "event.html", {
        "event": event,
        "eventVersion": eventVersion,
        "revisions": revisions,
        "displayedRevision": int(revision),
        "currentRevision": event.getCurrentVersion().revision,
        "nav":"events",
        "permissions": request.user.get_all_permissions(),
        "user": request.user,
        "new": False,
        "languages": Query.listLanguages()
    })
예제 #3
0
파일: views.py 프로젝트: Lapeth/timeline
def editTag(request, tagId, revision=None):
    tag = TagBase.objects.filter(id=tagId).get()
    
    if request.method == "POST":
        if not 'cancel' in request.POST:
            (tag,version) = Query.updateTag(request, tagId, revision)
            if 'redirect' in request.POST:
                return HttpResponseRedirect(request.POST['redirect'])
            if tag is not None:
                revision = version.revision if version is not None else tag.publicRevision
                return HttpResponseRedirect("%s/tag/%s/%s" % (pathPrefix, tag.id, revision))
        return HttpResponseRedirect("%s/tag/" % pathPrefix)
    
    elif request.method == "DELETE":
        if revision is not None:
            tag = Query.deleteTagVersion(request, tagId, revision)
            return HttpResponseRedirect("%s/tag/%s/%s" % (pathPrefix, tag.id, event.publicRevision))
        else:
            Query.deleteTag(request, tagId)
            return HttpResponseRedirect("%s/tag/" % pathPrefix)
            
    
    else:
        
        
        if revision is None:
            revision = tag.publicRevision
        tagVersion = tag.getVersion(revision)
        
        revisions = {}
        for version in tag.getVersions():
            revisions[version.revision] = version.created

        return render(request, "tag.html", {
            "tag": tag,
            "tagVersion": tagVersion,
            "revisions": revisions,
            "displayedRevision": int(revision),
            "currentRevision": tag.getCurrentVersion().revision,
            "nav":"tags",
            "permissions": request.user.get_all_permissions(),
            "user": request.user,
            "new": False,
            "languages": Query.listLanguages()
        })
예제 #4
0
파일: views.py 프로젝트: Lapeth/timeline
def listTags(request):
    isJSON = request.GET.get('f') == "json"
    (tags,pagination) = Query.listTags(request, isJSON)
    
    if isJSON:
        return HttpResponse(JSONSerializer().serialize(tags))
    
    languages = Query.listLanguages()
    
    return render(request, "tags.html", {
        "tags": tags,
        "nav": "tags",
        "pagination": pagination,
        "user": request.user,
        "permissions": request.user.get_all_permissions(),
        "languages": languages,
        "language": request.GET.get("l")
    })
예제 #5
0
파일: views.py 프로젝트: Lapeth/timeline
def listEvents(request):
    isJSON = request.GET.get('f') == "json"
    (events, pagination) = Query.listEvents(request, isJSON)
    
    if isJSON:
        return HttpResponse(JSONSerializer().serialize(events))
    
    path = "/event/"
    if len(request.GET):
        i = 0
        for key in request.GET:
            if key != 'p':
                value = request.GET[key]
                if not isinstance(value, list):
                    value = [value]
                for v in value:
                    path += "&" if i > 0 else "?";
                    path += key + "=" + v
                    i += 1
        ppath = path + ("?" if i == 0 else "&")
    else:
        ppath = "?"
        
    query = Query.getQuery(request)
    
    data = {
        "events":events,
        "nav":"events",
        "pagination": pagination,
        "query": query or '',
        "path": path,
        "ppath": ppath
    }
    data["user"] = request.user
    data["permissions"] = request.user.get_all_permissions()
    data["languages"] = Query.listLanguages()
    data["language"] = request.GET.get("l")
    return render(request, "events.html", data, context_instance=RequestContext(request))
예제 #6
0
파일: views.py 프로젝트: Lapeth/timeline
def lookupWikipedia(request):
    
    def excludeWikiItem(item):
        excludeDescriptionBeginnings = ['This is a redirect from a title with another method of capitalisation.']
        for exclusion in excludeDescriptionBeginnings:
            if item['description'].startswith(exclusion):
                return True
        return False
    
    if request.method == "GET" and 'q' in request.GET and 'l' in request.GET:
        query = request.GET['q']
        language = request.GET['l']
        if Query.hasLanguage(language):
            prefix = "https://%s.wikipedia.org" % language
            wikiprefix = "%s/wiki/" % prefix
            data = requests.get("%s/w/api.php" % prefix, params={
                'action': 'opensearch',
                'format': 'json',
                'namespace': 0,
                'limit': 10,
                'search': query
            })
            if data:
                obj = data.json()
                if obj:
                    items = []
                    term = obj[0]
                    titles = obj[1]
                    descriptions = obj[2]
                    links = obj[3]
                    count = min(len(titles), len(descriptions), len(links))
                    print links
                    for i in range(0, count-1):
                        item = {'title':titles[i],
                                    'description':descriptions[i],
                                    'links':links[i]}
                        if links[i].startswith(wikiprefix):
                            item['key'] = links[i][len(wikiprefix):]
                        if not excludeWikiItem(item):
                            items.append(item)
                        
                    return HttpResponse(JSONSerializer().serialize(items))
예제 #7
0
파일: views.py 프로젝트: Lapeth/timeline
def listEvents(request):
    (events,p) = Query.listEvents(request, True)
    return HttpResponse(JSONSerializer().serialize(events))
예제 #8
0
파일: views.py 프로젝트: Lapeth/timeline
def listTags(request):
    (tags,p) = Query.listTags(request, True)
    return HttpResponse(JSONSerializer().serialize(tags))