Exemple #1
0
def create_galley_from_file(file_object, article_object, owner=None):
    # we copy the file here so that the user submitting has no control over the typeset files
    # N.B. os.path.splitext[1] always returns the final file extension, even in a multi-dotted (.txt.html etc.) input
    new_filename = str(uuid4()) + str(
        os.path.splitext(file_object.uuid_filename)[1])
    folder_structure = os.path.join(settings.BASE_DIR, 'files', 'articles',
                                    str(article_object.id))

    old_path = os.path.join(folder_structure, str(file_object.uuid_filename))
    new_path = os.path.join(folder_structure, str(new_filename))

    copyfile(old_path, new_path)

    # clone the file model object to a new galley
    new_file = core_models.File(
        mime_type=file_object.mime_type,
        original_filename=file_object.original_filename,
        uuid_filename=new_filename,
        label=file_object.label,
        description=file_object.description,
        owner=owner,
        is_galley=True)

    new_file.save()

    core_models.Galley.objects.create(
        article=article_object,
        file=new_file,
        label=new_file.label,
    )
Exemple #2
0
    def install_cover(press, request):
        """ Installs the default cover for the press (stored in Files/press/cover.png)

        :param press: the press object
        :param request: the current request or None
        :return: None
        """

        if request:
            owner = request.user if request.user is not None and not request.user.is_anonymous else core_models.Account(
                id=1)
        else:
            owner = core_models.Account(id=1)

        thumbnail_file = core_models.File(mime_type="image/png",
                                          original_filename="cover.png",
                                          uuid_filename="cover.png",
                                          label="Press logo",
                                          description="Logo for the press",
                                          owner=owner)

        core_models.File.add_root(instance=thumbnail_file)

        press.thumbnail_image = thumbnail_file
        press.save()
Exemple #3
0
def add_file(file_mime,
             extension,
             description,
             owner,
             filename,
             article,
             galley=True,
             thumbnail=False):
    """ Add a file to the File model in core. Saves a file to the database affiliated with an article.

    :param file_mime: the MIME type of the file. Used in serving the file back to users
    :param extension: the extension of the file
    :param description: a description of the file
    :param owner: the user who owns the file
    :param filename: the filename
    :param article: the article with which the file is associated
    :param galley: whether or not this is a galley file
    :param thumbnail: whether or not this is a thumbnail
    :return: the new File object
    """

    # create a new File object with the passed parameters

    if extension.startswith('.'):
        original_filename = 'file{0}'.format(extension)
    else:
        original_filename = 'file.{0}'.format(extension)

    new_file = core_models.File(mime_type=file_mime,
                                original_filename=original_filename,
                                uuid_filename=filename,
                                label=extension.upper(),
                                description=description,
                                owner=owner,
                                is_galley=galley,
                                privacy='public',
                                article_id=article.pk)

    new_file.save()

    if thumbnail:
        article.thumbnail_image_file = new_file
        article.save()
        return new_file

    # if it is a galley, add to the list of manuscript files. Otherwise, add to the list of data files.
    if galley:
        article.manuscript_files.add(new_file)
        core_models.Galley.objects.create(
            article=article,
            file=new_file,
            is_remote=False,
            label=new_file.label,
            type=extension,
        )

    article.save()

    return new_file
Exemple #4
0
def save_file_to_article(file_to_handle,
                         article,
                         owner,
                         label=None,
                         description=None,
                         replace=None,
                         is_galley=False,
                         save=True):
    """Save a file into an article's folder with appropriate mime type and permissions.

    :param file_to_handle: the uploaded file object we need to handle
    :param article: the article to which the file belongs
    :param owner: the owner of the file
    :param label: the file's label (or title)
    :param description: the description of the item
    :param replace: the file to which this is a revision or None
    :return: a File object that has been saved in the database
    """

    if isinstance(file_to_handle, str):
        original_filename = os.path.basename(file_to_handle)
    else:
        original_filename = str(file_to_handle.name)

    # N.B. os.path.splitext[1] always returns the final file extension, even in a multi-dotted (.txt.html etc.) input
    filename = str(uuid4()) + str(os.path.splitext(original_filename)[1])
    folder_structure = os.path.join(settings.BASE_DIR, 'files', 'articles',
                                    str(article.id))

    if not os.path.exists(folder_structure):
        mkdirs(folder_structure)

    if save:
        save_file_to_disk(file_to_handle, filename, folder_structure)
        file_mime = file_path_mime(os.path.join(folder_structure, filename))
    else:
        shutil.move(
            os.path.join(folder_structure, original_filename),
            os.path.join(folder_structure, filename),
        )
        file_mime = guess_mime(filename)

    from core import models
    new_file = models.File(mime_type=file_mime,
                           original_filename=original_filename,
                           uuid_filename=filename,
                           label=label,
                           description=description,
                           owner=owner,
                           is_galley=is_galley,
                           article_id=article.pk)

    new_file.save()

    return new_file
Exemple #5
0
def upload(request):

    if request.method == "POST":
        uploadfile = request.FILES['document']
        log = request.user.username
        bookname = request.POST['book']
        b = bookname + log

        if models.File.objects.filter(filename=b).exists():
            messages.info(
                request, '*book name is already available in your repository')
            books = models.File.objects.filter(username=request.user.username)

            username = request.user.username
            data = models.My_users.objects.get(username=username)
            flag = 1
            print('not uploaded')
            return render(request, 'home.html', {'data': data, 'flag': flag})
        print('uploading........')

        client = boto3.client('s3')
        email = User.objects.get(username=log)
        email = email.email
        s = email
        data = uploadfile.read()
        s = s.replace('.', 'd')
        s = s.replace('@', 'a')
        u = log.replace(' ', 's')
        bucket_name = log + 'kumar' + s
        bucket_name = bucket_name.lower()
        print(bucket_name)
        res = client.put_object(ACL='public-read',
                                Body=data,
                                Bucket=bucket_name,
                                Key=bookname)
        print('************************')
        print('object has been uploaded')
        url = "https://" + bucket_name + ".s3.ap-south-1.amazonaws.com/" + bookname
        print(url)
        data = models.File(username=log,
                           filename=bookname + log,
                           filename_real=bookname,
                           url=url)
        data.save()

        books = models.File.objects.filter(username=request.user.username)
        print(type(uploadfile))

        print('uploaded')

        username = request.user.username
        data = models.My_users.objects.get(username=username)
        print(books)
        return render(request, 'home.html', {'data': data, 'books': books})
Exemple #6
0
def handle_review_file(_file, content_type, review_assignment, kind):
    original_filename = smart_text(
        _file._get_name().replace(',', '_').replace(';', '_')
    )
    filename = str(uuid4()) + str(path.splitext(original_filename)[1])

    if content_type == 'book':
        folder_structure = path.join(
            settings.BASE_DIR,
            'files',
            'books',
            str(review_assignment.book.id)
        )
    else:
        folder_structure = path.join(
            settings.BASE_DIR,
            'files',
            'proposals',
            str(review_assignment.proposal.id)
        )

    if not path.exists(folder_structure):
        makedirs(folder_structure)

    _path = path.join(folder_structure, str(filename))
    fd = open(_path, 'wb')
    [fd.write(chunk) for chunk in _file.chunks()]
    fd.close()
    file_mime = mime.guess_type(filename)

    try:
        file_mime = file_mime[0]
        if not file_mime:
            file_mime = 'unknown'
    except IndexError:
        file_mime = 'unknown'

    new_file = core_models.File(
        mime_type=file_mime,
        original_filename=original_filename,
        uuid_filename=filename,
        stage_uploaded=1,
        kind=kind,
        owner=review_assignment.user,
    )
    new_file.save()
    review_assignment.files.add(new_file)

    return path
Exemple #7
0
def handle_file(file, book, kind, user):  # File helpers.

    if file:
        original_filename = str(
            file._get_name()
        ).replace(
            ',', '_'
        ).replace(
            ';', '_'
        )
        filename = str(uuid4()) + str(path.splitext(file._get_name())[1])
        folder_structure = path.join(
            settings.BASE_DIR,
            'files',
            'books',
            str(book.id),
        )

        if not path.exists(folder_structure):
            makedirs(folder_structure)

        _path = path.join(folder_structure, str(filename))
        fd = open(_path, 'wb')
        [fd.write(chunk) for chunk in file.chunks()]
        fd.close()
        file_mime = mime.guess_type(filename)

        try:
            file_mime = file_mime[0]
        except IndexError:
            file_mime = 'unknown'

        if not file_mime:
            file_mime = 'unknown'

        new_file = models.File(
            mime_type=file_mime,
            original_filename=original_filename,
            uuid_filename=filename,
            stage_uploaded=1,
            kind=kind,
            owner=user,
        )
        new_file.save()
        book.files.add(new_file)
        book.save()

        return new_file
Exemple #8
0
def article_file_make_galley(request, article_id, file_id):
    """ Copies a file to be a publicly available galley

    :param request: the request associated with this call
    :param article_id: the ID of the associated articled
    :param file_id: the file ID for which to view the history
    :return: a redirect to the URL at the GET parameter 'return'
    """
    article_object = get_object_or_404(submission_models.Article,
                                       pk=article_id)
    file_object = get_object_or_404(core_models.File, pk=file_id)

    # we copy the file here so that the user submitting has no control over the typeset files
    # N.B. os.path.splitext[1] always returns the final file extension, even in a multi-dotted (.txt.html etc.) input
    new_filename = str(uuid4()) + str(
        os.path.splitext(file_object.uuid_filename)[1])
    folder_structure = os.path.join(settings.BASE_DIR, 'files', 'articles',
                                    str(article_object.id))

    old_path = os.path.join(folder_structure, str(file_object.uuid_filename))
    new_path = os.path.join(folder_structure, str(new_filename))

    copyfile(old_path, new_path)

    # clone the file model object to a new galley
    new_file = core_models.File(
        mime_type=file_object.mime_type,
        original_filename=file_object.original_filename,
        uuid_filename=new_filename,
        label=file_object.label,
        description=file_object.description,
        owner=request.user,
        is_galley=True)

    new_file.save()

    core_models.Galley.objects.create(
        article=article_object,
        file=new_file,
        label=new_file.label,
    )

    article_object.data_figure_files.add(new_file)

    return redirect(request.GET['return'])
Exemple #9
0
def handle_proposal_file(_file, proposal, kind, owner, label=None):
    original_filename = smart_text(_file._get_name()).replace(',',
                                                              '_').replace(
                                                                  ';', '_')
    filename = str(uuid4()) + str(os.path.splitext(original_filename)[1])
    folder_structure = os.path.join(
        settings.BASE_DIR,
        'files',
        'proposals',
        str(proposal.id),
    )

    if not os.path.exists(folder_structure):
        os.makedirs(folder_structure)

    path = os.path.join(folder_structure, str(filename))
    fd = open(path, 'wb')

    for chunk in _file.chunks():
        fd.write(chunk)
    fd.close()

    file_mime = mime.guess_type(filename)

    try:
        file_mime = file_mime[0]
    except IndexError:
        file_mime = 'unknown'

    if not file_mime:
        file_mime = 'unknown'

    new_file = models.File(
        mime_type=file_mime,
        original_filename=original_filename,
        uuid_filename=filename,
        stage_uploaded=1,
        kind=kind,
        label=label,
        owner=owner,
    )
    new_file.save()

    return new_file
Exemple #10
0
def copy_local_file_to_article(file_to_handle,
                               file_name,
                               article,
                               owner,
                               label=None,
                               description=None,
                               replace=None,
                               galley=False):
    """Copy a local file into an article's folder with appropriate mime type and permissions.

    :param file_to_handle: the uploaded file object we need to handle
    :param file_name: the name of the file
    :param article: the article to which the file belongs
    :param owner: the owner of the file
    :param label: the file's label (or title)
    :param description: the description of the item
    :param replace: the file to which this is a revision or None
    :return: a File object that has been saved in the database
    """

    original_filename = str(file_name)

    # N.B. os.path.splitext[1] always returns the final file extension, even in a multi-dotted (.txt.html etc.) input
    filename = str(uuid4()) + str(os.path.splitext(original_filename)[1])
    folder_structure = os.path.join(settings.BASE_DIR, 'files', 'articles',
                                    str(article.id))

    copy_file_to_folder(file_to_handle, filename, folder_structure)

    file_mime = guess_mime(filename)

    from core import models
    new_file = models.File(mime_type=file_mime,
                           original_filename=original_filename,
                           uuid_filename=filename,
                           label=label,
                           description=description,
                           owner=owner,
                           is_galley=galley,
                           article_id=article.pk)

    new_file.save()

    return new_file
Exemple #11
0
def article(request, identifier_type, identifier):
    """ Renders an article.

    :param request: the request associated with this call
    :param identifier_type: the identifier type
    :param identifier: the identifier
    :return: a rendered template of the article
    """
    article_object = submission_models.Article.get_article(
        request.journal, identifier_type, identifier)
    """
    logger.add_entry(types='Info',
                     description='Article hit for identifier {0} of type {1}'.format(identifier, identifier_type),
                     level='Info', actor=None, target=article_object)
    """

    content = None
    galleys = article_object.galley_set.all()

    # check if there is a galley file attached that needs rendering
    if article_object.stage == submission_models.STAGE_PUBLISHED:
        content = list_galleys(article_object, galleys)
    else:
        article_object.abstract = "This is an accepted article with a DOI pre-assigned that is not yet published."

    if not article_object.large_image_file or article_object.large_image_file.uuid_filename == '':
        article_object.large_image_file = core_models.File()
        # assign the default image with a hacky patch
        # TODO: this should be set to a journal-wide setting
        article_object.large_image_file.uuid_filename = "carousel1.png"
        article_object.large_image_file.is_remote = True

    store_article_access(request, article_object, 'view')

    template = 'journal/article.html'
    context = {
        'article': article_object,
        'galleys': galleys,
        'identifier_type': identifier_type,
        'identifier': identifier,
        'article_content': content
    }

    return render(request, template, context)
Exemple #12
0
def handle_review_file(file, review_assignment, kind, return_file=None):
    original_filename = smart_text(file._get_name()).replace(',', '_').replace(
        ';', '_')
    filename = str(uuid4()) + str(os.path.splitext(original_filename)[1])
    folder = "{0}s".format(review_assignment.content_type)
    folder_structure = os.path.join(settings.BASE_DIR, 'files', folder,
                                    str(review_assignment.content_object.id))

    if not os.path.exists(folder_structure):
        os.makedirs(folder_structure)

    path = os.path.join(folder_structure, str(filename))
    fd = open(path, 'wb')

    [fd.write(chunk) for chunk in file.chunks()]
    fd.close()

    file_mime = mime.guess_type(filename)

    try:
        file_mime = file_mime[0]
        if not file_mime:
            file_mime = 'unknown'
    except IndexError:
        file_mime = 'unknown'

    new_file = core_models.File(
        mime_type=file_mime,
        original_filename=original_filename,
        uuid_filename=filename,
        stage_uploaded=1,
        kind=kind,
        owner=review_assignment.user,
    )
    new_file.save()
    review_assignment.files.add(new_file)

    if return_file:
        return new_file

    return path
Exemple #13
0
def handle_onetasker_file(_file, book, assignment, kind):
    original_filename = smart_text(_file._get_name())
    filename = str(uuid4()) + str(os.path.splitext(original_filename)[1])
    folder_structure = os.path.join(
        settings.BASE_DIR,
        'files',
        'books',
        str(book.id),
    )

    if not os.path.exists(folder_structure):
        os.makedirs(folder_structure)

    path = os.path.join(folder_structure, str(filename))
    fd = open(path, 'wb')

    for chunk in _file.chunks():
        fd.write(chunk)

    fd.close()
    file_mime = mime.guess_type(filename)

    try:
        file_mime = file_mime[0]
        if not file_mime:
            file_mime = 'unknown'
    except IndexError:
        file_mime = 'unknown'

    owner = get_owner(assignment)
    new_file = models.File(
        mime_type=file_mime,
        original_filename=original_filename,
        uuid_filename=filename,
        stage_uploaded=1,
        kind=kind,
        owner=owner,
    )
    new_file.save()

    return new_file
Exemple #14
0
def install_cover(journal, request):
    """ Installs the default cover for the journal (stored in Files/journal/<id>/cover.png)

    :param journal: the journal object
    :param request: the current request or None
    :return: None
    """
    owner = request.user if request.user is not None else core_models.Account(
        id=1)

    thumbnail_file = core_models.File(mime_type="image/png",
                                      original_filename="cover.png",
                                      uuid_filename="cover.png",
                                      label="Journal logo",
                                      description="Logo for the journal",
                                      owner=owner)

    thumbnail_file.save()

    journal.thumbnail_image = thumbnail_file
    journal.save()
Exemple #15
0
def handle_marc21_file(content, name, book, owner):
    original_filename = name
    filename = str(uuid4()) + str(os.path.splitext(original_filename)[1])
    folder_structure = os.path.join(
        settings.BASE_DIR,
        'files',
        'books',
        str(book.id),
    )

    if not os.path.exists(folder_structure):
        os.makedirs(folder_structure)

    path = os.path.join(folder_structure, str(filename))
    fd = open(path, 'wb')
    fd.write(content)
    fd.close()

    file_mime = mime.guess_type(filename)

    try:
        file_mime = file_mime[0]
        if not file_mime:
            file_mime = 'unknown'
    except IndexError:
        file_mime = 'unknown'

    new_file = models.File(
        mime_type=file_mime,
        original_filename=original_filename,
        uuid_filename=filename,
        stage_uploaded=1,
        kind='marc21',
        owner=owner,
    )
    new_file.save()

    return new_file
Exemple #16
0
    def handle(self, **options):
        if not os.path.exists(options['dir']):
            raise CommandError('dir not exists')

        # models.File.objects.all().delete()

        file_exts = [i.lower() for i in models.FileExt.objects.all().values_list('file_ext', flat=True)]

        num = 1
        computer_name = get_computer_name()
        for dir_name, sub_dirs, files in os.walk(options['dir']):
            for file_name in files:
                dir_name = os.path.abspath(dir_name)
                if os.sep == '\\':
                    dir_name = dir_name.replace('\\', '/')
                full_path = os.path.join(dir_name, file_name)

                if os.path.splitext(file_name)[-1].lower() not in file_exts:
                    # print('**', full_path)
                    print(num)
                    num += 1
                    continue
                else:
                    print('--', full_path)

                kwargs = dict(computer_name=computer_name,
                              file_dir=dir_name,
                              file_name=file_name)

                file_obj_exist = False
                try:
                    file = models.File.objects.filter(**kwargs)[0]
                except IndexError:
                    file = models.File(**kwargs)
                else:
                    file_obj_exist = True

                if file_obj_exist and not options['new_scan']:
                    print('** skip')
                    continue

                file_hash = get_file_hash(full_path)

                file_hash_obj,c = models.FileHash.objects.get_or_create(file_hash=file_hash)

                file_size = get_file_size(full_path)

                if not file_obj_exist:
                    file.file_exist = True
                    file.file_size = file_size
                    file.file_hash_obj = file_hash_obj
                    file.save()

                if options['new_scan']:
                    if file_obj_exist:
                        uf = []
                        if file.file_exist != True:
                            file.file_exist = True
                            uf.append('file_exist')
                        if file.file_size != file_size:
                            file.file_size = file_size
                            uf.append('file_size')
                        if file.file_hash_obj != file_hash_obj:
                            file.file_hash_obj = file_hash_obj
                            uf.append('file_hash_obj')
                        if uf:
                            file.save(update_fields=uf)

                    file_scan = models.FileScan(file=file)
                    file_scan.file_exist = True
                    file_scan.file_size = file_size
                    file_scan.file_hash = file_hash
                    file_scan.save()
Exemple #17
0
    def setUp(self):
        """
        Setup the test environment.
        :return: None
        """
        self.journal_one, self.journal_two = self.create_journals()
        self.create_roles([
            "editor", "author", "reviewer", "proofreader", "production",
            "copyeditor", "typesetter", "proofing_manager", "section-editor"
        ])

        self.regular_user = self.create_user("*****@*****.**")
        self.regular_user.is_active = True
        self.regular_user.save()

        self.second_user = self.create_user("*****@*****.**",
                                            ["reviewer"],
                                            journal=self.journal_one)
        self.second_user.is_active = True
        self.second_user.save()

        self.admin_user = self.create_user("*****@*****.**")
        self.admin_user.is_staff = True
        self.admin_user.is_active = True
        self.admin_user.save()

        self.inactive_user = self.create_user(
            "*****@*****.**",
            ["editor", "author", "proofreader", "production"],
            journal=self.journal_one)
        self.inactive_user.is_active = False
        self.inactive_user.save()

        self.editor = self.create_user("*****@*****.**", ["editor"],
                                       journal=self.journal_one)
        self.editor.is_active = True
        self.editor.save()

        self.author = self.create_user("*****@*****.**", ["author"],
                                       journal=self.journal_one)
        self.author.is_active = True
        self.author.save()

        self.proofreader = self.create_user("*****@*****.**",
                                            ["proofreader"],
                                            journal=self.journal_one)
        self.proofreader.is_active = True
        self.proofreader.save()

        self.proofreader_two = self.create_user("*****@*****.**",
                                                ["proofreader"],
                                                journal=self.journal_one)
        self.proofreader_two.is_active = True
        self.proofreader_two.save()

        self.production = self.create_user("*****@*****.**",
                                           ["production"],
                                           journal=self.journal_one)
        self.production.is_active = True
        self.production.save()

        self.copyeditor = self.create_user("*****@*****.**",
                                           ["copyeditor"],
                                           journal=self.journal_one)
        self.copyeditor.is_active = True
        self.copyeditor.save()

        self.typesetter = self.create_user("*****@*****.**",
                                           ["typesetter"],
                                           journal=self.journal_one)
        self.typesetter.is_active = True
        self.typesetter.save()

        self.other_typesetter = self.create_user(
            "*****@*****.**", ["typesetter"],
            journal=self.journal_one)
        self.other_typesetter.is_active = True
        self.other_typesetter.save()

        self.proofing_manager = self.create_user(
            "*****@*****.**", ["proofing_manager"],
            journal=self.journal_one)
        self.proofing_manager.is_active = True
        self.proofing_manager.save()

        self.other_typesetter.is_active = True
        self.other_typesetter.save()

        self.section_editor = self.create_user("*****@*****.**",
                                               ['section-editor'],
                                               journal=self.journal_one)
        self.section_editor.is_active = True
        self.section_editor.save()

        self.second_reviewer = self.create_user(
            "*****@*****.**", ['reviewer'],
            journal=self.journal_one)
        self.second_reviewer.is_active = True
        self.second_reviewer.save()

        self.public_file = core_models.File(mime_type="A/FILE",
                                            original_filename="blah.txt",
                                            uuid_filename="UUID.txt",
                                            label="A file that is public",
                                            description="Oh yes, it's a file",
                                            owner=self.regular_user,
                                            is_galley=False,
                                            privacy="public")

        self.public_file.save()

        self.private_file = core_models.File(mime_type="A/FILE",
                                             original_filename="blah.txt",
                                             uuid_filename="UUID.txt",
                                             label="A file that is private",
                                             description="Oh yes, it's a file",
                                             owner=self.regular_user,
                                             is_galley=False,
                                             privacy="owner")

        self.private_file.save()

        self.article_in_production = submission_models.Article(
            owner=self.regular_user,
            title="A Test Article",
            abstract="An abstract",
            stage=submission_models.STAGE_TYPESETTING,
            journal_id=self.journal_one.id)
        self.article_in_production.save()
        self.article_in_production.data_figure_files.add(self.public_file)

        self.article_unsubmitted = submission_models.Article(
            owner=self.regular_user,
            title="A Test Article",
            abstract="An abstract",
            stage=submission_models.STAGE_UNSUBMITTED,
            journal_id=self.journal_one.id)
        self.article_unsubmitted.save()

        self.article_unassigned = submission_models.Article(
            owner=self.regular_user,
            title="A Test Article",
            abstract="An abstract",
            stage=submission_models.STAGE_UNASSIGNED,
            journal_id=self.journal_one.id)
        self.article_unassigned.save()

        self.article_assigned = submission_models.Article(
            owner=self.regular_user,
            title="A Test Article",
            abstract="An abstract",
            stage=submission_models.STAGE_ASSIGNED,
            journal_id=self.journal_one.id)
        self.article_assigned.save()

        self.article_under_review = submission_models.Article(
            owner=self.regular_user,
            title="A Test Article",
            abstract="An abstract",
            stage=submission_models.STAGE_UNDER_REVIEW,
            journal_id=self.journal_one.id)
        self.article_under_review.save()

        self.article_review_completed = submission_models.Article.objects.create(
            owner=self.regular_user,
            title="A Test Article",
            abstract="An abstract",
            stage=submission_models.STAGE_ACCEPTED,
            journal_id=self.journal_one.id,
            date_accepted=timezone.now())

        self.article_author_is_owner = submission_models.Article.objects.create(
            owner=self.author,
            title="A Test Article",
            abstract="An abstract",
            stage=submission_models.STAGE_ACCEPTED,
            journal_id=self.journal_one.id,
            date_accepted=timezone.now())

        self.article_author_is_owner.authors.add(self.editor)
        self.article_author_is_owner.authors.add(self.author)

        self.review_form = review_models.ReviewForm(name="A Form",
                                                    slug="A Slug",
                                                    intro="i",
                                                    thanks="t",
                                                    journal=self.journal_one)
        self.review_form.save()

        self.review_assignment_complete = review_models.ReviewAssignment(
            article=self.article_review_completed,
            reviewer=self.regular_user,
            editor=self.editor,
            date_due=datetime.datetime.now(),
            form=self.review_form,
            is_complete=True,
            date_complete=timezone.now())

        self.review_assignment_complete.save()

        self.review_assignment = review_models.ReviewAssignment(
            article=self.article_under_review,
            reviewer=self.second_user,
            editor=self.editor,
            date_due=datetime.datetime.now(),
            form=self.review_form)

        self.review_assignment.save()

        self.review_assignment_not_in_scope = review_models.ReviewAssignment(
            article=self.article_in_production,
            reviewer=self.regular_user,
            editor=self.editor,
            date_due=datetime.datetime.now(),
            form=self.review_form)
        self.review_assignment_not_in_scope.save()

        self.article_under_revision = submission_models.Article(
            owner=self.regular_user,
            title="A Test Article",
            abstract="An abstract",
            stage=submission_models.STAGE_UNDER_REVISION,
            journal_id=self.journal_one.id)
        self.article_under_revision.save()

        self.article_rejected = submission_models.Article(
            owner=self.regular_user,
            title="A Test Article",
            abstract="An abstract",
            stage=submission_models.STAGE_REJECTED,
            journal_id=self.journal_one.id)
        self.article_rejected.save()

        self.article_accepted = submission_models.Article(
            owner=self.regular_user,
            title="A Test Article",
            abstract="An abstract",
            stage=submission_models.STAGE_ACCEPTED,
            journal_id=self.journal_one.id)
        self.article_accepted.save()

        self.section_editor_assignment = review_models.EditorAssignment(
            article=self.article_assigned,
            editor=self.section_editor,
            editor_type='section-editor',
            notified=True)
        self.section_editor_assignment.save()

        self.article_editor_copyediting = submission_models.Article(
            owner=self.regular_user,
            title="A Test Article",
            abstract="An abstract",
            stage=submission_models.STAGE_EDITOR_COPYEDITING,
            journal_id=self.journal_one.id)
        self.article_editor_copyediting.save()

        self.article_author_copyediting = submission_models.Article(
            owner=self.regular_user,
            title="A Test Article",
            abstract="An abstract",
            stage=submission_models.STAGE_AUTHOR_COPYEDITING,
            journal_id=self.journal_one.id)
        self.article_author_copyediting.save()

        self.article_final_copyediting = submission_models.Article(
            owner=self.regular_user,
            title="A Test Article",
            abstract="An abstract",
            stage=submission_models.STAGE_FINAL_COPYEDITING,
            journal_id=self.journal_one.id)
        self.article_final_copyediting.save()

        self.article_proofing = submission_models.Article(
            owner=self.regular_user,
            title="A Test Article",
            abstract="An abstract",
            stage=submission_models.STAGE_PROOFING,
            journal_id=self.journal_one.id)
        self.article_proofing.save()

        assigned = production_models.ProductionAssignment(
            article=self.article_in_production,
            production_manager=self.production)
        assigned.save()

        self.article_published = submission_models.Article(
            owner=self.regular_user,
            title="A Second Test Article",
            abstract="An abstract",
            stage=submission_models.STAGE_PUBLISHED,
            journal_id=self.journal_one.id)
        self.article_published.save()

        assigned = production_models.ProductionAssignment(
            article=self.article_published, production_manager=self.production)
        assigned.save()

        self.article_in_production_inactive = submission_models.Article(
            owner=self.regular_user,
            title="A Test Article",
            abstract="An abstract",
            stage=submission_models.STAGE_TYPESETTING,
            journal_id=self.journal_one.id)
        self.article_in_production_inactive.save()

        self.assigned = production_models.ProductionAssignment(
            article=self.article_in_production_inactive,
            production_manager=self.inactive_user)
        self.assigned.save()

        self.copyedit_assignment = copyediting_models.CopyeditAssignment(
            article=self.article_editor_copyediting,
            editor=self.editor,
            copyeditor=self.copyeditor,
            due=timezone.now(),
            assigned=timezone.now(),
            notified=timezone.now(),
            decision='accepted',
            date_decided=timezone.now())
        self.copyedit_assignment.save()

        self.typeset_task = production_models.TypesetTask(
            assignment=self.assigned,
            typesetter=self.typesetter,
            notified=True,
            accepted=timezone.now())
        self.typeset_task.save()

        self.other_typeset_task = production_models.TypesetTask(
            assignment=self.assigned,
            typesetter=self.other_typesetter,
            notified=True,
            accepted=timezone.now())
        self.other_typeset_task.save()

        self.proofing_assignment = proofing_models.ProofingAssignment(
            article=self.article_proofing,
            proofing_manager=self.proofing_manager,
            notified=True)
        self.proofing_assignment.save()
        self.proofing_assignment.add_new_proofing_round()

        self.proofing_task = proofing_models.ProofingTask(
            round=self.proofing_assignment.current_proofing_round(),
            proofreader=self.proofreader,
            notified=True,
            due=timezone.now(),
            accepted=timezone.now(),
            task='sdfsdffs')
        self.proofing_task.save()

        self.correction_task = proofing_models.TypesetterProofingTask(
            proofing_task=self.proofing_task,
            typesetter=self.typesetter,
            notified=True,
            due=timezone.now(),
            accepted=timezone.now(),
            task='fsddsff')
        self.correction_task.save()

        self.journal_one.name = 'Journal One'
        self.journal_two.name = 'Journal Two'
        self.press = press_models.Press.objects.create(name='Press',
                                                       domain='localhost',
                                                       main_contact='*****@*****.**')
        self.press.save()
        call_command('sync_journals_to_sites')