wco_models 3.5.0.6 → 3.5.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/wco/main.scss +7 -3
  3. data/app/assets/stylesheets/wco/photos.scss +2 -1
  4. data/app/controllers/wco/newsvideos_controller.rb +18 -16
  5. data/app/controllers/wco/office_action_templates_controller.rb +3 -0
  6. data/app/controllers/wco/publishers_controller.rb +6 -16
  7. data/app/controllers/wco/reports_controller.rb +6 -5
  8. data/app/controllers/wco/sitemap_paths_controller.rb +14 -2
  9. data/app/controllers/wco/sites_controller.rb +1 -1
  10. data/app/controllers/wco/tags_controller.rb +1 -1
  11. data/app/jobs/wco/newspartial_speech_job.rb +12 -0
  12. data/app/jobs/wco/{newsvideo_generate_job.rb → newsvideo_combine_job.rb} +2 -2
  13. data/app/models/iro/option.rb +37 -4
  14. data/app/models/iro/priceitem.rb +62 -4
  15. data/app/models/tda/option.rb +39 -41
  16. data/app/models/wco/newspartial.rb +16 -6
  17. data/app/models/wco/newsvideo.rb +1 -1
  18. data/app/models/wco/publisher.rb +29 -8
  19. data/app/models/wco/publisher_d10.rb +50 -0
  20. data/app/models/wco/report.rb +12 -2
  21. data/app/models/wco/site.rb +1 -67
  22. data/app/models/wco/sitemap_path.rb +19 -13
  23. data/app/models/wco/tag.rb +15 -8
  24. data/app/models/wco/utils.rb +1 -1
  25. data/app/views/wco/api/newsproducer/README.txt +4 -0
  26. data/app/views/wco/api/newsproducer/_studio_blue2.js-bk +606 -0
  27. data/app/views/wco/api/newsproducer/_studio_blue2.js-bk2 +898 -0
  28. data/app/views/wco/api/newsproducer/studio_blue2.html.erb-bk +151 -0
  29. data/app/views/wco/office_action_templates/index.haml +1 -1
  30. data/app/views/wco/office_actions/_actions.haml +1 -1
  31. data/app/views/wco/publishers/_form.haml +11 -2
  32. data/app/views/wco/publishers/_post_with.haml +1 -1
  33. data/app/views/wco/reports/_form.haml +13 -2
  34. data/app/views/wco/reports/_index.haml +18 -11
  35. data/app/views/wco/reports/show.haml +6 -1
  36. data/app/views/wco/sitemap_paths/_index.haml +1 -0
  37. data/app/views/wco/sitemap_paths/show.haml +14 -0
  38. data/app/views/wco/sites/index.haml +6 -0
  39. data/app/views/wco/sites/show.haml +1 -1
  40. data/app/views/wco/tags/_form.haml +3 -0
  41. data/config/routes.rb +3 -3
  42. data/lib/shortcuts.rb +1 -1
  43. data/lib/wco_models.rb +1 -1
  44. metadata +10 -4
  45. data/app/views/wco/sitemap_paths/check.haml +0 -13
@@ -1,4 +1,11 @@
1
1
 
2
+ def url_exists?(url)
3
+ response = HTTParty.head(url, timeout: 5, follow_redirects: true)
4
+ response.code == 200
5
+ rescue StandardError
6
+ false
7
+ end
8
+
2
9
  class Wco::Publisher
3
10
  include Mongoid::Document
4
11
  include Mongoid::Timestamps
@@ -19,26 +26,35 @@ class Wco::Publisher
19
26
  field :post_path
20
27
 
21
28
  has_many :oats, class_name: 'Wco::OfficeActionTemplate'
29
+ has_and_belongs_to_many :tags
22
30
 
23
31
  attr_accessor :props
24
32
 
25
33
  def do_run
26
- @site = site
34
+ @publisher = publisher = self
35
+
36
+ @site = publisher.site
27
37
  @headers = {}
28
38
  @ctx = OpenStruct.new
29
39
 
30
- # puts! context_eval, 'context_eval'
31
- eval( context_eval )
32
- # puts! @ctx, '@ctx'
40
+ puts! publisher.context_eval, 'context_eval'
41
+ eval( publisher.context_eval )
42
+ puts! @ctx, '@ctx'
33
43
 
34
- tmpl = ERB.new post_body_tmpl
44
+ if @abort
45
+ errors.add(:base, 'aborted')
46
+ return false
47
+ end
48
+
49
+ tmpl = ERB.new publisher.post_body_tmpl
35
50
  body = JSON.parse tmpl.result(binding)
36
- # puts! body, 'body'
51
+ puts! body, 'body'
37
52
 
38
53
  out = Wco::HTTParty.post( "#{@site.origin}#{post_path}", {
39
54
  body: body.to_json,
40
55
  headers: @headers,
41
56
  basic_auth: { username: @site.username, password: @site.password },
57
+ debug_output: $stdout,
42
58
  })
43
59
  puts! out.response, 'publisher httparty response'
44
60
  puts! out.body, 'publisher httparty body'
@@ -54,12 +70,17 @@ class Wco::Publisher
54
70
  raise out.body
55
71
  end
56
72
 
57
- eval( after_eval ) if after_eval.present?
73
+ if after_eval.present?
74
+ puts! after_eval, 'after_eval'
75
+ eval( after_eval )
76
+ end
77
+
78
+ return true
58
79
  end
59
80
 
60
81
 
61
82
  def to_s
62
- "#{slug}: #{kind} => #{site}"
83
+ "#{site} :: #{slug}"
63
84
  end
64
85
 
65
86
  def self.list
@@ -0,0 +1,50 @@
1
+
2
+ ##
3
+ ## this doesn't work and was never tested or used.
4
+ ## 2026-11-14
5
+ ##
6
+ class Wco::PublisherD10 < Wco::Publisher
7
+
8
+ def self.context_eval
9
+
10
+ @headers['Content-Type'] = 'application/vnd.api+json'
11
+ @headers['Authorization'] = "Basic base64(#{@site.username}:#{@site.password})"
12
+
13
+ @report = Wco::Report.find @props[:report_id]
14
+
15
+ tags = @publisher.tags.where( site: @site )
16
+ @tags_data = tags.map do |tag|
17
+ { "type": "taxonomy_term--tags", "id": tag.external_id.to_s }
18
+ end.to_json
19
+ puts! @tags_data, '@tags_data'
20
+
21
+ @field_image_thumb_data = ""
22
+ if false || @report.image_thumb
23
+ image_url ||= @report.image_thumb.photo.url(:thumb)
24
+
25
+ uri = URI(image_url)
26
+ image_data = Net::HTTP.get(uri)
27
+ credentials = Base64.strict_encode64("#{@site.username}:#{@site.password}")
28
+
29
+ puts! 'Saving an image...'
30
+ response = HTTParty.post(
31
+ "#{@site.origin}/jsonapi/node/article/field_image_thumb",
32
+ headers: {
33
+ 'Content-Type' => 'application/octet-stream',
34
+ 'Accept' => 'application/vnd.api+json',
35
+ 'Content-Disposition' => 'file; filename="thumbnail.jpg"',
36
+ 'Authorization' => "Basic #{credentials}",
37
+ },
38
+ body: image_data
39
+ )
40
+ puts! response, 'response'
41
+ field_image_thumb_id = response['data']['id']
42
+ @field_image_thumb_data =<<~AOL
43
+ "field_image_thumb": { "data": { "type": "file--file", "id": "#{field_image_thumb_id}" } },
44
+ AOL
45
+ puts! @field_image_thumb_data, '@field_image_thumb_data'
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -25,14 +25,24 @@ class Wco::Report
25
25
 
26
26
  field :body
27
27
  def body_json
28
- body.gsub(/\r/, '').gsub(/\n\n+/, '<br /><br />').to_json
28
+ out = body
29
+ if FORMAT_PLAINTEXT == body_format
30
+ out = out.gsub(/\r/, '').gsub(/\n\n+/, '<br /><br />')
31
+ end
32
+ out.to_json
29
33
  end
34
+ FORMAT_PLAINTEXT = 'format-plaintext'
35
+ FORMAT_FULLHTML = 'format-fullhtml'
36
+ FORMATS = [ FORMAT_PLAINTEXT, FORMAT_FULLHTML ]
37
+ field :body_format, type: :string, default: FORMAT_PLAINTEXT
30
38
 
31
39
  field :x, :type => Float
32
40
  field :y, :type => Float
33
41
  field :z, :type => Float
42
+ field :source_url, type: :string
43
+ field :summary, type: :string
34
44
 
35
- belongs_to :author, class_name: 'Wco::Profile'
45
+ belongs_to :author, class_name: 'Wco::Profile', optional: true
36
46
 
37
47
  has_one :image_thumb, class_name: 'Wco::Photo', inverse_of: :report, dependent: :destroy
38
48
  accepts_nested_attributes_for :image_thumb
@@ -18,7 +18,7 @@ class Wco::Site
18
18
  has_many :logs, inverse_of: :obj
19
19
  has_many :publishers # , class_name: 'Wco::Publisher'
20
20
  has_many :sitemap_paths, class_name: 'Wco::SitemapPath'
21
- has_many :tags, class_name: 'Wco::Tag'
21
+ has_many :tags, class_name: 'Wco::Tag', inverse_of: :site
22
22
 
23
23
  field :slug
24
24
  validates :slug, presence: true, uniqueness: true
@@ -34,78 +34,12 @@ class Wco::Site
34
34
 
35
35
  def to_s
36
36
  slug
37
- # origin
38
37
  end
39
38
 
40
39
  def self.list
41
40
  [[nil,nil]] + all.map { |s| [ s.slug, s.id ] }
42
41
  end
43
42
 
44
- def body
45
- {
46
- "_links": {
47
- "type":{"href":"http://pi.local/rest/type/node/article"}
48
- },
49
- "title":[{"value":"Node +++ 123 bac +++" }],
50
- "body":[{"value": "<b>hello, wor</b>ld!", "format": "full_html" }],
51
- "type":[{"target_id":"article"}],
52
- "status": [{"value": 1}],
53
- "_embedded": {
54
- "http://pi.local/rest/relation/node/article/field_issue": [
55
- { "uuid": [{ "value": "56229a95-d675-43e1-99b1-f9e11b5579c5" }] }
56
- ],
57
- "http://pi.local/rest/relation/node/article/field_tags": [
58
- { "uuid": [{ "value": "45646a7d-1a16-42e8-b758-f6e1c8d976f7" }] },
59
- { "uuid": [{ "value": "834e34e2-05ae-498d-b876-453798872ce1" }] }
60
- ]
61
- }
62
-
63
- }
64
- end
65
-
66
- def do_post
67
- HTTParty.post( post_url,
68
- body: JSON.generate( body ),
69
- headers: { 'Content-Type' => 'application/hal+json' },
70
- basic_auth: { username: username, password: password },
71
- )
72
- end
73
-
74
- def wp_import
75
- site = self
76
-
77
- root_tag = Wco::Tag.find_or_create_by slug: "#{site.slug}_wp-import", site_id: site.id
78
- url = "#{site.origin}/wp-json/wp/v2/posts"
79
- pi_admin = Wco::Profile.find_or_create_by email: 'admin@piousbox.com'
80
- n_pages = 12
81
- per_page = 100
82
-
83
- (1..n_pages).each do |page|
84
- print "Page #{page}"
85
-
86
- posts = HTTParty.get url, query: { per_page: per_page, page: page }
87
- posts.each do |post|
88
- report = Wco::Report.new({
89
- legacy_id: post['id'],
90
- created_at: post['date'],
91
- slug: post['link'].sub(site.origin, ''),
92
- title: post['title']['rendered'],
93
- subtitle: post['excerpt']['rendered'],
94
- body: post['content']['rendered'],
95
- author: pi_admin,
96
- tag_ids: ( [ root_tag ] + site.tags.where( :legacy_id.in => post['categories'] ) ).map(&:id),
97
- })
98
-
99
- if report.save
100
- print '^'
101
- else
102
- puts report.errors.messages
103
- end
104
- end
105
- end
106
- puts "ok"
107
- end
108
-
109
43
  def check_sitemap
110
44
  @results = []
111
45
  @total_count = 0
@@ -15,9 +15,15 @@ class Wco::SitemapPath
15
15
  field :selectors, type: Array, default: []
16
16
  field :title, type: String
17
17
 
18
- field :results, type: Array, default: []
18
+
19
19
  field :status, type: String
20
20
 
21
+ # field :results, type: Array, default: []
22
+ has_many :logs, inverse_of: :obj
23
+ def results
24
+ logs.map { |log| "#{log.message} [on #{log.created_at.to_s[0...10]}]" }
25
+ end
26
+
21
27
  def check
22
28
  self.status = 'NOT_OK'
23
29
  skip_rest = false
@@ -26,26 +32,26 @@ class Wco::SitemapPath
26
32
  begin
27
33
  body = HTTParty.get( "#{site.origin}#{self[:path]}" ).body
28
34
  rescue OpenSSL::SSL::SSLError => err
29
- results.push "NOT OK [ssl-exception] #{self[:path]}" # .red
35
+ log = Wco::Log.create obj: self, message: "NOT OK [ssl-exception] #{self[:path]}" # .red
30
36
  return
31
37
  end
32
38
  doc = Nokogiri::HTML( body )
33
39
  out = doc.search self[:selector]
34
40
  if out.present?
35
- results.push "OK #{self[:path]}"
41
+ log = Wco::Log.create obj: self, message: "OK #{self[:path]}"
36
42
  self.status = 'OK'
37
43
  else
38
- results.push "NOT OK [selector-missing] #{self[:path]}" # .red
44
+ log = Wco::Log.create obj: self, message: "NOT OK [selector-missing] #{self[:path]}" # .red
39
45
  end
40
46
 
41
47
  elsif self[:redirect_to].present?
42
48
  out = HTTParty.get( "#{site.origin}#{self[:path]}", follow_redirects: false )
43
49
  if( out.headers[:location] == self[:redirect_to] ||
44
50
  out.headers[:location] == "#{site.origin}#{self[:redirect_to]}" )
45
- results.push "OK #{self[:path]}"
51
+ log = Wco::Log.create obj: self, message: "OK #{self[:path]}"
46
52
  self.status = 'OK'
47
53
  else
48
- results.push "NOT OK [redirect-missing] #{self[:path]}" # .red
54
+ log = Wco::Log.create obj: self, message: "NOT OK [redirect-missing] #{self[:path]}" # .red
49
55
 
50
56
  puts!( out.response, 'response' ) if DEBUG
51
57
  # puts!( out.body, 'body' ) if DEBUG
@@ -56,7 +62,7 @@ class Wco::SitemapPath
56
62
  end
57
63
  skip_rest = true
58
64
  else
59
- results.push "SKIP #{self[:path]}"
65
+ log = Wco::Log.create obj: self, message: "SKIP #{self[:path]}"
60
66
  self.status = 'OK'
61
67
  skip_rest = true
62
68
  end
@@ -66,10 +72,10 @@ class Wco::SitemapPath
66
72
  if self[:meta_description].present?
67
73
  out = doc.search( 'head meta[name="description"]' )[0]['content']
68
74
  if out.include?( self[:meta_description] )
69
- results.push "OK #{self[:path]} meta_description"
75
+ log = Wco::Log.create obj: self, message: "OK #{self[:path]} meta_description"
70
76
  else
71
77
  self.status = 'NOT_OK'
72
- results.push "NOT OK [meta-description-no-contain] #{self[:path]}" # .red
78
+ log = Wco::Log.create obj: self, message: "NOT OK [meta-description-no-contain] #{self[:path]}" # .red
73
79
  end
74
80
  end
75
81
 
@@ -77,10 +83,10 @@ class Wco::SitemapPath
77
83
  self[:selectors].each do |selector|
78
84
  out = doc.search selector
79
85
  if out.present?
80
- results.push "OK #{self[:path]} selectors:#{selector}"
86
+ log = Wco::Log.create obj: self, message: "OK #{self[:path]} selectors:#{selector}"
81
87
  else
82
88
  self.status = 'NOT_OK'
83
- results.push "NOT OK [selectors-missing:#{selector}] #{self[:path]}" # .red
89
+ log = Wco::Log.create obj: self, message: "NOT OK [selectors-missing:#{selector}] #{self[:path]}" # .red
84
90
  end
85
91
  end
86
92
  end
@@ -88,10 +94,10 @@ class Wco::SitemapPath
88
94
  if self[:title].present?
89
95
  out = doc.search( 'head title' )[0].text
90
96
  if out.include?( self[:title] )
91
- results.push "OK #{self[:path]} title"
97
+ log = Wco::Log.create obj: self, message: "OK #{self[:path]} title"
92
98
  else
93
99
  self.status = 'NOT_OK'
94
- results.push "NOT OK [title-no-contain] #{self[:path]}" # .red
100
+ log = Wco::Log.create obj: self, message: "NOT OK [title-no-contain] #{self[:path]}" # .red
95
101
  end
96
102
  end
97
103
 
@@ -5,19 +5,21 @@ class Wco::Tag
5
5
  store_in collection: 'wco_tags'
6
6
 
7
7
  field :slug
8
- validates :slug, presence: true, uniqueness: true
8
+ validates :slug, presence: true, uniqueness: { scope: :site_id }
9
9
  index({ slug: -1 })
10
10
 
11
11
  field :weight, type: :string, default: 'jjj'
12
+ field :external_id, type: :string
13
+ def eid; external_id; end
12
14
 
13
15
  belongs_to :parent, class_name: '::Wco::Tag', inverse_of: :sons, optional: true
14
16
  has_many :sons, class_name: '::Wco::Tag', inverse_of: :parent
15
17
 
16
- belongs_to :site, class_name: '::Wco::Site', optional: true
17
- belongs_to :sidebar_profile, class_name: 'Wco::Profile', optional: true
18
- has_many :email_filters, class_name: '::WcoEmail::EmailFilter', inverse_of: :tag
19
- has_many :email_templates, class_name: '::WcoEmail::EmailTemplate', inverse_of: :tag
20
- has_many :ajects, class_name: '::WcoEmail::EmailFilterAction', inverse_of: :aject
18
+ belongs_to :site, class_name: '::Wco::Site', optional: true, inverse_of: :tags
19
+ belongs_to :sidebar_profile, class_name: 'Wco::Profile', optional: true
20
+ has_many :email_filters, class_name: '::WcoEmail::EmailFilter', inverse_of: :tag
21
+ has_many :email_templates, class_name: '::WcoEmail::EmailTemplate', inverse_of: :tag
22
+ has_many :ajects, class_name: '::WcoEmail::EmailFilterAction', inverse_of: :aject
21
23
 
22
24
  has_and_belongs_to_many :conversations, class_name: '::WcoEmail::Conversation', index: true
23
25
  has_and_belongs_to_many :galleries, class_name: '::Wco::Gallery'
@@ -27,6 +29,7 @@ class Wco::Tag
27
29
  has_and_belongs_to_many :message_stubs, class_name: '::WcoEmail::MessageStub'
28
30
  has_and_belongs_to_many :newsvideos, class_name: '::Wco::Newsvideo'
29
31
  has_and_belongs_to_many :reports, class_name: '::Wco::Report'
32
+ has_and_belongs_to_many :publishers, class_name: '::Wco::Publisher'
30
33
  has_and_belongs_to_many :videos, class_name: '::Wco::Video'
31
34
 
32
35
 
@@ -71,9 +74,13 @@ class Wco::Tag
71
74
 
72
75
 
73
76
  def to_s
74
- slug
77
+ if site
78
+ "#{slug}@#{site}"
79
+ else
80
+ slug
81
+ end
75
82
  end
76
83
  def self.list
77
- [[nil,nil]] + all.order_by( slug: :asc ).map { |p| [ p.slug, p.id ] }
84
+ [[nil,nil]] + all.includes(:site).order_by( slug: :asc ).map { |t| [ t.to_s, t.id.to_s ] }
78
85
  end
79
86
  end
@@ -50,7 +50,7 @@ module Wco::Utils
50
50
  def set_slug
51
51
  return if !slug.blank?
52
52
  if defined? name
53
- new_slug = name.downcase.gsub(/[^a-z0-9\s]/i, '').gsub(' ', '-')
53
+ new_slug = name.downcase.gsub(/[^a-z0-9\s_-]/i, '').gsub(' ', '-')
54
54
  else
55
55
  new_slug = '1'
56
56
  end
@@ -0,0 +1,4 @@
1
+
2
+ studio_fps is current, studio_blue2 is old.
3
+
4
+ actually, i still need studio_blue2, it seems.