Exemplo n.º 1
0
def add_video(request):
    competition_id = request.POST.get('competition_id')
    if competition_id is None:
        return api_response.error("Missing competition id")
    else:
        competition = Competition.objects.get_by_id(competition_id)
        if competition is None:
            logging.error("Competition not found: %s" % id)
            return api_response.error("Competition not found.")

    video_url = request.POST.get('video_url')

    thumbnail_url = None
    if video_url is not None:
        thumbnail_url = get_thumbnail(video_url)

    video = Video.objects.create(
        competition_id=competition.competition_id,
        user_id=request.user.id, video_url=video_url,
        thumbnail_url=thumbnail_url)
    competition.videos.append(video.video_id)
    competition.save()
    Activity.objects.joined_competition_activity(request.user, competition,
                                                 video)
    return api_response.ok(video)
Exemplo n.º 2
0
def get_video_thumbnail(request):
    url = request.GET.get('url')
    if not url:
        return api_response.invalid_param("Missing url parameter")
    thumbnail_url = get_thumbnail(url)
    if thumbnail_url:
        return {'thumbnail': thumbnail_url}
Exemplo n.º 3
0
    def put(self, request, *args, **kwargs):
        # PUT = QueryDict(request.body, request.encoding)
        PUT = simplejson.loads(request.body, request.encoding)
        # todo: check if ajax
        # todo: check if PUT
        # todo: check for CSRF
        competition = Competition.objects.get_by_id(self.pk)
        if competition is None:
            logging.error("Competition not found: %s" % self.pk)
            api_response.error("Competition not found.")
            return
        try:
            thumbnail_url = PUT.get('thumbnail_url')
            if thumbnail_url is not None:
                competition.thumbnail_url = thumbnail_url
            name = PUT.get('name')
            if name is not None:
                competition.name = name
            description = PUT.get('description')
            if description is not None:
                competition.description = description
            is_private = PUT.get('is_private')
            if is_private is not None:
                competition.is_private = is_private
            category_id = PUT.get('category_id')
            if category_id is not None:
                competition.category_id = category_id
            minimum_bounty = PUT.get('minimum_bounty')
            if minimum_bounty is not None:
                competition.minimum_bounty = int(minimum_bounty)
            intro_video_url = PUT.get('intro_video_url')
            if intro_video_url is not None:
                competition.intro_video_url = intro_video_url
                if thumbnail_url is None:
                    thumbnail_url = get_thumbnail(intro_video_url)
                    competition.thumbnail_url = thumbnail_url

            categories = PUT.get('categories')
            if categories is not None:
                competition.categories = categories

            # todo(dan) check dates
            beginning_date = PUT.get('beginning_date')
            if beginning_date is not None:
                if beginning_date:
                    beginning_date = beginning_date.strip()
                    beginning_date = datetime.strptime(beginning_date,
                                                       "%m/%d/%Y")
                    competition.beginning_date = beginning_date
                else:
                    competition.beginning_date = None

            end_date = PUT.get('end_date')
            if end_date is not None:
                if end_date:
                    end_date = end_date.strip()
                    end_date = datetime.strptime(end_date, "%m/%d/%Y")
                    competition.end_date = end_date
                else:
                    competition.end_date = None

            competition.save()
            return api_response.ok(competition)
        except Exception as e:
            return api_response.error(e)