mirror of https://github.com/stijndcl/didier
				
				
				
			Start working on new roles
							parent
							
								
									225cc8129e
								
							
						
					
					
						commit
						c79c478ab4
					
				|  | @ -0,0 +1,32 @@ | |||
| """Add second role to ufora courses | ||||
| 
 | ||||
| Revision ID: 11388e39bb90 | ||||
| Revises: a64876b41af2 | ||||
| Create Date: 2022-09-25 00:09:06.625622 | ||||
| 
 | ||||
| """ | ||||
| import sqlalchemy as sa | ||||
| 
 | ||||
| from alembic import op | ||||
| 
 | ||||
| # revision identifiers, used by Alembic. | ||||
| revision = "11388e39bb90" | ||||
| down_revision = "a64876b41af2" | ||||
| branch_labels = None | ||||
| depends_on = None | ||||
| 
 | ||||
| 
 | ||||
| def upgrade() -> None: | ||||
|     # ### commands auto generated by Alembic - please adjust! ### | ||||
|     with op.batch_alter_table("ufora_courses", schema=None) as batch_op: | ||||
|         batch_op.add_column(sa.Column("alternative_overarching_role_id", sa.BigInteger(), nullable=True)) | ||||
| 
 | ||||
|     # ### end Alembic commands ### | ||||
| 
 | ||||
| 
 | ||||
| def downgrade() -> None: | ||||
|     # ### commands auto generated by Alembic - please adjust! ### | ||||
|     with op.batch_alter_table("ufora_courses", schema=None) as batch_op: | ||||
|         batch_op.drop_column("alternative_overarching_role_id") | ||||
| 
 | ||||
|     # ### end Alembic commands ### | ||||
|  | @ -254,6 +254,8 @@ class UforaCourse(Base): | |||
|     compulsory: bool = Column(Boolean, server_default="1", nullable=False) | ||||
|     role_id: Optional[int] = Column(BigInteger, nullable=True, unique=False) | ||||
|     overarching_role_id: Optional[int] = Column(BigInteger, nullable=True, unique=False) | ||||
|     # This is not the greatest fix, but there can only ever be two, so it will do the job | ||||
|     alternative_overarching_role_id: Optional[int] = Column(BigInteger, nullable=True, unique=False) | ||||
|     log_announcements: bool = Column(Boolean, server_default="0", nullable=False) | ||||
| 
 | ||||
|     announcements: list[UforaAnnouncement] = relationship( | ||||
|  |  | |||
|  | @ -0,0 +1,160 @@ | |||
| from sqlalchemy.ext.asyncio import AsyncSession | ||||
| 
 | ||||
| from database.engine import DBSession | ||||
| from database.schemas import UforaCourse, UforaCourseAlias | ||||
| 
 | ||||
| __all__ = ["main"] | ||||
| 
 | ||||
| 
 | ||||
| async def main(): | ||||
|     """Add the Ufora courses for the 2022-2023 academic year""" | ||||
|     session: AsyncSession | ||||
|     async with DBSession() as session: | ||||
|         """3rd Bachelor""" | ||||
|         artificiele_intelligentie = UforaCourse( | ||||
|             code="C003756", | ||||
|             name="Artificiële Intelligentie", | ||||
|             year=3, | ||||
|             compulsory=True, | ||||
|             role_id=891743671022673920, | ||||
|             overarching_role_id=891743208248324196, | ||||
|         ) | ||||
| 
 | ||||
|         algoritmen_datastructuren_3 = UforaCourse( | ||||
|             code="C003782", | ||||
|             name="Algoritmen en Datastructuren 3", | ||||
|             year=3, | ||||
|             compulsory=True, | ||||
|             role_id=891743791466307654, | ||||
|             overarching_role_id=891743208248324196, | ||||
|         ) | ||||
| 
 | ||||
|         automaten_berekenbaarheid_complexiteit = UforaCourse( | ||||
|             code="C003785", | ||||
|             name="Automaten, Berekenbaarheid en Complexiteit", | ||||
|             year=3, | ||||
|             compulsory=True, | ||||
|             role_id=891744082404200539, | ||||
|             overarching_role_id=891743208248324196, | ||||
|         ) | ||||
| 
 | ||||
|         besturingssystemen = UforaCourse( | ||||
|             code="E019010", | ||||
|             name="Besturingssystemen", | ||||
|             year=3, | ||||
|             compulsory=True, | ||||
|             role_id=891743898291032114, | ||||
|             overarching_role_id=891743208248324196, | ||||
|         ) | ||||
| 
 | ||||
|         computationele_biologie = UforaCourse( | ||||
|             code="C003789", | ||||
|             name="Computationele Biologie", | ||||
|             year=3, | ||||
|             compulsory=True, | ||||
|             role_id=891744050988847135, | ||||
|             overarching_role_id=891743208248324196, | ||||
|         ) | ||||
| 
 | ||||
|         logisch_programmeren = UforaCourse( | ||||
|             code="C003783", | ||||
|             name="Logisch Programmeren", | ||||
|             year=3, | ||||
|             compulsory=True, | ||||
|             role_id=891743966482034800, | ||||
|             overarching_role_id=891743208248324196, | ||||
|         ) | ||||
| 
 | ||||
|         software_engineering_lab_2 = UforaCourse( | ||||
|             code="C003784", | ||||
|             name="Software Engineering Lab 2", | ||||
|             year=3, | ||||
|             compulsory=True, | ||||
|             role_id=891744007300980737, | ||||
|             overarching_role_id=891743208248324196, | ||||
|         ) | ||||
| 
 | ||||
|         modelleren_en_simuleren = UforaCourse( | ||||
|             course_id=636139, | ||||
|             code="C003786", | ||||
|             name="Modelleren en Simuleren", | ||||
|             year=3, | ||||
|             compulsory=True, | ||||
|             overarching_role_id=891744461405687808, | ||||
|             log_announcements=True, | ||||
|         ) | ||||
| 
 | ||||
|         informatiebeveiliging = UforaCourse( | ||||
|             code="E019400", | ||||
|             name="Informatiebeveiliging", | ||||
|             year=3, | ||||
|             compulsory=True, | ||||
|             role_id=1023333190678626314, | ||||
|             overarching_role_id=891744461405687808, | ||||
|             alternative_overarching_role_id=1023278462733127710, | ||||
|         ) | ||||
| 
 | ||||
|         parallelle_computersystemen = UforaCourse( | ||||
|             code="E034140", | ||||
|             name="Parallelle Computersystemen", | ||||
|             year=3, | ||||
|             compulsory=True, | ||||
|             role_id=1023300295918358691, | ||||
|             overarching_role_id=891744461405687808, | ||||
|             alternative_overarching_role_id=1023278462733127710, | ||||
|         ) | ||||
| 
 | ||||
|         session.add_all( | ||||
|             [ | ||||
|                 artificiele_intelligentie, | ||||
|                 algoritmen_datastructuren_3, | ||||
|                 automaten_berekenbaarheid_complexiteit, | ||||
|                 besturingssystemen, | ||||
|                 computationele_biologie, | ||||
|                 logisch_programmeren, | ||||
|                 software_engineering_lab_2, | ||||
|                 modelleren_en_simuleren, | ||||
|                 informatiebeveiliging, | ||||
|                 parallelle_computersystemen, | ||||
|             ] | ||||
|         ) | ||||
|         await session.commit() | ||||
| 
 | ||||
|         """Aliases""" | ||||
|         ai = UforaCourseAlias(course_id=artificiele_intelligentie.course_id, alias="AI") | ||||
|         ad3 = UforaCourseAlias(course_id=algoritmen_datastructuren_3.course_id, alias="AD3") | ||||
|         abc = (UforaCourseAlias(course_id=automaten_berekenbaarheid_complexiteit.course_id, alias="ABC"),) | ||||
|         bs = UforaCourseAlias(course_id=besturingssystemen.course_id, alias="BS") | ||||
|         compbio = UforaCourseAlias(course_id=computationele_biologie.course_id, alias="Compbio") | ||||
|         logprog = UforaCourseAlias(course_id=logisch_programmeren.course_id, alias="LogProg") | ||||
|         prolog = UforaCourseAlias(course_id=logisch_programmeren.course_id, alias="Prolog") | ||||
|         sel2 = UforaCourseAlias(course_id=software_engineering_lab_2.course_id, alias="SEL2") | ||||
|         selab2 = UforaCourseAlias(course_id=software_engineering_lab_2.course_id, alias="SELab2") | ||||
|         modsim = UforaCourseAlias(course_id=modelleren_en_simuleren.course_id, alias="ModSim") | ||||
|         infosec = UforaCourseAlias(course_id=informatiebeveiliging.course_id, alias="InfoSec") | ||||
|         information_security = UforaCourseAlias(course_id=informatiebeveiliging.course_id, alias="Information Security") | ||||
|         pcs = UforaCourseAlias(course_id=parallelle_computersystemen.course_id, alias="PCS") | ||||
|         parallel_computer_systems = UforaCourseAlias( | ||||
|             parallelle_computersystemen.course_id, alias="Parallel Computer Systems" | ||||
|         ) | ||||
| 
 | ||||
|         session.add_all( | ||||
|             [ | ||||
|                 ai, | ||||
|                 ad3, | ||||
|                 abc, | ||||
|                 bs, | ||||
|                 compbio, | ||||
|                 logprog, | ||||
|                 prolog, | ||||
|                 sel2, | ||||
|                 selab2, | ||||
|                 modsim, | ||||
|                 infosec, | ||||
|                 information_security, | ||||
|                 pcs, | ||||
|                 parallel_computer_systems, | ||||
|             ] | ||||
|         ) | ||||
| 
 | ||||
|         await session.commit() | ||||
|  | @ -54,8 +54,16 @@ class Schedule(EmbedBaseModel): | |||
| 
 | ||||
|         personal_slots = set() | ||||
|         for slot in self.slots: | ||||
|             alt_id = slot.alternative_overarching_role_id | ||||
| 
 | ||||
|             # Check if the user has a course selected in their roles | ||||
|             role_found = slot.role_id is not None and slot.role_id in roles | ||||
|             overarching_role_found = slot.overarching_role_id is not None and slot.overarching_role_id in roles | ||||
| 
 | ||||
|             # Some engineering master courses are present in multiple different places, | ||||
|             # so this is necessary | ||||
|             overarching_role_found = (slot.overarching_role_id is not None and slot.overarching_role_id in roles) or ( | ||||
|                 alt_id is not None and alt_id in roles | ||||
|             ) | ||||
|             if role_found or overarching_role_found: | ||||
|                 personal_slots.add(slot) | ||||
| 
 | ||||
|  | @ -131,6 +139,11 @@ class ScheduleSlot: | |||
|         # so this is guaranteed to be unique | ||||
|         self._hash = hash(f"{self.course.course_id} {str(self.start_time)}") | ||||
| 
 | ||||
|     @property | ||||
|     def alternative_overarching_role_id(self) -> Optional[int]: | ||||
|         """Shortcut to getting the alternative overarching role id for this slot""" | ||||
|         return self.course.alternative_overarching_role_id | ||||
| 
 | ||||
|     @property | ||||
|     def overarching_role_id(self) -> Optional[int]: | ||||
|         """Shortcut to getting the overarching role id for this slot""" | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue