示例#1
0
def view_list(request, id, template='generic/view_list.html'):
    def load_suggestions_async(suggestions):
        suggestions = suggestions.get_result()
        from georemindme.funcs import prefetch_refprops
        from geoalert.models import Suggestion
        suggestions = prefetch_refprops(suggestions, Suggestion.user, Suggestion.poi)
        suggestions_loaded = []
        for suggestion in suggestions:
            suggestions_loaded.append({
                                    'instance': suggestion,
                                    'has_voted':  Vote.objects.user_has_voted(request.user, suggestion.key()) if request.user.is_authenticated() else False,
                                    'vote_counter': Vote.objects.get_vote_counter(suggestion.key())
                                   }
                                  )
        return suggestions_loaded
   
    list = ListSuggestion.objects.get_by_id_querier(id, request.user)
    if list is None:
        raise Http404
    from google.appengine.ext import db
    from geoalert.models import Event
    from geovote.models import Vote, Comment
    suggestions_async = db.get_async(list.keys)
    if 'print' in request.GET:
        top_comments = Comment.objects.get_top_voted(list, request.user)
        vote_counter = Vote.objects.get_vote_counter(list.key())
        return render_to_response('print/view_list.html',
                                {'list': list,
                                 'suggestions': load_suggestions_async(suggestions_async),
                                 'vote_counter': vote_counter,
                                 'top_comments': top_comments,
                                },
                                context_instance=RequestContext(request)
                              )
    from geovote.api import get_comments
    query_id, comments_async = get_comments(request.user, instance=list, async=True)
    has_voted = Vote.objects.user_has_voted(request.user, list.key())
    vote_counter = Vote.objects.get_vote_counter(list.key())
    #comments = get_comments_list(request.user, list.id)
    top_comments = Comment.objects.get_top_voted(list, request.user)
    user_follower = list.has_follower(request.user)
    if not request.user.is_authenticated():
        pos = template.rfind('.html')
        template = template[:pos] + '_anonymous' + template[pos:]
    return render_to_response(template,
                                {'list': list,
                                 'has_voted': has_voted,
                                 'vote_counter': vote_counter,
                                 'user_follower': user_follower,
                                 'suggestions': load_suggestions_async(suggestions_async),
                                 'comments': Comment.objects.load_comments_from_async(query_id, comments_async, request.user),
                                 'top_comments': top_comments
                                },
                                context_instance=RequestContext(request)
                              )
示例#2
0
def suggestion_profile(request, slug, template='generic/suggestionprofile.html'):
    """Devuelve el perfil de una sugerencia, comprueba la visibilidad de una funcion
        
            :param id: identificador de la sugerencia
            :type id: :class:`ìnteger`
    """
    
    suggestion = Suggestion.objects.get_by_slug_querier(slug, querier=request.user)
    if suggestion is None:
        raise Http404 
    from geovote.models import Vote, Comment
    from geolist.models import ListSuggestion
    from georemindme.funcs import single_prefetch_refprops, prefetch_refList, prefetch_refprops
    if 'print' in request.GET:
        suggestion = single_prefetch_refprops(suggestion, Suggestion.user, Suggestion.poi)
        vote_counter = Vote.objects.get_vote_counter(suggestion.key())
        top_comments = Comment.objects.get_top_voted(suggestion, request.user)
        return render_to_response('print/suggestionprofile.html',
                        {'suggestion': suggestion,
                         'vote_counter': vote_counter,
                         'top_comments': top_comments,
                        },
                        context_instance=RequestContext(request)
                      )
            
    from geovote.api import get_comments
    lists = ListSuggestion.objects.get_by_user(user=request.user, querier=request.user, all=True)
    query_id, comments_async = get_comments(request.user, suggestion, async=True)
    suggestion.prefetch(Suggestion.user, Suggestion.poi)
    has_voted = Vote.objects.user_has_voted(request.user, suggestion.key())
    vote_counter = Vote.objects.get_vote_counter(suggestion.key())
    user_follower = suggestion.has_follower(request.user)
    top_comments = Comment.objects.get_top_voted(suggestion, request.user)
    in_lists = ListSuggestion.objects.get_by_suggestion(suggestion, request.user)
    # construir un diccionario con todas las keys resueltas y usuarios
    in_lists = [l.to_dict(resolve=False) for l in in_lists]
    # listas del usuario
    lists = [l for l in lists if not suggestion.key() in l.keys]
    lists = model_plus.prefetch(lists, ListSuggestion.user)
    lists = [l.to_dict(resolve=False) for l in lists]
    # construir un diccionario con todas las keys resueltas y usuarios
    if not request.user.is_authenticated():
            pos = template.rfind('.html')
            template = template[:pos] + '_anonymous' + template[pos:]
    return render_to_response(template, {
                                        'suggestion': suggestion,
                                        'comments': Comment.objects.load_comments_from_async(query_id, comments_async, request.user),
                                        'has_voted': has_voted,
                                        'in_lists': in_lists,
                                        'lists': lists,
                                        'vote_counter': vote_counter,
                                        'user_follower': user_follower,
                                        'top_comments': top_comments,
                                        },
                               context_instance=RequestContext(request))
示例#3
0
def get_comments(request, kind):
    """
    Obtiene todas los comentarios visibles de un evento
    Parametros POST
        instance_id: evento a mostrar
        page: pagina a mostrar
        query_id: id de la consulta de pagina
    """
    instance_id = request.POST['instance_id']
    query_id = request.POST.get('query_id', None)
    page = request.POST.get('page', 1)
    comments = geovote.get_comments(request.user, instance_id, kind, query_id, page) 
    
    from libs.jsonrpc.jsonencoder import JSONEncoder
    return HttpResponse(simplejson.dumps(comments, cls=JSONEncoder),
                        mimetype="application/json")
示例#4
0
def get_comments(request, kind):
    """
    Obtiene todas los comentarios visibles de un evento
    Parametros POST
        instance_id: evento a mostrar
        page: pagina a mostrar
        query_id: id de la consulta de pagina
    """
    instance_id = request.POST['instance_id']
    query_id = request.POST.get('query_id', None)
    page = request.POST.get('page', 1)
    comments = geovote.get_comments(request.user, instance_id, kind, query_id,
                                    page)

    from libs.jsonrpc.jsonencoder import JSONEncoder
    return HttpResponse(simplejson.dumps(comments, cls=JSONEncoder),
                        mimetype="application/json")
 def get_suggestion(self, request):
     """
     Obtiene la informacion de la sugerencia solicitada
        
         :param request: Parametros pasados a la peticion
         :type request: :class:`GetSuggestionRequest`
         :returns: :class:`Suggestion`
         :raises: :class:`ApplicationError`
     """
     self._login_required()
     
     from geovote.api import get_comments
     suggestion = SuggestionModel.objects.get_by_id_querier(request.id, querier=self.user)
     query_id, comments_async = get_comments(self.user, suggestion.id, 'Event', async=True)
     suggestion = single_prefetch_refprops(suggestion, SuggestionModel.user, SuggestionModel.poi)
     has_voted = Vote.objects.user_has_voted(self.user, suggestion.key())
     vote_counter = Vote.objects.get_vote_counter(suggestion.key())
     user_follower = suggestion.has_follower(self.user)
     top_comments = Comment.objects.get_top_voted(suggestion, self.user)
     in_lists = ListSuggestion.objects.get_by_suggestion(suggestion, self.user)
     in_lists = [l.to_dict(resolve=False) for l in in_lists]
     comments = Comment.objects.load_comments_from_async(query_id, comments_async, self.user)[1]
     # TODO: ENVIAR LOS COMENTARIOS AL MOVIL
     return Suggestion(id = suggestion.id,
                       name=suggestion.name,
                       description=suggestion.description,
                       poi_lat=suggestion.poi.location.lat,
                       poi_lon=suggestion.poi.location.lon,
                       poi_id=suggestion.poi.id,
                       google_places_reference = suggestion.poi.google_places_reference,
                       modified = int(mktime(suggestion.modified.utctimetuple())),
                       created = int(mktime(suggestion.created.utctimetuple())),
                       username = suggestion.user.username,
                       lists = [List(id=l['id'], name=l['name']) for l in in_lists],
                       comments = [Comment(id=c['id'],
                                           username=c['username'],
                                           message=c['msg'],
                                           created=c['created']) for c in comments],
                       has_voted=has_voted,
                       vote_counter=vote_counter,
                       user_follower=user_follower,
                      )
示例#6
0
def view_list(request, id, template='generic/view_list.html'):
    def load_suggestions_async(suggestions):
        suggestions = suggestions.get_result()
        from georemindme.funcs import prefetch_refprops
        from geoalert.models import Suggestion
        suggestions = prefetch_refprops(suggestions, Suggestion.user,
                                        Suggestion.poi)
        suggestions_loaded = []
        for suggestion in suggestions:
            suggestions_loaded.append({
                'instance':
                suggestion,
                'has_voted':
                Vote.objects.user_has_voted(request.user, suggestion.key())
                if request.user.is_authenticated() else False,
                'vote_counter':
                Vote.objects.get_vote_counter(suggestion.key())
            })
        return suggestions_loaded

    list = ListSuggestion.objects.get_by_id_querier(id, request.user)
    if list is None:
        raise Http404
    from google.appengine.ext import db
    from geoalert.models import Event
    from geovote.models import Vote, Comment
    suggestions_async = db.get_async(list.keys)
    if 'print' in request.GET:
        top_comments = Comment.objects.get_top_voted(list, request.user)
        vote_counter = Vote.objects.get_vote_counter(list.key())
        return render_to_response(
            'print/view_list.html', {
                'list': list,
                'suggestions': load_suggestions_async(suggestions_async),
                'vote_counter': vote_counter,
                'top_comments': top_comments,
            },
            context_instance=RequestContext(request))
    from geovote.api import get_comments
    query_id, comments_async = get_comments(request.user,
                                            instance=list,
                                            async=True)
    has_voted = Vote.objects.user_has_voted(request.user, list.key())
    vote_counter = Vote.objects.get_vote_counter(list.key())
    #comments = get_comments_list(request.user, list.id)
    top_comments = Comment.objects.get_top_voted(list, request.user)
    user_follower = list.has_follower(request.user)
    if not request.user.is_authenticated():
        pos = template.rfind('.html')
        template = template[:pos] + '_anonymous' + template[pos:]
    return render_to_response(template, {
        'list':
        list,
        'has_voted':
        has_voted,
        'vote_counter':
        vote_counter,
        'user_follower':
        user_follower,
        'suggestions':
        load_suggestions_async(suggestions_async),
        'comments':
        Comment.objects.load_comments_from_async(query_id, comments_async,
                                                 request.user),
        'top_comments':
        top_comments
    },
                              context_instance=RequestContext(request))