Skip to content

Commit

Permalink
Correctly save first_commit across guide edits
Browse files Browse the repository at this point in the history
- Fixes #67
  • Loading branch information
durden committed May 6, 2016
1 parent edfb2e7 commit f84dbf7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion pskb_website/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def api_save():
title = request.form['title']
sha = request.form['sha']
orig_stack = request.form['original_stack']
first_commit = request.form['first_commit']

if not content.strip() or not title.strip():
data = {'error': 'Must enter title and body of guide'}
Expand Down Expand Up @@ -105,7 +106,8 @@ def api_save():
user.avatar_url,
stacks=stacks,
repo_path=repo_path,
author_real_name=user.name)
author_real_name=user.name,
first_commit=first_commit)

if not article:
redirect_to = url_for('index')
Expand Down
13 changes: 10 additions & 3 deletions pskb_website/models/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ def read_article_from_metadata(file_details):

def save_article(title, message, new_content, author_name, email, sha,
branch=u'master', image_url=None, repo_path=None,
author_real_name=None, stacks=None, status=DRAFT):
author_real_name=None, stacks=None, status=DRAFT,
first_commit=None):
"""
Create or save new (original) article, not branched article
Expand All @@ -398,6 +399,7 @@ def save_article(title, message, new_content, author_name, email, sha,
:param author_real_name: Optional real name of author, not username
:param stacks: Optional list of stacks to associate with article
:param status: PUBLISHED, IN_REVIEW, or DRAFT
:param first_commit: Optional first commit of article if it already exists
:returns: Article object updated or saved or None for failure
Expand All @@ -411,6 +413,7 @@ def save_article(title, message, new_content, author_name, email, sha,
repo_path=repo_path, author_real_name=author_real_name,
stacks=stacks)
article.publish_status = status
article.first_commit = first_commit

commit_sha = remote.commit_file_to_github(article.full_path, message,
new_content, author_name, email,
Expand Down Expand Up @@ -508,7 +511,8 @@ def branch_article(article, message, new_content, author_name, email,

def branch_or_save_article(title, path, message, content, author_name, email,
sha, image_url, repo_path=None,
author_real_name=None, stacks=None):
author_real_name=None, stacks=None,
first_commit=None):
"""
Save article as original or as a branch depending on if given author is
the same as original article (if it already exists)
Expand All @@ -528,6 +532,7 @@ def branch_or_save_article(title, path, message, content, author_name, email,
:param author_real_name: Optional real name of author, not username
:param stacks: Optional list of stacks to associate with article (this
argument is ignored if article is branched)
:param first_commit: SHA of first commit to save with article
:returns: Article object updated, saved, or branched
"""
Expand All @@ -543,6 +548,7 @@ def branch_or_save_article(title, path, message, content, author_name, email,
return None

status = article.publish_status
first_commit = article.first_commit

if article and article.author_name != author_name and sha:
# Note branching an article cannot change the stacks!
Expand All @@ -552,7 +558,8 @@ def branch_or_save_article(title, path, message, content, author_name, email,
new = save_article(title, message, content, author_name, email,
sha, image_url=image_url, repo_path=repo_path,
author_real_name=author_real_name,
stacks=stacks, status=status)
stacks=stacks, status=status,
first_commit=first_commit)

return new

Expand Down
5 changes: 3 additions & 2 deletions pskb_website/static/js/editor_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,15 @@ var addModalMessage = function(message) {
$('#modal-error').modal()
};

function save(sha, path, secondary_repo) {
function save(sha, path, secondary_repo, first_commit) {
var data = {
'title': $('input[name=title]').val(),
'original_stack': $('input[name=original_stack]').val(),
'stacks': $('#stacks').val(),
'content': editor.getSession().getValue(),
'sha': sha,
'path': path
'path': path,
'first_commit': first_commit
}
if (secondary_repo) {
data['secondary_repo'] = 1;
Expand Down
2 changes: 1 addition & 1 deletion pskb_website/templates/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<img src="/static/img/light-logo.png" alt="hack.guides()" class="editor-ps-logo img-responsive">
</a>

<button id="btn-save" onclick="save('{{article.sha}}', '{{article.path}}', '{{secondary_repo}}')" class="btn btn-primary btn-save btn-autosize">Save</button>
<button id="btn-save" onclick="save('{{article.sha}}', '{{article.path}}', '{{secondary_repo}}', '{{'' if not article.first_commit else article.first_commit}}')" class="btn btn-primary btn-save btn-autosize">Save</button>

<button id="btn-back" onclick="back()" class="btn btn-danger btn-back btn-autosize">Back</button>

Expand Down

0 comments on commit f84dbf7

Please sign in to comment.