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

Django Creator Part 2 #33

Merged
merged 33 commits into from
Mar 31, 2025
Merged

Django Creator Part 2 #33

merged 33 commits into from
Mar 31, 2025

Conversation

fudgeu
Copy link

@fudgeu fudgeu commented Mar 25, 2025

Adds many of the remaining features for the creator. Additionally introduces and changes some util classes, as well as a lot of cleanup. Completes much of the remaining tasks in #20 (with some exceptions)

  • Ported endpoints for AI generation and set up the generator_util.py util class. Generation config is loaded in through a .env file that has the same format as the config for Materia PHP
    • Image generation was not ported however since it wasn't a feature used in the first place
    • This PR adds the openai package to requirements.txt for this functionality
  • Ported endpoints for qset history. Works as expected.
  • Removed question importing
  • Implemented widget instance locking through an endpoint and WidgetInstanceUtil methods.
    • Though, there is no way to invite collaborators yet, etc.
  • Cleaned out some old API endpoints, util classes, and related files that are no longer used due to their DRF replacements.
  • Fixed a lot of linting issues
  • js_global_vars now properly supports setting None, str, bool, and numbers as global JS variables appropriately (whereas before every item was just pasted in as a JS string object).
  • Converted the MsgUtil class into MsgBuilder and Msg. Msg now exists as a standalone class that can be used to pass error states internally. Msg objects have .as_json_response() and .as_drf_response() to easily convert them to formats that can be sent to the client. MsgBuilder is a factory class that helps in creating many of the common message types, such as no_login or failure.
  • Created the ContextUtil class and ported all existing context creations to use it. Eases the creation of Context objects, largely by auto-filling many of the required or almost-always-required fields automatically.
  • Adds a UserUtil class, largely to provide a verify_session function that acts similarly to the version present in PHP
  • Patches the widget installer tool to work since it relied on some internal API calls that don't exist anymore due to DRF

Things that are not included in this branch:

  • Anything regarding assets, as that is still a WIP
  • Expand instance ID hash size to a more future-proof variant

@fudgeu fudgeu marked this pull request as ready for review March 26, 2025 19:00
Copy link
Member

@clpetersonucf clpetersonucf left a comment

Choose a reason for hiding this comment

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

Approved, with the provision that there are some changes to things that will still need to be adjusted or deleted in the future: some examples include changes to the JS API util that are on deprecated/NYI endpoints and the Question model.

inst.qset.data,
inst.qset.version
])
apiGetQuestionSet(inst.id).then((qset) => {
Copy link
Member

Choose a reason for hiding this comment

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

Pairing the qset with widget instance data in this context slipped past me - but I think I'm generally OK with having a dedicated request for it here. Keeping these resources separated feels cleaner, even if it means an additional hit on the API. I'm open to being convinced otherwise though.


# Mimics PHP's FILTER_VALIDATE_BOOL
@staticmethod
def validate_bool(raw_bool: str, default: bool = False) -> bool:
Copy link
Member

Choose a reason for hiding this comment

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

I think I'm OK with this method existing, but anywhere that isn't using explicit boolean values should be judiciously updated to only use boolean values. One of the hard-line goals of the django rewrite is to eliminate any future uses of nonsense like foo == "1" for boolean checks.

@@ -579,12 +579,21 @@ class Question(models.Model):
type = models.CharField(max_length=255) # type is a "soft" reserved word in Python
text = models.TextField()
created_at = models.DateTimeField(default=datetime.now)
data = models.TextField(blank=True, null=True)
_data = models.TextField(blank=True, null=True, db_column="data")
Copy link
Member

Choose a reason for hiding this comment

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

These changes may be redundant if we choose to retire the Question model, but I don't see the harm in including them preemptively.

@clpetersonucf clpetersonucf merged commit 81db14a into django-working Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants