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

[WIP] Contact Us API #74

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

emecas
Copy link
Member

@emecas emecas commented Jul 27, 2021

Copy link
Contributor

@cnk cnk left a comment

Choose a reason for hiding this comment

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

Looks reasonable so far.

One question: you have created a ReadOnly API. How is the data getting into the database? Via the Django Admin? or do we need this API changed to accept input from at React form on the site?

verbose_name_plural = "Contacts"

def __str__(self):
return f"Contact {self.id}: {self.email} {self.text} {self.logo_url} {self.name} {self.organization} {self.project_url}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Ummm that's the entire model. Not really best practice. Why are you returning EVERYTHING in str?

@@ -81,6 +81,21 @@ def __str__(self):
return f"Alias {self.id}: {self.tag} {self.alias}"


class Contact(models.Model):
Copy link
Contributor

Choose a reason for hiding this comment

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

You added a model but where is the migration? You can create it using ./manage.py makemigrations. The name generated automatically may or may not say 'added_contact_model'. If you end up with on with a name like "0004_auto_" please rename it to be more descriptive.

I am puzzled by the failing tests in this PR. Hopefully adding a migration file will fix - or at least give us a more understandable error.

@@ -81,6 +81,21 @@ def __str__(self):
return f"Alias {self.id}: {self.tag} {self.alias}"


class Contact(models.Model):
email = models.CharField(max_length=128, unique=True)
text = models.TextField(max_length=4096, null=True, blank=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

For TextField and CharFields, best practice is to ONLY use "blank=True" - that way the row will always have an empty string for missing data in that field. If you allow null, then you would have to check for null and '' to decide if you don't have a value.

@cnk
Copy link
Contributor

cnk commented Jul 30, 2021

@emecas I went to the CTI meeting 7/29. The contact information form is going to take information in but won't be displaying the information anywhere. So rather than using ReadOnlyModelViewSet in your view, you need something that creates records. You can either use a function view like we do in our organization create view:

Or you can make a class based view somewhat like this set of docs:

class CreateListRetrieveViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet):

Also, for your model, you probably want to be pretty loose in the model validations, e.g. remove all uniqueness constraints and most of the required fields - except email. If we do want to enforce filling in some fields, we can have the Serializer insist you give us project or parent org.

@bruceplai
Copy link
Member

@emecas would you happen to have any updates for this PR? Thanks

@emecas
Copy link
Member Author

emecas commented Mar 25, 2022

@emecas would you happen to have any updates for this PR? Thanks

@bruceplai I am not sure if it could be close since civictechindex/CTI-website-frontend#604 is already closed and labeled as Done!! are you aware of any requirement in pending?

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.

Connect 'Contact Us' page using API
3 participants