def submit_article(request, article_name=None): message = None if article_name: pk = decrypt_text(article_name) dt = datetime.today() try: art_info = Article.objects.get(id__exact=pk) try: ArticleFile.objects.get(main=True, article=art_info) art_info.is_submitted = True art_info.date_submitted = dt art_info.state = 'ACC' art_info.save() except ArticleFile.DoesNotExist or ArticleFile: request.session[ 'joumsy_message'] = "Please Complete Submission" direct = '/articles/submission_info/' + encrypt_text( str(art_info.id)) return HttpResponseRedirect(direct) message = art_info.title + '- has been submitted.' request.session['joumsy_message'] = message except Article.DoesNotExist or Article: message = 'Invalid Data.<a href="articles/articles-list/"> Click here</a> to see article list' return HttpResponse(message) direct = '/articles/submission_info/' + encrypt_text(str(art_info.id)) return HttpResponseRedirect(direct) return HttpResponse(message)
def article_meta_save(request): message = None if request.method == 'POST': art_form = ArticleForm(request.POST, request.FILES) if art_form.is_valid(): dt = datetime.today() curr = request.user article_meta = Article( section=art_form.cleaned_data['section'], title=art_form.cleaned_data['title'], # subtitle = models.CharField(max_length=300, null = True) # cover_letter = models.CharField(max_length=500, null = True) references=art_form.cleaned_data['references'], #keywords = art_form.cleaned_data['keywords'], # journal = art_form.cleaned_data['journal'] # copyright = models.ForeignKey(Copyright, null=True) is_featured=False, article_version=0, published_by_others=False, is_submitted=False, abstract=art_form.cleaned_data['abstract'], likes=0, pub_date=None, date_created=dt, require_review=True, restrict_access_article=False, date_modified=None, submitting_author=curr, ) article_meta.save() # if request.user: artauth = ArticleAuthor( author=User.objects.get(username=curr), article=article_meta, date_added=dt, main_author=True, ) artauth.save() if 'main_file' in request.FILES: # print(request.FILES['image_path']) art_file = request.FILES['main_file'] a_file = ArticleFile(file_name=art_file.name, file_path=art_file, article=article_meta, date_created=dt, uploader=request.user, state='AUTH', main=True, stage=1) a_file.save() return HttpResponseRedirect('/articles/submission/' + encrypt_text(str(article_meta.id)) + '/authors/')
def accept_review(request, ref_det=None): if not request.user.is_authenticated(): return HttpResponseRedirect('/sign-in/') message = None pk = decrypt_text(ref_det) art_info = None art_auths = None dt = datetime.datetime.now() try: rev_info = ReviewDetails.objects.get(id__exact=pk) print(rev_info.article.title, '--rev_article----') rev_info.invitation_accepted = True rev_info.is_active = True rev_info.date_confirmed = dt rev_info.save() # rev_info.article.status='REV' # rev_info.article.save() # check if updating article state is_saved art_auths = ArticleAuthor.objects.filter(article=rev_info.article) art_files = ArticleFile.objects.filter(article=rev_info.article, state='SUP') return HttpResponseRedirect('/reviews/submission_meta/' + encrypt_text(str(rev_info.id)) + '/') # message=art_info.title +'- Article .<a href="/articles/articles-list/"> Click here</a> to see article list' except ReviewDetails.DoesNotExist or Article: message = 'Invalid Data.<a href="/reviews/"> Click here</a> to see article list' return HttpResponse(message) return HttpResponseRedirect('/reviews/submission_meta/' + encrypt_text(str(rev_info.id)) + '/')
def review_form_save(request, ref_det=None): if not request.user.is_authenticated(): return HttpResponseRedirect('/sign-in/') pk = decrypt_text(ref_det) art_info = None art_auths = None dt = datetime.datetime.now() if request.method == 'POST': rev_form = Review_Submission_Form(request.POST, request.FILES) try: rev_info = ReviewDetails.objects.get(id__exact=pk) print(rev_info.article.title, '--rev_article----') rev_info.recommendation = request.POST.get('recommendation') rev_info.acceptability = request.POST.get('acceptability') rev_info.clarity = request.POST.get('clarity') rev_info.quality = request.POST.get('quality') rev_info.abstract_review = request.POST.get('abstract_review') rev_info.comments_for_editor = request.POST.get( 'comments_for_editor') rev_info.comments_for_author = request.POST.get( 'comments_for_author') rev_info.save() art_auths = ArticleAuthor.objects.filter(article=rev_info.article) art_files = ArticleFile.objects.filter(article=rev_info.article, state='SUP') return HttpResponseRedirect('/reviews/submission_meta/' + encrypt_text(str(rev_info.id))) # message=art_info.title +'- Article .<a href="/articles/articles-list/"> Click here</a> to see article list' except ReviewDetails.DoesNotExist or Article: message = 'Invalid Data.<a href="articles/articles-list/"> Click here</a> to see article list' return HttpResponse(message) else: return HttpResponseRedirect("Denied")
def update_article_info(request, article_name=None): message = None main_file = None if article_name: pk = decrypt_text(article_name) try: art_info = Article.objects.get(id__exact=pk) # request.session['article'] = pk # message=art_info.title +'- Article .<a href="/articles/articles-list/"> Click here</a> to see article list' if ArticleFile.objects.filter(article=art_info, main=True).exists(): main_file = ArticleFile.objects.get(article=art_info, main=True) except Article.DoesNotExist or Article: message = 'Invalid Data.<a href="articles/articles-list/"> Click here</a> to see article list' return HttpResponse(message) art_form = ArticleForm(initial=model_to_dict(art_info)) return render( request, 'articles/article_submission.html', { 'system_name': 'Article Form', 'meta_form': art_form, 'art_meta': 'active', 'art_info': art_info, 'main_file': main_file, }) else: if request.method == 'POST': artform = ArticleForm(request.POST, request.FILES) print("we got the form") dt = datetime.today() if artform.is_valid(): print("checking for duplicate file", ) # old = request.session['article'] old = request.POST.get('art_detail') old_art = Article.objects.get(id=old) check = False # datetime.today() try: pasyente = Article.objects.exclude( id__exact=old_art.id).get( title__iexact=request.POST.get('title')) check = True message = 'Article Info exist.' except Article.DoesNotExist or Article: pass if not check: print("no duplicate") old_art.title = artform.cleaned_data['title'] old_art.section = artform.cleaned_data['section'] old_art.references = artform.cleaned_data['references'] old_art.keywords = artform.cleaned_data['keywords'] old_art.abstract = artform.cleaned_data['abstract'] old_art.is_featured = False old_art.pub_date = None old_art.require_review = False date_modified = dt old_art.save() if 'main_file' in request.FILES: # print(request.FILES['image_path']) art_file = request.FILES['main_file'] if ArticleFile.objects.filter(article=old_art, main=True).exists(): main_art_file = ArticleFile.objects.get( article=old_art, main=True) os.unlink(main_art_file.file_path.path) main_art_file.file_name = art_file.name + '_1' main_art_file.file_path = art_file main_art_file.date_created = dt main_art_file.save() else: a_file = ArticleFile(file_name=art_file.name, file_path=art_file, article=old_art, date_created=dt, uploader=request.user, state='AUTH', main=True, stage=1) a_file.save() # saved_pats = str(request.session['patient']) + patientform.cleaned_data['firstname'] + patientform.cleaned_data['lastname'] # delete session # del request.session['article'] # request.session['article_auths'] request.session[ 'updated_succ_messages'] = 'Article Successfully updated.' direct = ('/articles/submission/' + encrypt_text(str(old_art.id))) return HttpResponseRedirect(direct) else: return HttpResponseRedirect('/error-404/') else: print("form is not valid") main_file = None old = request.POST.get('art_detail') if ArticleFile.objects.filter(article=art_info, main=True).exists(): main_file = ArticleFile.objects.get(article=art_info, main=True) art_info = Article.objects.get(id=old) form = ArticleForm() form.fields['title'].initial = request.POST.get('title') form.fields['abstract'].initial = request.POST.get('abstract') form.fields['keywords'].initial = request.POST.get('keywords') form.fields['references'].initial = request.POST.get( 'references') # del request.session['article'] return render( request, 'articles/article_submission.html', { 'system_name': 'Article Form', 'meta_form': form, 'art_meta': 'active', 'art_info': art_info, 'message': 'Please fill form properly. Unable to update data.', 'main_file': main_file, }) return HttpResponse(message)
def encrypts(value, args): if args == 'encrypt': encrypted = encrypt_text(str(value)) return encrypted return value
def assign_editor(request): art_det = request.GET.get('art_curr') edie = request.GET.get('ass_editor') enddate = request.GET.get('date_due') edie_id = decrypt_text(edie) pk= decrypt_text(art_det) if not request.user.is_authenticated(): return HttpResponseRedirect('/sign-in/') message="" dt = datetime.datetime.now() art_info=None outs=None chk=False # try: # with transaction.atomic(): try: eddie = User.objects.get(id=edie_id) chk=True print('Getting User editor Info') try: art_info = Article.objects.get(id__exact=pk) print('Getting article Info') has_assigned=hasAssignedEditor(art_info,'article') if not has_assigned: accept= False if eddie.id == request.user.id: accept= True # article has been assigned notify other user assign_eddie = AssignEditor( assoc_editor = eddie, article = art_info, date_assigned = dt, can_edit = True, can_review = True, date_notified = dt, assigned_by = request.user, is_accepted = accept, ) assign_eddie.save() art_info.state='REV' art_info.date_review_start=dt art_info.save() # print(get_editor_assign_template('assign_editor', eddie.id ,art_info.id, request.user)) # notif_message= JMSMessage( # creator = request.user, # target = eddie # content = 'content', # title = 'title', # is_opened = False, # date_sent = dt, # # date_update = # ) # notif_message.save() outs={ 'success':'yes', 'art_title':art_info.title, 'ass_edit':eddie.first_name+', '+eddie.last_name, 'ass_edit_info':eddie.id, 'art_ident':encrypt_text(str(art_info.id)), } art_log= ArticleSubmissionLog( creator = request.user, # desc of work done work_desc = 'Assigned Editor '+ eddie.username +' to article '+ str( art_info.id), # dictionary of model and id att_obj = str(eddie.id)+'-'+'AssignEditor', ) art_log.save() else: chk=False message="Article has been assigned" except Article.DoesNotExist or Article: message='Invalid Data.<a href="articles/articles-list/"> Click here</a> to see article list' return HttpResponse(message) except User.DoesNotExist or User: chk= False # except: # message ='Unable to assign Editor. Some error occurs.' # print('Unable to process editor decision. Some error occurs.') if chk: data=outs else: data={ 'success':'no', 'message': message, } json_response = json.dumps(data) return HttpResponse(json_response, content_type="application/json")
def assign_accept_editor(request): edie = request.GET.get('ass_editor') edie_id = decrypt_text(edie) if not request.user.is_authenticated(): return HttpResponseRedirect('/sign-in/') message = "" dt = datetime.datetime.now() art_info = None outs = None chk = False eddie =None try: with transaction.atomic(): try: eddie = AssignEditor.objects.get(id=edie_id) chk=True has_assigned=hasAssignedEditor(eddie.article,'article') if not has_assigned: eddie.is_accepted=True eddie.save() print('asdasd---',eddie.assoc_editor.username) art_log= ArticleSubmissionLog( creator = request.user, # desc of work done work_desc = 'Accepted role - Assigned Editor -'+ eddie.assoc_editor.username +' - to article -'+ str( eddie.article.id), # dictionary of model and id att_obj = str(eddie.id)+'-'+'AssignEditor', ) art_log.save() outs={ 'success':'yes', 'art_title':eddie.article.title, 'ass_edit':eddie.assoc_editor.first_name+', '+eddie.assoc_editor.last_name, 'ass_edit_info':eddie.id, 'art_ident':encrypt_text(str(eddie.article.id)), } else: chk=False message="Article has been assigned" except AssignEditor.DoesNotExist or AssignEditor: chk= False except: print('accept-assign not saved. error occurs on data insertion!') if chk: data=outs else: data={ 'success':'no', 'message': message, } json_response = json.dumps(data) return HttpResponse(json_response, content_type="application/json")