Пример #1
0
def content_list_page(request, content_type="blog"):
    page_url = "".join(("/", content_type))
    errors={}
    
    try:    
        if request.method == 'GET':
            page = request.GET.get('page', None)
            size = request.GET.get('size', None)
            tag = request.GET.get('tag', None)
            month = request.GET.get('month', None)
            year = request.GET.get('year', None)
            
            posted_after = None
            posted_before = None
            
            if (month and year):
                if (int(month) > 11):
                    next_month = '1'
                    next_year = str(int(year) + 1)
                    posted_after = convertFormToDateTime("".join((month,"/01/",year," 00:01")))
                    posted_before = convertFormToDateTime("".join((next_month,"/01/",next_year," 00:01")))
                else:
                    next_month = str(int(month) + 1)     
                    posted_after = convertFormToDateTime("".join((month,"/01/",year," 00:01")))
                    posted_before = convertFormToDateTime("".join((next_month,"/01/",year," 00:01")))
                
            # Persist the filter information.  Keep it if we're moving across pages.
            if (tag is not None):
                request.session[content_type + '-include-tags'] = tag
            elif (page is not None):
                tag = request.session.get(content_type + '-include-tags', None)
                
            if (posted_after is not None):
                request.session[content_type + '-posted-after'] = posted_after
            elif (page is not None):
                posted_after = request.session.get(content_type + '-posted-after', None)
            if (posted_before is not None):
                request.session[content_type + '-posted-before'] = posted_before
            elif (page is not None):
                posted_before = request.session.get(content_type + '-posted-before', None)
            
            if not page:
                page = '1'
            if not size:
                size = '5'
                
            content_list_response = client_get_contents(type = content_type,
                                                        page=(int(page)-1), size=int(size), 
                                                        include_tags = tag,
                                                        posted_before=posted_before, posted_after=posted_after,
                                                        sort_by="postingDate", ascending=False)
            
            context = {'page': int(page),
                       'size': int(size),
                       'contents' : content_list_response.contents,
                       'page_url' : page_url,
                       'errors' : errors}
            context.update(pageDisplay(page, size, content_list_response.count))
            context.update(getContentTagContext(request, content_type))
            context.update(getContentMonthContext(request))
            
            c = RequestContext(request, context)
            
            if (content_type == "podcast"):
                return render_to_response('podcast_list.html', c)
            elif (content_type == "video"):
                return render_to_response('video_list.html', c)
            
            return render_to_response('blog_list.html', c)
            
    except Exception:      
        logger.error("Exception when rending content list page:") 
        logger.error(traceback.print_exc(8))
        raise Exception  
Пример #2
0
def get_user_profile(request, id = None, name = None):

    try:        
        # Check to see if we're coming here from a GET.  If so, we've got work to do.
        if request.method == 'GET':
            
            service_response = client_get_user_by_id(id, request.user.session_id)
            
            if (not service_response.status.success):
                logger.warning("Error when retrieving user profile: " + service_response.status.message)
                raise BaseException() 
            elif (not service_response.reckoner_user):
                raise Http404
            elif (request.path != service_response.reckoner_user.getURL()):
                return HttpResponseRedirect(service_response.reckoner_user.getURL())
            else:         
                page_url = service_response.reckoner_user.getURL()
                             
                # Pull the relevant variables from the request string.
                page = request.GET.get('page', "1")
                size = request.GET.get('size', None)
                tab = request.GET.get('tab', None)
                
                # Persist the specified variables in the session for when the user navigates away and back.
                # Otherwise, pull the information out of the session                    
                if (size):
                    request.session['user-size'] = size
                else:
                    size = request.session.get('user-size', '15')         
                    
                if (tab):
                    request.session['user-tab'] = tab
                else:
                    tab = request.session.get('user-tab', 'newest') 
                
                reckonings_response = client_get_user_reckonings(id, int(page)-1, size, request.user.session_id)
                comments_response = client_get_user_comments(id, int(page)-1, size, request.user.session_id)
                votes_response = client_get_user_reckoning_votes(id, int(page)-1, size, request.user.session_id)
                tracking_response = client_get_favorited_reckonings(id, int(page)-1, size, request.user.session_id)
                
                # Execute the correct action based on the selected tab and info.  Valid tabs:
                #  * tracking, comments, votes, reckonings
                if (tab == "tracking"):
                    reckoning_count = tracking_response.count
                    reckonings = tracking_response.reckonings
                elif (tab == "comments"):
                    reckoning_count = comments_response.count                    
                    reckonings = comments_response.reckonings
                elif (tab == "votes"):
                    reckoning_count = votes_response.count                    
                    reckonings = votes_response.reckonings
                else:
                    tab = 'reckonings'
                    reckoning_count = reckonings_response.count
                    reckonings = reckonings_response.reckonings
                            
                context = {'profile_user' : service_response.reckoner_user,
                           'reckonings' : reckonings,
                           'page' : int(page),
                           'size' : int(size),
                           'tab'  : tab,
                           'page_url' : page_url,
                           'reckoning_count' : reckonings_response.count,
                           'comment_count' : comments_response.comment_count,
                           'vote_count' : votes_response.count,
                           'tracking_count' : tracking_response.count}
                
                context.update(pageDisplay(page, size, reckoning_count))
                c = RequestContext(request, context)
            
                return render_to_response('user_profile.html', c)
    except Exception:
        logger.error("Exception when showing a user profile:") 
        logger.error(traceback.print_exc(8))
        raise Exception