Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Dashboard models #9

Merged
merged 2 commits into from
Jul 8, 2014
Merged

Conversation

dweep123
Copy link

This PR depends on the django-cms PR

@econchick
Copy link
Contributor

Again, address the first PR. Either close and reopen, or update.

Also, when submitting PRs, please only do "pieces". You've put in settings, templates, urls, and media. But this PR is referring to dashboard models.

from dashboard.models import Resource
from dashboard.models import Tag
from dashboard.models import Resource_Type
from dashboard.models import CommunityPages
Copy link
Contributor

Choose a reason for hiding this comment

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

Lines 3-8 are a little redundant. I would do:

from dashboard.models import (
    SysterUser, Community, News, Resource, Tag, Resource_Type,
    CommunityPages)

@econchick
Copy link
Contributor

In addition to the comments I've left, I'd suggest to not put both blank=True and null=True for any model that inherits from CharField or TextField, like URLField, EmailField, etc. This is because this allows the DB to have two values for "no data", both an empty string, and NULL. You can read more here (the first three answers are good).

BTW the default behavior is blank=False and null=False. So other than being very explicit, there's no reason to include them when they're false.

@econchick
Copy link
Contributor

Ah nearly forgot - could you also put in tests? See @ana-balica 's pr #7 for example on how to setup tests for models.

@dweep123
Copy link
Author

Can a tag be of more than 30 characters? Should I change it for tags also ?

@econchick
Copy link
Contributor

That makes sense, sure.

return "{0} of {1} Community".format(self.title, self.community.name)


class CommunityPages(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.

Make it CommunityPage (singular form) to be consistent with other models naming convention.

@ana-balica
Copy link
Contributor

While working on permissions I have figured out we need a model to represent also community requests/proposals.
@rosariorobinson can you send the ABI_Community_Proposal_Form.pdf referenced in the Appendix of the requirements document? Thank you :)

@rosariorobinson
Copy link
Contributor

Document sent to entire team.



class SysterUser(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.

It's not a PEP8 error, but why did you add a blank line before class definition?

@econchick
Copy link
Contributor

@dweep123 - a few things in addition to my comments:

  1. I don't see tests for the Tag and Resource_Type model
  2. You have inconsistent indentation; mixing tabs and spaces too.
  3. Do get in the habit of checking our Travis when submitting a PR, too; you'll see that this build failed with a lot of flake8 errors.

return self.name


class Resource_Type(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.

This should be ResourceType - not snake cased.

@dweep123
Copy link
Author

@econchick , PR has been updated according to the comments above.
Still there are some warnings for line too long , but If I break those lines then that might be a odd way of breaking lines .
Please review these changes :)

@@ -5,3 +5,4 @@ flake8==2.1.0
psycopg2==2.5.3
django-cms==3.0
djangocms-text-ckeditor==2.1.6
django-countries==2.1.2
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to keep the requirements in alphabetical order, same as pip freeze does.
Can you update that?

@dweep123
Copy link
Author

dweep123 commented Jul 1, 2014

@ana-balica updated

@@ -1,7 +1,8 @@
Django==1.6.5
Sphinx==1.2.2
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you try running pip freeze? It lists first the packages with uppercase and then those with lowercase.
So usually it outputs something like this:

Django==1.6.5
Sphinx==1.2.2
django-cms==3.0
[and so on]

Copy link
Author

Choose a reason for hiding this comment

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

Now updated according to pip freeze :)

self.assertEqual(systeruser.blog_url, 'http://blog_url.com')
self.assertEqual(systeruser.homepage_url, 'http://homepage_url.com')
second_user = User.objects.create(username='user2', password='user2')
second_systeruser = SysterUser.objects.create(user=second_user)
Copy link
Contributor

Choose a reason for hiding this comment

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

second_systeruser is never actually used.

Copy link
Author

Choose a reason for hiding this comment

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

second_systeruser is corresponding syster user for second_user , It was created to check if the user entry is deleted then its corresponding syster user entry should also be deleted.

@econchick
Copy link
Contributor

Hi @dweep123 - can you see https://travis-ci.org/systers/portal/ ? This PR fails the build, seen here. Please address all the flake errors.

Otherwise, after the flake errors, this looks good. Ping me when this is updated and I will merge. (a simple @ will be fine)

@dweep123
Copy link
Author

dweep123 commented Jul 2, 2014

@econchick , updated
There is still one flake8 error , that "second_systeruser is never used" but I created that to check when a user is deleted its corresponding systeruser is also deleted ,
Should I remove that test ?

@econchick
Copy link
Contributor

@dweep123 add # nopep8 comment at the end of the line to keep the test and have flake8 ignore it. Be sure to run flake8 before updating the PR to make sure it works. I'm on my mobile so I'm sorry I can't link you the docs, but if you google "flake8 ignore" it is the first entry.

1 similar comment
@econchick
Copy link
Contributor

@dweep123 add # nopep8 comment at the end of the line to keep the test and have flake8 ignore it. Be sure to run flake8 before updating the PR to make sure it works. I'm on my mobile so I'm sorry I can't link you the docs, but if you google "flake8 ignore" it is the first entry.

@dweep123
Copy link
Author

dweep123 commented Jul 2, 2014

@econchick , updated. No flake8 errors now :)

@econchick
Copy link
Contributor

Thanks @dweep123. @ana-balica can you check Travis's failure? I was able to look it up and only see a secret key error - do you know what's going on?

Once the Travis build passes I'll merge.

@ana-balica
Copy link
Contributor

@econchick I know what is the problem. Since we are using secure env, on PR from forked repos, travis is not including this data, hence the SECRET_KEY is missing and the build fails. More here.

I will check if the workaround provided by travis works for us.

@dweep123 dweep123 mentioned this pull request Jul 3, 2014
@ana-balica
Copy link
Contributor

Are we going to use slugs or ids for representing models in views?

related_name='member_of_community')
community_admin = models.ForeignKey(SysterUser, related_name='community')
parent_community = models.ForeignKey('self', blank=True, null=True)
website = models.URLField(max_length=30, 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.

max_length is rather short for URLs.
Same on lines 40, 41, 42.

Changed CommunityPages to CommunityPage

Added tests for models

deleted unwanted files

Removed credentials
Added tests for models

Run flake8
Added tests for models

Added tests for models

Added tests for models

Changed Line breaks
Added tests for models

Added Tests for models
Added Tests for models

requirements in alphabetical order
Added Tests for models

requirements in alphabetical order
Added Tests for models

Added tests for models
Added tests for models
Added tests for models

Ignore never used flake8 errors

Added slug field

Added tests for models
@dweep123
Copy link
Author

dweep123 commented Jul 7, 2014

@ana-balica @econchick updated.
Instead of using django cms page model can we use a model with placeholder fields which can be edited through django-cms front end editing , more here
If we use it Community Page model would be something like

class CommunityPage(models.Model):
    title = models.CharField(max_length=255)
    editable_content = PlaceholderField('editable_content')
    community = models.ForeignKey(Community)
    slug = models.SlugField(max_length=150, unique=True)

This is more simple and we can define our own urls for these pages if we use the above model and also cms page model also provides a lot of other options which I guess we don't want.
The problem with django-cms is that it allows front end editing only for staff users , If a user has permissions to edit a model but is not a staff user then won't be able to edit the model through front end.
If we have to allow that then either we have to set permissions for specific objects or change some code in django-cms where it checks whether the user is staff or not ,here and here

@econchick
Copy link
Contributor

@dweep123 @ana-balica I think I understand placeholder fields, and if I understand correctly, switching to this would make sense.

It sounds like you can extend the auth backend (here) just fine, although UserProfiles are deprecated in Django IIRC.

@ana-balica what do you think? Also, you think you can help/work with Chitra re the auth permissions?

Something to think about: having a WYSIWYG or a Markdown editor for the user-facing editable content. Folks will want to format the content, I'm assuming, and not want to write in pure HTML (I don't even know how Django/Django-CMS would handle the text)

@ana-balica
Copy link
Contributor

@econchick sure. But first it would be nice to review and merge what we have at the moment, since it becomes more and more complicated to work on new tasks which are dependent on pending PRs :)

I suppose we want to achieve row level permissions. This is not complicated, we can have a decorator obj_permission_required or a function to check if user has object permission. I didn't look much into Django-CMS, but my concern how are we going to use it on views already defined by Django-CMS?

There are Django-CMS permissions, but I need to see how flexible are those and if they meet our needs.

Recently I have discovered that tinymce, at last, has a decent theme, so we can use django-tinymce to provide a WYSIWYG editor.

@econchick
Copy link
Contributor

So this doesn't break the build (besides the secret key issue). I'm going to merge it so you both can continue on.

econchick added a commit that referenced this pull request Jul 8, 2014
@econchick econchick merged commit 5fc3552 into anitab-org:master Jul 8, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants