def step5(request, action_id, form_class=ActionStep5Form, template_name="actions/step5.html"): action = get_object_or_404(Action, pk=action_id) if not has_perm(request.user,'actions.add_action'): raise Http403 if request.method == "POST": form = form_class(request.POST) if form.is_valid(): add_article = form.cleaned_data['add_article'] if add_article: # add an article from articles.models import Article from categories.models import Category from perms.object_perms import ObjectPermission from django.template.defaultfilters import slugify # article slug is a unique field, if the slug already exists, # what should we do? let append the action id to it to keep it unique slug = slugify(action.email.subject + '-' + str(action.id)) try: art = Article.objects.get(slug=slug) except Article.DoesNotExist: art = Article() art.headline = action.email.subject art.slug = slug art.summary = "" art.body = action.email.body art.sourct = request.user.get_full_name() art.first_name = request.user.first_name art.last_name = request.user.last_name profile = request.user.get_profile() art.phone = profile.phone art.fax = profile.fax art.email = profile.email art.website = get_setting('site', 'global', 'siteurl') art.release_dt = datetime.datetime.now() if action.member_only: art.allow_anonymous_view = 1 art.allow_user_view = 1 art.allow_member_view = 1 art.allow_anonymous_edit = 0 art.allow_user_edit = 0 art.allow_member_edit = 0 art.status = 1 art.status_detail = 'active' art.creator = request.user art.creator_username = request.user.username art.owner = request.user art.owner_username = request.user.username art.save() # user group - assign the permission to view this article if action.group: ObjectPermission.objects.assign_group(action.group, art) # update category category = Category.objects.update(art, 'Newsletter', 'category') action.article = art action.save() #if action.group.members.count() < LIMIT: return HttpResponseRedirect(reverse('action.send', args=[action.id])) #else: # # return to confirmation page # return HttpResponseRedirect(reverse('action.confirm', args=[action.id])) else: form = form_class() return render_to_response(template_name, {'form':form, 'action':action}, context_instance=RequestContext(request))
data = conn.read() conn.close() path = SimpleUploadedFile(path_str, data) img = ArticleImage( image = path, caption = clean_text(photo['caption']), byline = photo['photographer'], article = article ) img.save() status += '-- Imported images for new story %s<br>' % article.headline else: if article.headline != story['headline']: article.headline = story['headline'] if article.summary != story['summary']: article.summary = story['summary'] if article.body != story['body']: article.body = story['body'] status += 'updating story: %s <br>' % article.headline if article.dateline != story['dateline']: article.dateline = story['dateline'] if article.overline != story['overline']: article.overline = story['overline'] if article.id and story.has_key('images'): img_count = 0 for photo_id, photo in story['images'].items(): dupe = False filename = photo['source_url'].rsplit('/', 1)[1] path_str = get_image_path(filename, pub_date) shortname = path_str.split('.')[0] # get file name before the first period. Ex: /img/articles/mypic