Пример #1
0
def more_profiles(request, other_user_id, last_profile, type):

    other_user = User.objects.get( pk = other_user_id )
    more_num = 10
    last_prof = int(last_profile)

    template = """<tr><td>
       <div class="profiles-item">
       <div class="avatar span-2"><a href="%s" title="%s %s"><img src="%s" alt="%s" width="70" height="70" /></a></div>
       <div class="profiles-details span-5 last"><a href="%s" title="%s %s">%s %s</a></div>
       <div class="profiles-about span-10 last">%s</div>
       <div class="separator span-10 last"></div>
       </div>
       </td></tr> """

    users = []

    if type == 'Seguidores':
        followers = FollowAuthor.objects.filter( UserTo = other_user ).order_by('-id')
        for  follow in followers:
            if follow.UserFrom:
                users.append( follow.UserFrom )
    elif type == 'Seguindo':
        followings = FollowAuthor.objects.filter( UserFrom = other_user ).order_by('-id')
        for  follow in followings:
            if follow.UserTo:
                users.append( follow.UserTo )

    users = users[last_prof:last_prof+more_num]

    htmlOutput = ""

    for user in users:
        link_prof_details = reverse('profile_detail', args=(user,))

        try:
            name = user.get_profile().first_name
            lastname = user.get_profile().last_name
            small_about = user.get_profile().get_small_about()
        except:
            name = user.username
            lastname = ''
            small_about = ''

        username = user.username
        avatar = avatar_url(user, 70)
        if len(name) == 0:
            name = username
        htmlOutput += template % ( link_prof_details, name, lastname, avatar, username, link_prof_details, name, lastname,
                               name, lastname, small_about )


    dajax = Dajax()
    dajax.append('#list-profiles','innerHTML', htmlOutput)
    dajax.assign('#last_profile','innerHTML', last_prof+len(users))

    return dajax.json()
Пример #2
0
def more_updates(request, last_update):

    media_url = '/site_media/'
    more_num = 10
    last_up = int(last_update)

    template_post = """<div class="update-item span-14"><div class="update-item span-14">
        <div class="update-avatar span-2"><a href="%s" title="%s %s"><img src="%s" alt="%s" width="70" height="70" /></a></div>
        <div class="update-name span-5 last"><a href="%s" title="%s %s">%s %s</a></div>

        <a class="span-10 update-posts-title last" href="%s">%s</a>
        <div class="span-10 update-posts-description last">
            %s
        </div>
        </div>
        </div>"""

    template_pub  = """<div class="update-item span-14"><div class="update-avatar span-2"><a href="%s" title="%s %s"><img src="%s" alt="%s" width="70" height="70" /></a></div>
        <div class="update-name span-3 last"><a href="%s" title="%s %s">%s %s</a></div>
        <div class="update-pub-cover span-4">
        <a href="%s">
        <img src="%s%s" href="%s" alt="%s"/></a>
        </div>
        <div class="update-pub-title span-10 last">
        <a href="%s">%s</a>
        </div>
        <div class="update-pub-description span-10 last ">%s</div>
        </div>
        """

    followings = getFollowings(request, request.user)

    updates = getUpdates(request, followings)[last_up:last_up+more_num]

    htmlOutput = ""

    for update in updates:

        if update.type == '1':
            link_prof_details_pub  = reverse('profile_detail', args=(update.publication.author,))
            link_details_pub       = reverse('publication_details', args=(update.publication.author,update.publication.id,))
            name = update.publication.author.get_profile().first_name
            lastname = update.publication.author.get_profile().last_name
            text_pub = update.publication.get_small_text()
            username = update.publication.author.username
            avatar_pub = avatar_url(update.publication.author, 70)
            htmlOutput += template_pub % ( link_prof_details_pub, name, lastname, avatar_pub, username  ,link_prof_details_pub, name, lastname,
                                           name, lastname, link_details_pub, media_url, update.publication.get_thumbnail150_name(),
                                           link_details_pub, update.publication.title, link_details_pub, update.publication.title,
                                           text_pub )
        else:
            link_prof_details_post = reverse('profile_detail', args=(update.post.author,))
            link_post_url          = update.post.get_absolute_url()
            name = update.post.author.get_profile().first_name
            lastname = update.post.author.get_profile().last_name
            text_post = update.post.get_small_text()
            username = update.post.author.username
            avatar_post = avatar_url(update.post.author, 70)
            htmlOutput += template_post % ( link_prof_details_post, name, lastname, avatar_post, username, link_prof_details_post,
                                           name, lastname,
                                           name, lastname, link_post_url, update.post.title, text_post )

    dajax = Dajax()
    dajax.append('#list-updates','innerHTML', htmlOutput)
    dajax.assign('#last_update','innerHTML', last_up+len(updates))

    return dajax.json()
Пример #3
0
def more_publications(request, other_user_id, last_publication):
    publications = []

    more_num = 6

    other_user = User.objects.get( pk = other_user_id )
    media_url = '/site_media/'

    last_pub = int(last_publication)

    if other_user == request.user:
        is_me = True
    else:
        is_me = False

    template = """<div class="list-pub-item span-14">
                    <div class="span-4 publications-cover">
                        <a href="%s">
                            <img src="%s%s" href="%s" alt="%s"/>
                        </a>
                    </div>

                    <div class="span-8 list-pub-title">
                        <a href="%s">%s</a>
                    </div>

                    <div class="span-8 last list-pub-description">%s</div>
                    <div class="list-pub-subtitle"> %s </div>
                  """

    if is_me:
        template += """<div class="span-1 list-pub-button"><a href="%s" ><img src="%simages/publication_edit.png" title="Editar Publica&ccedil;&atilde;o"></img></a></div>
                       <div class="span-1 list-pub-button last"><a href="%s" onclick=" ConfirmChoice('%s'); return false;"><img src="%simages/publication_delete.png" title="Excluir Publica&ccedil;&atilde;o"></img></a></div>"""


    template += "</div>"

    if request.user.is_authenticated():
        if is_me == True:
            publications = Publication.objects.filter( author = other_user ).order_by('-date_added')[last_pub:last_pub+more_num]
        else:
            request.user.get_profile().calc_age()
            publications = Publication.objects.filter( author = other_user, rated__lte=request.user.get_profile().age ).order_by('-date_added')[last_pub:last_pub+more_num]
    else:
        publications = Publication.objects.filter( author = other_user, is_public=True ).order_by('-date_added')[last_pub:last_pub+more_num]

    htmlOutput = ""

    for publication in publications:

        str_pages = str(publication.nr_pages)
        if publication.nr_pages > 1:
            str_pages += ' P&aacute;ginas'
        else:
            str_pages += ' P&aacute;gina'

        link_details = ''
        if publication.status != 0:
            link_details = reverse('publication_details', args=(publication.author,publication.id,))

        link_edit = reverse('edit_publication', args=(publication.id,))
        link_destroy = reverse('destroy_publication', args=(publication.id,))
        pub_image = 'images/cover_default150.png'
        if publication.status != 0:
            pub_image = publication.get_thumbnail150_name()

        #import pdb; pdb.set_trace()

        if is_me:
            htmlOutput += template % ( link_details, media_url, pub_image, link_details, publication.title,
            link_details, publication.title, publication.get_small_text(), str_pages, link_edit, media_url, link_destroy, link_destroy ,media_url )
        else:
            htmlOutput += template % ( link_details, media_url, pub_image, link_details, publication.title,
            link_details, publication.title, publication.get_small_text(), str_pages,  )


    dajax = Dajax()
    dajax.append('#list-publications','innerHTML', htmlOutput)
    dajax.assign('#last_publication','innerHTML', last_pub+len(publications))

    return dajax.json()
Пример #4
0
def more_posts(request, other_user_id, last_post):
    publications = []

    more_num = 10

    other_user = User.objects.get(pk=other_user_id)
    media_url = "/site_media/"

    last_post = int(last_post)

    if other_user == request.user:
        is_me = True
    else:
        is_me = False

    template = """<div class="blog-post-item"><a class="span-5 list-posts-title" href="%s">%s</a>
                <div class="list-posts-subtitle last">%s</div>"""
    if is_me:
        template += """<div class="span-2 list-posts-buttons">
                    <div class="span-1 list-posts-button"><a href="%s" ><img src="%simages/publication_edit.png" title="Editar Post"></img></a></div>
                    <div class="span-1 list-posts-button last"><a href="%s" onclick=" ConfirmChoice('%s'); return false;"><img src="%simages/publication_delete.png" title="Excluir Post"></img></a></div>
                    </div>"""

    template += """<div class="span-10 list-posts-description last">
                        %s
                </div>"""

    template += """<div class="separator span-13 last"></div></div>"""

    posts = Post.objects.filter(status=2).select_related(depth=1).order_by("-publish")

    if is_me == True:
        posts = posts.filter(author=request.user)[last_post : last_post + more_num]
    else:
        posts = posts.filter(author=other_user)[last_post : last_post + more_num]

    htmlOutput = ""

    for post in posts:

        post_url = post.get_absolute_url()
        date_posted = post.publish.strftime("%d/%m/%Y")
        post_text = post.get_small_text()
        link_edit = reverse("blog_edit", args=(post.id,))
        link_destroy = reverse("blog_edit", args=(post.id,))

        if is_me:
            htmlOutput += template % (
                post_url,
                post.title,
                date_posted,
                link_edit,
                media_url,
                link_destroy,
                link_destroy,
                media_url,
                post_text,
            )
        else:
            htmlOutput += template % (post_url, post.title, date_posted, post_text)

    dajax = Dajax()
    dajax.append("#list-posts", "innerHTML", htmlOutput)
    dajax.assign("#last_post", "innerHTML", last_post + len(posts))

    return dajax.json()