示例#1
0
    def handle(self, *args, **options):

        rss_url = 'http://blog.djangogirls.org/rss'

        response = requests.get(rss_url)
        rss = ElementTree.fromstring(response.content)

        for post in rss.iter('item'):
            title = post.find('title').text
            if 'Your Django Story: Meet' in title:
                name = title.replace('Your Django Story: Meet ', '')
                is_story = True
            else:
                name = title
                is_story = False

            if not Story.objects.filter(name=name).exists():
                post_url = post.find('link').text
                post = pq(post.find('description').text)
                image_url = post('img').attr.src
                story = Story(name=name, post_url=post_url, content=post, is_story=is_story)

                if image_url:
                    img = NamedTemporaryFile(delete=True)
                    img.write(urlopen(image_url).read())
                    img.flush()
                    story.image.save(image_url.split('/')[-1], File(img))

                story.save()

                if is_story:
                    print('Story of %s has been fetched' % name)
                else:
                    print('Blogpost "%s" has been fetched' % name)
示例#2
0
    def handle(self, *args, **options):

        rss_url = 'http://blog.djangogirls.org/rss'

        response = requests.get(rss_url)
        rss = ElementTree.fromstring(response.content)

        for post in rss.iter('item'):
            title = post.find('title').text
            if 'Your Django Story: Meet' in title:
                name = title.replace('Your Django Story: Meet ', '')

                if not Story.objects.filter(name=name).exists():
                    post_url = post.find('link').text
                    post = pq(post.find('description').text)
                    image_url = post('img').attr.src

                    if image_url:
                        story = Story(name=name, post_url=post_url)

                        img = NamedTemporaryFile(delete=True)
                        img.write(urllib2.urlopen(image_url).read())
                        img.flush()

                        story.image.save(image_url.split('/')[-1], File(img))
                        story.save()

                        print 'Story of %s has been fetched' % name
def test_story_object_init(client):
    story = Story(id = 'st123', grapher_name = 'Prashant', name = 'Test.png', description = 'This is test', 
                    duration = 3600, file_type = 'image', state = 'UPLOADED')

    assert story.id == 'st123'
    assert story.grapher_name == 'Prashant'
    assert story.name == 'Test.png'
    assert story.description == 'This is test'
    assert story.duration == 3600
    assert story.file_type == 'image'
    assert story.state == 'UPLOADED'
示例#4
0
    def save(self, commit=True):
        story_sprint = Sprint.objects.get(pk=self.sprint_pk)
        new_story = Story(
            code=self.cleaned_data['code'],
            description=self.cleaned_data['description'],
            creation_date=self.cleaned_data['creation_date'],
            initial_points=self.cleaned_data['initial_points'],
            endpoints=self.cleaned_data['initial_points'],
            duration=timedelta(minutes=0),
            responsible=self.cleaned_data['responsible'],
            completed=False
        )

        if commit:
            new_story.save()

        StorySprint.objects.create(
            story=new_story,
            sprint=story_sprint
        )
        return new_story
def insert(file, data):
    # story metadata information and saving the story in the db
    story = Story()
    story = update_story_object(story, data, file)
    db.session.add(story)
    db.session.commit()

    # Enqueuing background task to process image and video
    enqueue_background_task(story)

    # returning the saved story object
    story = get_by_id(story.id)
    # Removing file from the story object since it will result in increasing the size of payload
    del story.file
    return serializers.serialize(story)
示例#6
0
def checkout(request):
	if not request.user.is_authenticated():
		return redirect('/user/login/')

	name = ''
	sumary = ''
	error_message = False
	total = 0
	currency = 'USD'
	cart = []
	if request.POST:
		name = request.POST['name']
		sumary = request.POST['sumary']
		if name and sumary:
			cart = request.session[settings.SHOPPING_CART_KEY]
			# Check client status
			client = Client.objects.filter(user__id = request.user.id)
			if client: # User is already registered as client
				client = client[0]
			else:
				client = Client(user=request.user, created=timezone.now())
				client.save()
			# Create story and events
			story = Story(
				client = client,
				name = name,
				sumary = sumary,
				created = timezone.now()
			)
			story.save()
			for ev in cart:
				place = Place.objects.get(pk=ev['place'])
				ev = complete_event(ev, place)
				event = Event(
					story = story,
					place = place,
					created = timezone.now(),
					start = ev['start'],
					end = ev['end']
				)
				event.save()
			del request.session[settings.SHOPPING_CART_KEY]
			return redirect('/story/' + str(story.id))

		else:
			error_message = 'Some fields are required.'

	if settings.SHOPPING_CART_KEY in request.session:
		cart = request.session[settings.SHOPPING_CART_KEY]
		i = 0
		for ev in cart:
			place = Place.objects.get(pk=ev['place'])
			ev['index'] = i
			ev = complete_event(ev, place)
			total += ev['price']
			i = i+1

	context = {
		'name'			: name,
		'sumary'		: sumary,
		'total'			: total,
		'currency'		: currency,
		'cart'			: cart,
		'error_message'	: error_message,
		'user'			: views.user_status(request),
		'shopping_cart'	: views.shopping_cart_status(request)
	}
	return render(request, 'story/checkout.html', context)
示例#7
0
            date = read_date(get_field(old_story, "date"))
            text = get_field(old_story, "text", "(no text").strip()

            # Switch over old embedded content to new system
            # Replace the old picture ID with the new content ID corresponding to that picture
            text = re.sub(
                "<sco:picture id=(\d+)>",
                lambda match: "<sco:embed type=\"image\" id={}/>".format(
                    match.group(1)), text)

            story = Story(id=get_field(old_story, "sid"),
                          title=get_field(old_story, "headline", "(no title)"),
                          description=get_field(old_story, "secdeck",
                                                "(no description)").strip(),
                          lead=get_field(old_story, "lead",
                                         "(no lead)").strip(),
                          text=text,
                          section=(Section.objects.get(
                              id=category_id) if category_id > 0 else None),
                          created=date,
                          modified=date)
            story.save()
        except:
            print("Failed to import story {}/{}".format(i, len(stories)))

if ask_reimport("authors"):
    for link in read_table("story_author"):
        try:
            story = Story.objects.get(id=int(get_field(link, "sid")))
            story.authors.add(User.objects.get(id=int(get_field(link, "uid"))))
            story.save()
示例#8
0
                lambda match:
                '<div class="content-embed" data-content-id="{}"></div>'.
                format(Image.objects.get(legacy_id=match.group(1)).pk),
                text,
            )

            text = linebreaks(text)

            story = Story(
                legacy_id=get_field(old_story, "sid"),
                title=get_field(old_story, "headline", ""),
                second_deck=get_field(old_story, "secdeck", "").strip(),
                description=get_field(old_story, "lead", "").strip(),
                cover=cover_image,
                text=text,
                section=(Section.objects.get(
                    id=category_id) if category_id > 0 else None),
                created=date,
                modified=date,
                visibility=Content.PUBLISHED
                if get_field(old_story, "published") == "true"
                and get_field(old_story, "hide") != "1" else Content.HIDDEN,
            )
            story.save()
        except:
            print("Failed to import story {}/{}".format(i, len(stories)))

if ask_reimport("story tags"):
    tags = read_table("story_tag")
    for old_tag in tags:
        try: