Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: retweet #465

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions hasjob/models/jobpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ class JobPost(BaseMixin, db.Model):
review_datetime = db.Column(db.DateTime, nullable=True)
review_comments = db.Column(db.Unicode(250), nullable=True)

# Social media links
tweetid = db.Column(db.Unicode(30), nullable=True)

search_vector = deferred(db.Column(TSVECTOR, nullable=True))

_state = db.Column('status', db.Integer, StateManager.check_constraint('status', POST_STATE),
Expand Down
12 changes: 9 additions & 3 deletions hasjob/templates/detail.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,15 @@
<a class="list-group-item visible-xs-block visible-sm-block" href="whatsapp://send?text={{ headline|urlquoteplus }}+{{ post.url_for(utm_campaign='share', utm_medium='whatsapp', _external=true)|urlquoteplus }}">
<i class="fa fa-fw fa-whatsapp"></i>&nbsp;&nbsp; Share on WhatsApp
</a>
<a class="list-group-item share-popup" data-width="550" data-height="250" rel="noopener" target="_blank" href="https://twitter.com/share?url={{ post.url_for(utm_campaign='share', utm_medium='twitter', _external=true)|urlquoteplus }}&amp;counturl={{ post.url_for(_external=true)|urlquoteplus }}&amp;via=hasjob&amp;related=hasjob:HasGeek%20Job%20Board&amp;text=Job%3A%20{{ headline|urlquoteplus }}">
<span class="badge" id="tweet-count"></span><i class="fa fa-fw fa-twitter"></i>&nbsp;&nbsp; Tweet this
</a>
{%- if post.tweetid %}
<a class="list-group-item share-popup" data-width="550" data-height="250" rel="noopener" target="_blank" href="https://twitter.com/intent/retweet?tweet_id={{ post.tweetid }}">
<span class="badge" id="tweet-count"></span><i class="fa fa-fw fa-twitter"></i>&nbsp;&nbsp; Retweet this
</a>
{%- else%}
<a class="list-group-item share-popup" data-width="550" data-height="250" rel="noopener" target="_blank" href="https://twitter.com/share?url={{ post.url_for(utm_campaign='share', utm_medium='twitter', _external=true)|urlquoteplus }}&amp;counturl={{ post.url_for(_external=true)|urlquoteplus }}&amp;via=hasjob&amp;related=hasjob:HasGeek%20Job%20Board&amp;text=Job%3A%20{{ headline|urlquoteplus }}">
<span class="badge" id="tweet-count"></span><i class="fa fa-fw fa-twitter"></i>&nbsp;&nbsp; Tweet this
</a>
{%- endif %}
<a class="list-group-item share-popup" data-width="520" data-height="230" rel="noopener" target="_blank" href="http://www.facebook.com/sharer.php?s=100&p[url]={{ post.url_for(utm_campaign='share', utm_medium='facebook', _external=true)|urlquoteplus }}">
<i class="fa fa-fw fa-facebook"></i>&nbsp;&nbsp; Share on Facebook
</a>
Expand Down
9 changes: 8 additions & 1 deletion hasjob/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ def tweet(title, url, location=None, parsed_location=None, username=None):
text = text + ' ' + locationtag
if username:
text = text + ' @' + username
api.update_status(text)
tweet_status = api.update_status(text)
return tweet_status.id


def retweet(post):
# Need to add the By-line like A job by Company has been posted on hasjob, check it out + post.headline
tweet_id = tweet(post.headline, post.url_for(_external=True))
return tweet_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this instead:

def tweet_post(post_id):
    post = JobPost.query.get(post_id)
    if post.headlineb:
        post.tweetid = tweet(post.headline, post.url_for(b=0, _external=True),
            post.location, dict(post.parsed_location or {}), username=post.twitter)
        tweet(post.headlineb, post.url_for(b=1, _external=True),
            post.location, dict(post.parsed_location or {}), username=post.twitter)
    else:
        post.tweetid = tweet(post.headline, post.url_for(_external=True),
            post.location, dict(post.parsed_location or {}), username=post.twitter)
    db.session.commit()



def shorten(url):
Expand Down
2 changes: 2 additions & 0 deletions hasjob/views/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
AnonJobView, JobApplication, Campaign, CAMPAIGN_POSITION, unique_hash,
viewstats_by_id_hour, viewstats_by_id_day)
from hasjob.twitter import tweet
from hasjob.twitter import retweet
from hasjob.tagging import tag_locations, add_to_boards, tag_jobpost
from hasjob.uploads import uploaded_logos
from hasjob.utils import get_word_bag, redactemail, random_long_key, common_legal_names
Expand Down Expand Up @@ -746,6 +747,7 @@ def confirm_email(domain, hashid, key):
% post.email_domain, category='info')
return redirect(url_for('index'))
post.confirm()
post.tweetid = retweet(post)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be inside if app.config['TWITTER_ENABLED']:

db.session.commit()
if app.config['TWITTER_ENABLED']:
if post.headlineb:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this if block entirely with tweet_post.delay(post.id)

Expand Down
23 changes: 23 additions & 0 deletions migrations/versions/d8258df712fa_tweet_id_for_jobpost.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Tweet id for JobPost

Revision ID: d8258df712fa
Revises: 625415764254
Create Date: 2018-07-12 18:22:20.245244

"""

# revision identifiers, used by Alembic.
revision = 'd8258df712fa'
down_revision = '625415764254'

from alembic import op
import sqlalchemy as sa



def upgrade():
op.add_column('jobpost', sa.Column('tweetid', sa.Unicode(length=30), nullable=True))


def downgrade():
op.drop_column('jobpost', 'tweetid')