Comments (3)
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.
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.
Regarding the bug: I agree that it's minor enough to not warrant a complex fix.
from ethics.
Related Issues (20)
- Compare pdf's - textual change
- Integrate integration platform
- 'applicants' cannot be None, when 'other_applicants' is False HOT 1
- Upgrade to Django 4.2
- Forms in case of public interest - textual change
- Datamanagement en Privacy - link to online training
- Break up page 1 HOT 5
- Figure out where WMOCheck is used HOT 1
- Problem with editing of pre aproved proposals by supervisors HOT 1
- Direct link to application in automatic mails?
- Rework form pages into the new DSC3 CSS
- Other stakeholders need more info
- Change how we ask funding info
- Wilsonbekwame (volwassen) deelnemers
- Bijzondere persoonsgegevens
- Observation - Wordt er anoniem geobserveerd?
- Niet verder in behandeling genomen - dates are swopped HOT 2
- Add application/zip as mimetype for docx files
- Figure out table styling for the proposal form.
- Styling for task and session display
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ethics.