Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move wants_thursday_event to custom field #3807

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

falbru
Copy link
Contributor

@falbru falbru commented Mar 26, 2025

Description

Frontend: webkom/lego-webapp#5498

Testing

  • The code quality is at a minimum required level of quality, readability, and performance.
  • I have thoroughly tested my changes.

The migration works. Also creation of new company intersts work.

Resolves ... (either GitHub issue or Linear task)

Copy link

linear bot commented Mar 26, 2025

@coderabbitai coderabbitai bot added the review-needed Pull requests that need review label Mar 26, 2025
@falbru falbru requested a review from a team March 26, 2025 18:13
Copy link

coderabbitai bot commented Mar 26, 2025

📝 Walkthrough

Walkthrough

This pull request refactors how the Thursday event is handled in the companies application. The changes remove the translation constant for the Thursday event and introduce a dedicated Boolean field, wants_thursday_event, into the CompanyInterest model. A new migration file handles data updates by transferring relevant data from the old other_offers field. In addition, the serializer and CSV export functionality have been updated to include this new field.

Changes

File(s) Change Summary
lego/apps/companies/constants.py Removed THURSDAY_EVENT: "Ønsker arrangement torsdag" from the TRANSLATED_OTHER_OFFERS dictionary.
lego/apps/companies/migrations/0034_companyinterest_wants_thursday_event.py,
lego/apps/companies/models.py,
lego/apps/companies/serializers.py
Added a new Boolean field wants_thursday_event to the CompanyInterest model, introduced a migration to add the field and update existing records by removing "thursday_event" from other_offers, and updated the serializer to include the new field.
lego/apps/companies/views.py Modified the CSV export in CompanyInterestViewSet to include the wants_thursday_event value.

Sequence Diagram(s)

sequenceDiagram
    participant MIG as Migration Script
    participant CI as CompanyInterest Record
    participant DB as Database

    MIG->>CI: Check if "thursday_event" exists in other_offers
    CI-->>MIG: Return matching records
    MIG->>CI: Remove "thursday_event" from other_offers
    MIG->>CI: Set wants_thursday_event = True
    MIG->>DB: Persist changes
Loading
sequenceDiagram
    participant U as User
    participant V as CompanyInterestViewSet
    participant CSV as CSV Writer

    U->>V: Request CSV export
    V->>V: Retrieve CompanyInterest data (includes wants_thursday_event)
    V->>CSV: Write CSV row with wants_thursday_event field
    CSV-->>U: Return CSV output
Loading

Suggested labels

review-needed

Suggested reviewers

  • jonasdeluna
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 797a2d6 and 1da2b75.

📒 Files selected for processing (5)
  • lego/apps/companies/constants.py (0 hunks)
  • lego/apps/companies/migrations/0034_companyinterest_wants_thursday_event.py (1 hunks)
  • lego/apps/companies/models.py (1 hunks)
  • lego/apps/companies/serializers.py (1 hunks)
  • lego/apps/companies/views.py (2 hunks)
💤 Files with no reviewable changes (1)
  • lego/apps/companies/constants.py
🧰 Additional context used
🧬 Code Definitions (1)
lego/apps/companies/migrations/0034_companyinterest_wants_thursday_event.py (1)
lego/apps/companies/models.py (1)
  • CompanyInterest (122-223)
🔇 Additional comments (5)
lego/apps/companies/models.py (1)

161-161: Field addition looks good

The new Boolean field wants_thursday_event has been added with appropriate default value and blank flag, matching the style of the existing office_in_trondheim field.

lego/apps/companies/serializers.py (1)

302-302: Serializer field added correctly

The new field has been properly added to the serializer fields list, making it accessible through the API. This is an essential step when adding a new model field.

lego/apps/companies/views.py (1)

281-285: Variable creation follows existing pattern

The handling of the wants_thursday_event field in the CSV export follows the same pattern as the other boolean fields like office_in_trondheim, which is good for consistency.

lego/apps/companies/migrations/0034_companyinterest_wants_thursday_event.py (2)

6-15: Well-structured data migration

The migration function properly identifies and updates existing records by:

  1. Finding all company interests that had "thursday_event" in the other_offers field
  2. Removing "thursday_event" from that array field
  3. Setting the new Boolean field to True for those records

This is a clean approach that preserves the data while moving it to a dedicated field.


23-30: Migration operations look good

The migration correctly:

  1. Adds the new field to the model
  2. Runs the data migration function to move existing data
  3. Has proper dependency on the previous migration

This ensures a smooth transition from the old data structure to the new one.

@@ -292,6 +297,7 @@ def csv(self, *args, **kwargs):
company_type,
company_course_themes,
office_in_trondheim,
wants_thursday_event,
Copy link

@coderabbitai coderabbitai bot Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Missing CSV header for the new field

While the data row includes the new wants_thursday_event field, there's no corresponding header in the CSV. This will cause misalignment between headers and data columns.

Add the header for the new field by updating the header row in the writer.writerow() call around line 186-210:

writer.writerow(
    [
        "Navn på bedrift",
        "Kontaktperson",
        "E-post",
        "Telefonnummer",
        "Bedriftsinformasjon",
        "Semester",
        "Arrangementer",
        "Annet",
        "Samarbeid",
        "Bedriftstype",
        "Relevante temaer",
        "Kontorer i Trondheim for besøk",
+       "Ønsker torsdagsarrangement",
        "Klassetrinn",
        "Antall deltagere",
        "Faglig arrangement kommentar",
        "Frokostforedrag kommentar",
        "Alternativt arrangement kommentar",
        "Start-up kommentar",
        "Bedrift-til-bedrift kommentar",
        "Lunsjpresentasjon kommentar",
        "Bedriftspresentasjon kommentar",
        "BedEx kommentarg",
    ]
)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
wants_thursday_event,
writer.writerow(
[
"Navn på bedrift",
"Kontaktperson",
"E-post",
"Telefonnummer",
"Bedriftsinformasjon",
"Semester",
"Arrangementer",
"Annet",
"Samarbeid",
"Bedriftstype",
"Relevante temaer",
"Kontorer i Trondheim for besøk",
"Ønsker torsdagsarrangement",
"Klassetrinn",
"Antall deltagere",
"Faglig arrangement kommentar",
"Frokostforedrag kommentar",
"Alternativt arrangement kommentar",
"Start-up kommentar",
"Bedrift-til-bedrift kommentar",
"Lunsjpresentasjon kommentar",
"Bedriftspresentasjon kommentar",
"BedEx kommentarg",
]
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahah nice catch!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ivarnakken Thanks! Happy to help. Let me know if you need any more assistance with this PR.

@@ -292,6 +297,7 @@ def csv(self, *args, **kwargs):
company_type,
company_course_themes,
office_in_trondheim,
wants_thursday_event,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahah nice catch!

@ivarnakken ivarnakken added the changes-requested Pull requests with requested changes label Mar 26, 2025
Copy link

codecov bot commented Mar 26, 2025

Codecov Report

Attention: Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.

Project coverage is 89.98%. Comparing base (cc1c32e) to head (f8ad35d).

Files with missing lines Patch % Lines
...tions/0034_companyinterest_wants_thursday_event.py 72.72% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3807      +/-   ##
==========================================
- Coverage   89.98%   89.98%   -0.01%     
==========================================
  Files         747      748       +1     
  Lines       24111    24124      +13     
==========================================
+ Hits        21697    21707      +10     
- Misses       2414     2417       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@itsisak itsisak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@falbru falbru force-pushed the falkbruskeland/aba-1349-move-thursday-button-on-interest-form branch 2 times, most recently from 7047a8f to f8ad35d Compare March 27, 2025 12:15
@falbru falbru force-pushed the falkbruskeland/aba-1349-move-thursday-button-on-interest-form branch from 93afa3c to 1115303 Compare March 29, 2025 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes-requested Pull requests with requested changes review-needed Pull requests that need review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants