Exemplo n.º 1
0
    def __init__(self, cache_for_form_optimization=None,  *args, **kwargs):
        # The cache_for_form_optimization is an object that is
        # optionally created by the request that calls
        # BulkEditForm. One difficulty with BulkEditForms is that the
        # forms generate similar data over and over again; we can
        # avoid some database hits by running some queries just once
        # (at BulkEditForm instantiation time), rather than once per
        # sub-form.
        #
        # However, it is unsafe to cache data in the BulkEditForm
        # class because that persists for as long as the Python
        # process does (meaning that subsequent requests will use the
        # same cache).
        EditVideoForm.__init__(self, *args, **kwargs)

        # We have to initialize tags manually because the model form
        # (django.forms.models.model_to_dict) only collects fields and
        # relations, and not descriptors like Video.tags
        self.initial['tags'] = util.get_or_create_tags(self.instance.tags)

        # cache the querysets so that we don't hit the DB for each form
        cache_for_form_optimization = self.fill_cache(cache_for_form_optimization)

        self.fields['categories'].queryset = cache_for_form_optimization[
            'categories_qs']
        self.fields['authors'].queryset = cache_for_form_optimization[
            'authors_qs']
Exemplo n.º 2
0
    def generate_video_model(self, site, status=models.VIDEO_STATUS_ACTIVE):
        scraped_data = get_scraped_data(self.website_url)
        self.name = scraped_data.get('title', self.name)
        self.description = scraped_data.get('description', self.description)
        self.file_url = scraped_data.get('file_url', self.file_url)
        self.embed_code = scraped_data.get('embed_code', self.embed_code)
        self.flash_enclosure_url = scraped_data.get('flash_enclosure_url',
                                                    self.flash_enclosure_url)
        self.website_url = scraped_data.get('link', self.website_url)

        if scraped_data.get('tags'):
            tags = get_or_create_tags(scraped_data['tags'])
        elif self.tags:
            tags = get_or_create_tags([tag['name'] for tag in
                                       self.tags['objects']['all']])
        else:
            tags = []

        video = models.Video(
            name=self.name,
            site=site,
            description=self.description,
            file_url=self.file_url,
            when_submitted=datetime.datetime.now(),
            when_approved=datetime.datetime.now(),
            status=status,
            website_url=self.website_url,
            thumbnail_url=self.thumbnail_url,
            embed_code=self.embed_code,
            flash_enclosure_url=self.flash_enclosure_url,
            when_published=self.publish_date,
            video_service_user=self.video_service_user,
            video_service_url=self.video_service_url)

        video.try_to_get_file_url_data()
        video.save()
        video.tags = tags
        video.save()
        if video.thumbnail_url:
            video.save_thumbnail()

        return video
Exemplo n.º 3
0
 def __init__(self, *args, **kwargs):
     self.scraped_data = kwargs.pop('scraped_data', {})
     if self.scraped_data.get('tags'):
         kwargs.setdefault('initial', {})['tags'] = \
             get_or_create_tags(self.scraped_data['tags'])
     SecondStepSubmitVideoForm.__init__(self, *args, **kwargs)
Exemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     forms.ModelForm.__init__(self, *args, **kwargs)
     self.initial['tags'] = util.get_or_create_tags(self.instance.tags)
Exemplo n.º 5
0
 def __init__(self, *args, **kwargs):
     self.scraped_data = kwargs.pop('scraped_data', {})
     if self.scraped_data.get('tags'):
         kwargs.setdefault('initial', {})['tags'] = \
             get_or_create_tags(self.scraped_data['tags'])
     SecondStepSubmitVideoForm.__init__(self, *args, **kwargs)
Exemplo n.º 6
0
 def __init__(self, *args, **kwargs):
     forms.ModelForm.__init__(self, *args, **kwargs)
     self.initial['tags'] = util.get_or_create_tags(self.instance.tags)