Beispiel #1
0
def get_challenge(request, challenge_id=None):
    from dashboard.serializer import ChallengeSerializer

    if challenge_id is not None:
        results = ChallengeSerializer(
            Challenge.objects.filter(pk=challenge_id).order_by('-created_at'),
            many=True).data[0]
    else:
        results = ChallengeSerializer(
            Challenge.objects.all().order_by('-created_at'), many=True).data
    return JsonResponse(results, safe=False)
Beispiel #2
0
 def campany_challenges(self, obj):
     t = Template(self.template)
     print
     return t.render(
         Context({
             'challenges':
             ChallengeSerializer(obj.challenges, many=True).data
         }))
Beispiel #3
0
def get_profile_challenge(request, profile_id):
    from dashboard.serializer import ChallengeSerializer
    results = []
    try:
        profile = Profile.objects.get(pk=profile_id)
        results = profile.get_interests(Challenge)
        results = ChallengeSerializer(results if len(results) > 0 else [],
                                      many=True).data
    except Exception as e:
        response = JsonResponse({'status': 'error', 'message': ''})
        response.status_code = 500
        return response

    return JsonResponse(results, safe=False)
Beispiel #4
0
    def get_entity_details(request, entity='news', entity_id=None):
        results = []
        profile = None

        try:
            method_to_call = 'get_' + entity + '_detail'
            results = getattr(DSPConnectorV13,
                              method_to_call)(entity_id=entity_id)[entity]
        except DSPConnectorException:
            pass
        except AttributeError as a:
            if entity == 'projects':
                local_entities = Project.objects.get(pk=entity_id)
                results = ProjectSerializer(local_entities).data
            else:
                local_entities = Challenge.objects.get(pk=entity_id)
                results = ChallengeSerializer(local_entities, many=True).data

        return success('ok', 'single entity', results)
Beispiel #5
0
    def get_entity(request, entity='news'):
        #TODO make cursor works
        profile = None
        results = []
        local_entities = None
        try:
            profile = request.user.profile
        except:
            # NOt logged user
            profile = None

        try:
            topics_list = DSPConnectorV12.get_topics()['topics']
            topics_id_list = [x['topic_id'] for x in topics_list]
            method_to_call = 'get_' + entity
            if not profile:
                selected_topic = random.choice(topics_id_list)
                results = getattr(
                    DSPConnectorV13,
                    method_to_call)(topic_id=selected_topic)[entity]
                results = results[:5]
            else:
                for index, topic_id in enumerate(topics_id_list):
                    results.append(
                        getattr(DSPConnectorV13,
                                method_to_call)(topic_id=topic_id)[entity])
                results = mix_result_round_robin(*results)
        except DSPConnectorException:
            pass
        except AttributeError as a:
            local_entities = Project.objects.all()
            if not profile:
                local_entities = local_entities[:5]
            results.extend(ProjectSerializer(local_entities, many=True).data)
            local_entities = Challenge.objects.all()
            if not profile:
                local_entities = local_entities[:5]
            results.extend(ChallengeSerializer(local_entities, many=True).data)

        return success('ok', 'entity list', results)