Exemple #1
0
def create_project(request):
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            import datetime
            category = get_object_or_404( Category, pk = 'Projects' )
            forum_thread = Thread( topic = form.cleaned_data['title'], poster = request.user, category = category, description = "Login to discuss this project.")
            forum_thread.save()
            wiki_page = Page( title = form.cleaned_data['title'] )
            wiki_page.save()
            newproj = Project( title = form.cleaned_data['title'], owner = form.cleaned_data['owner'], last_update = datetime.datetime.now(), status = form.cleaned_data['status'], description = form.cleaned_data['description'],documentation = form.cleaned_data['documentation'],wiki_page = wiki_page,forum_thread = forum_thread)       
            newproj.save()
            return HttpResponseRedirect("/projects/"+newproj.slug+"/")
    form = ProjectForm()
    return render('projects/create', dict(form = form))
Exemple #2
0
def save_page(request, page_title):
    content = request.POST["content"]
    try:
        page = Page.objects.get(pk = page_title)
        from difflib import context_diff
        import re
        diff = context_diff(page.content.splitlines(), content.splitlines(), 3)
        before_start = re.compile(r'[*]{3}\s(?P<start>[0-9]+)[,](?P<end>[0-9]+)\s[*]{3}')
        after_start = p = re.compile(r'[-]{3}\s(?P<start>[0-9]+)[,](?P<end>[0-9]+)\s[-]{3}')
        before = ''
        after = ''
        for line in diff:
            if(before_start.search(line)):
                before += line + '\n'
                while True:
                    try:
                        line = diff.next()
                    except StopIteration:
                        break
                    if (after_start.search(line)):
                        break
                    if( line.startswith('!') ):
                        line = '<span class="reddiff">' + line + '</span>'
                    before += line + '\n'
            if( after_start.search(line) ):
                after += line + '\n'
                while True:
                    try:
                        line = diff.next()
                    except StopIteration:
                        break
                    if( before_start.search(line) ):
                        break
                    if( line.startswith('!') or line.startswith('+') ):
                        line = '<span class="greendiff">' + line + '</span>'
                    after += line  + '\n'

        edit = Edit(editor = request.user, before = before, after = after, pub_date=datetime.datetime.now())
        edit.save()
        page.content = content
        page.edits.add(edit)
    except Page.DoesNotExist:
        page = Page( title = page_title, content = content, last_edit=datetime.datetime.now())
    page.save()
    return HttpResponseRedirect("/wiki/"+page.slug+"/")
Exemple #3
0
def create_page(request):
    if request.method == 'POST':
        page = Page( title = request.POST['title'], content = request.POST['content'], last_edit=datetime.datetime.now())
        page.save()
        return HttpResponseRedirect("/wiki/"+page.slug+"/")
    return render("wiki/new")