Beispiel #1
0
def user(request,user_id):
    """
    texts from user user_id
    """
    user = get_object_or_404(User,pk = user_id)
    if user == request.user:
        creator = None
        exclude_all_have_perm = True        
    else:
        creator = user
        exclude_all_have_perm = False
    texts = Text.objects.get_by_perm(request.user, 'can_view_local_text', creator_user = creator, exclude_all_have_perm = exclude_all_have_perm).order_by('-id')
    if request.user.is_authenticated():
        text_max_number = request.user.get_profile().get_max_number_text()
    else:
        text_max_number = 0
        
        
    paginator = Paginator(texts, 10) # Show 25 contacts per page

#    texts2 = texts._clone()
#    paginator = Paginator(texts2,paginate_by)

    # Make sure page request is an int. If not, deliver first page.
    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1
    try:
        pageobj = paginator.page(page)
    except (EmptyPage, InvalidPage):
        pageobj = paginator.page(paginator.num_pages)
        
    texts_page_subset = pageobj.object_list
    for text in texts_page_subset :
        last_version = text.get_latest_version()
        nbcomments,nbreplies=last_version.get_visible_commentsandreplies_count(request.user)
        setattr(text,'nbcomments',nbcomments)
        setattr(text,'nbreplies',nbreplies)
    # TODO : 404 if not my workspace and not texts
    return render_to_response('texts/list.html', {
                           'texts' : texts_page_subset,
                           'watched_user'  : user,
                           'user_can_create_text'    : user_can_create_text(request.user),
                           'text_max_number' : text_max_number,                           
                           'paginator' : paginator,                           
                           'page' : pageobj,                           
                           },
                          context_instance=RequestContext(request))
Beispiel #2
0
class UploadForm(BlockForm):
    file = forms.FileField(
                           label= ugettext_lazy(u"File"),
                           )


def cleanup_extension(name):
    if len(name) > 4 and name[-4] == ".":
        return name[:-4]
    else:
        return name

# TODO : http://code.djangoproject.com/ticket/5925
# use reverse('uauthorized') 
@user_passes_test(lambda u: user_can_create_text(u),login_url = '/unauthorized')
def upload(request):
    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        if form.is_valid():
            data = form.cleaned_data
            file_name = data['file'].name
            file_content = data['file'].read()
            try:
                html_res_content,images = convert(file_content,'html')
                xhtml_res_content,_not_used_ = convert(file_content,'xhtml')
            except:                
                if dj_settings.DEBUG:
                    raise
                else:
                    # TODO : manage errors : warn admins & co