Coder Social home page Coder Social logo

New reference number format about ethics HOT 3 CLOSED

tymees avatar tymees commented on July 30, 2024
New reference number format

from ethics.

Comments (3)

tymees avatar tymees commented on July 30, 2024

A proposal for the new generate_ref_number:

def generate_ref_number():
    """
    Generates a reference number for a new(!) Proposal.
    NOTE: Use generate_revision_ref_number to create reference numbers for
    revisions! This function will always create a new ref.num. with version = 1
    :return: a reference number in the format {nr}-{vr}-{current_year}, 
    where nr is the number of Proposals created  in the current year excluding 
    revisions. Vr is the version of this proposal, this function will always return vr = 1.
    """
    from ..models import Proposal

    # Set default values
    current_year = datetime.now().year
    proposal_number = 1
    version_number = 1

    try:
        # We count all proposals for this year by selecting all proposals
        # with a reference number ending with the current year.
        num_proposals = Proposal.objects.filter(
            reference_number__endswith=current_year,
        ).count()
        proposal_number = num_proposals + 1
    except Proposal.DoesNotExist:
        # Should not happen(TM)
        pass

    return '{:02}-{:02}-{}'.format(
        proposal_number,
        version_number,
        current_year
    )

I've used a slightly different format than in my initial post: 'nr-vr-year'. This way the function doesn't have to be aware of the older formats to work, as they all have the year at the end.

from ethics.

tymees avatar tymees commented on July 30, 2024

Ended up with a slightly different implementation, it was easier to just check the created_on variable in the count query.

My implementation is in PR #90

There is a small bug however:
If you have Proposal A with an old ref-num and make a revision B with A as parent, everything is fine. (20-001-02)
If you then make a revision C with B as parent, everything is still fine. (20-001-03)
If you then make revision D with A as parent again, you will be given the ref number 20-002-02.

It's actually very hard to solve this, as the function that generates a new ref number from old ref numbers cannot be aware of any revisions with the new ref.num. (There is simply no easy way of finding those without the new proposal number used by the other revisions).

To be honest, I don't think it's a big problem. At least not big enough to justify the effort of fixing it

from ethics.

JeltevanBoheemen avatar JeltevanBoheemen commented on July 30, 2024

Regarding the bug: I agree that it's minor enough to not warrant a complex fix.

from ethics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.