Esempio n. 1
0
__author__ = 'janak'

from django.views.generic import ListView
from internalresources.models import InternalResource
from django.core import serializers
from django.http import HttpResponse
from utils.log_helper import init_logger

logger = init_logger(__name__)


# Class to add an internal resource to a project. This is called dynamically via Ajax
class SearchTeamMembers(ListView):
    def get(self, request, *args, **kwargs):
        try:
            self.object_list = ""
            starts_with = request.GET['term']
            # Direct key access in QueryDict returns the last object. We need all the values in the list
            # thus we use the getlist method on the GET data elements.
            user_ids = request.GET.getlist('users[]')
            #Params received are in unicode, so we parse and convert string to int using list comprehension
            #and since the string can be empty, int conversion will fail, we handle that via conditional logic
            users_to_exclude = [int(user) for user in user_ids if user != '']

            if starts_with:
                internal_resource_list = serializers.serialize('json', InternalResource.objects.all().filter(
                    first_name__istartswith=starts_with).exclude(id__in=users_to_exclude)[:20])
            else:
                internal_resource_list = serializers.serialize('json', InternalResource.objects.all().exclude(
                    id__in=users_to_exclude))
            return HttpResponse(internal_resource_list)
Esempio n. 2
0
__author__ = 'janak'

from django.views.generic import TemplateView
from utils.template_mapping import template_names_dict
from utils.ajax_check_helper import AjaxCheckerMixin
from converse.models import Tweet
from utils.log_helper import init_logger

logger = init_logger(__file__)


class TweetHome(TemplateView, AjaxCheckerMixin):
    def get(self, request, *args, **kwargs):
        try:
            self.template_name = template_names_dict['tweethome']
            context = self.get_context_data(**kwargs)
            self.check_if_ajax_page(request, context)

            # Get Tweet Data
            tweets = Tweet.objects.values('userid_id', 'id', 'tweet', 'dateadded').order_by('-dateadded')[:10]
            context['tweets'] = tweets

            return self.render_to_response(context)
        except Exception as e:
            logger.error("Exception caught on Tweet Home " + str(e))