I guys I am very new to Django and app dev and I am having trouble to structure my app.
I am creating an app to send team questionaire.So wokflow is the following:
1) I create a team_project (Team_name)
2) Send Invitations to team members using Emails
3) Based on that invitation Team_member signIn (creating a new user) and are directly assigned to that team created.
I have no idea how to handle that and especially part 3
If you could give me a direction how to do it I will really appreciate
Thx you very much
What you want is a common requirement, so perhaps there is already a library or solution for it.
to write the code from scratch, which is not recommended,
You can define a custom url , like example.com/join_team/some_random_looking_unique_string/
create a model which keeps a random string, email , and maybe some kind of expiration policy. Read the unique string in your view, and retrieve the record associated with it. send a form to get more details like password and etc and save the user in database.
I also found this repo that I think does what you want:
https://github.com/bee-keeper/django-invitations
explain more in your question, and you can get more detailed answers!
Related
Hello Django REST API Experts,
We are building University Course portals where app offers various user types like Professor, Students and Admins using DJANGO/REACT. We are using REST API to connect between backend and frontend.
So, far we are able to perform some basic operation and it really works great. However now I need help from this group to do following:
When students enrolled in course it generates an acknowledge document stating course description, and its prerequisite which needs to get signed by students to ensure student acknowledge they fulfill these requirements.
In order to do this we have following:
Model for each course which contains the Content, Description and Prerequisite for each course.
StudentCourseAck Model which has FK to Course, Signed Boolean field, Binary field to store signed doc.
User flow:
Student logins to portal,
Select the Course, which generate StudentCourseAck entry.
Let Student review document and signed the document (on client side using sign pad).
The Signature gets stored in PDF (as binary field).
So far so good…
Now we want to enhance the featureset which allows admin to email student the link of studentcouseack document incase its not signed before course start. Also this link should only be valid for 48 hours or else it will expire.
So we need some help to enhance these featuresets as follow:
Current the API is exposed to frontend like: mysite.com/courseack/studentid/documentid
However we want to encrypt this so the link look like this: mysite.com/uniqueid
Where uniquid is mapped to /studentid/documented
So I have following design question:
Question 1: Should we enhance StudentCourseAck which store the UUID for each document?
Question 2: If I store UUID for each document, how do I make it expire once its generated?
Question 3: When Student is finished signing, I need to update the document into database to ensure that right document is saved to right student profile, so how can I ensure this security requirement.
I would really appreciate some expert opinion or some guidance so we can proceed this feature implementation. Any other alternative which is simpler and easier to maintain.
Once again thank you for your time and consideration.
Thank You.
Any other alternative which is simpler and easier to maintain.
Keeping the above phrase in mind I propose this solution.
Firstly I will not consider this as a DRF problem but as a general problem and proceed to answer your Questions.
The simple solution lies in 4 steps
Create a UUID field inside StudentCourseACK so that you can map this uuid with your url mysite.com/uniqueid, catch the document id inside the StudentCourseACK record as a foreign key and also create a created_at inside the model (this will be required for expiry timer)
Make a view inside your views.py that takes this StudentCourseACK UUID as a url parameter where you will have to fetch courseack, studentid and documentid from this StudentCourseACK mapping table and redirects it to mysite.com/courseack/studentid/documentid. When you link this view with your url pattern make sure the listing is at the very bottom.
To make an expiry timer you can check the created_at date in your StudentCourseAck record for 48hours limit before redirecting inside Step 2
Finally when the student is redirected to the mysite.com/courseack/studentid/documentid endpoint you will have to follow a simple process of getting the StudentCourseAck data via .filter(studentid="some value", documentid="somevalue") and make changes to this data accordingly.
Another thing that I realise is that you can completely ditch the long mysite.com/courseack/studentid/documentid url and correspond it's logic inside the new view, but I assume that you want to keep it that way.
I would like to give staff the ability to manage the fields from, subject, and body when sending emails without having to edit the html file. Ideally they would be able to do this via the admin site. My thought process is:
Create email table with the requested fields
Add send_email on admin.py classes when they perform a certain action. When they do, I can get the values for sending emails by getting object from email table based on primary key.
I haven't come across any documentation to set this up and am concerned it's considered bad to do.
I'm almost certain to be missing something crucial as to why this is a terrible idea... can anyone comment on cases when this would blow up, or that it's odd but shouldn't be an issue? Most of the emails staff edit will be of static text.
Any suggestions/comments/criticism is very much appreciated.
I personally use Django DB Templates for such purpose like email editing in Admin Area.
It's simple and you can save your existing templates to DB templates table.
I had no idea how to structure an accurate title for this question, but I did my best so please bear with me.
I am working on a app for my hockey team that consists of a django app and an mobile app that communicates with the django app using JSON (django-rest-framework). However, one problem I am struggeling with figuring out how to solve is as follows:
You create a user (using Token Authentication), and then you create a player and/or a manager.
However, what I am struggling with is what to do when an existing user logs in. How do I check whether or not there is a player or manager associated with that user? When I log in, all I get in return from the rest framework is that user's authentication token, so from a programming perspective, I have no clue what user it actually is since I dont have the user's Id. Even if I did, how can I look up players by anything other than their Id? Currently the only idea I have is to grab all players and loop through them to find one with the same email address as the user currently signed in has.
Hope this made some degree of sense!
Thanks
This isn't really a question about JSON.
Surely the token is associated with a user ID? I don't use django-rest-framework, but the documentation for TokenAuthentication is pretty clear that once the user logs in with their token, you'll get a normal auth.User instance in request.user just like you would with a standard web-based login.
Your second question is probably made irrelevant by that, but even so, you can always query by an email address, without needing to loop through:
Manager.objects.get(email=my_email_address)
Again this is standard Django querying - if you're not familiar with that syntax, you should do the Django tutorial.
Of course, since you have a User already, you can do a more efficient foreign key lookup:
Manager.objects.get(user=request.user)
or even
request.user.manager
(assuming you have a one-to-one relationship from User to Manager - it would have been helpful to see your models).
I've recently started using Pushover.net, I've done some searching and can't find any examples of it being integrated with a django project.
Since i can't find any examples I've decided it would be fun to try myself. What I'm interested in is how you would suggest I do it. I want the actual pushover part as decoupled a possible, hence doing it asas an app.
What I'm not entirely sure on how to approach is the user authorization. The idea being a user enters their pushover user key and its saved in a user profile model using django's AUTH_PROFILE_MODULE with some functions such as has_pushover but obviously I'd like some security so the user keys aren't stored in plaintext. What do people suggest for this?
Is there some inbuilt django security I can use?
In the past when I've needed to encrypt Django fields I used the encrypted fields available in django-fields. You could use one of these on your UserProfile model and define a has_pushover() method on the model which basically returns whether the pushover token field is None or not.
I'm guessing because you're talking about storing each user's Pushover token you are wanting to build an app for pushing arbitrary notifications to your website's users? This is in contrast to having the website just push notifications to yourself for site events.
Either my google searching has completely left me or there's hardly any documentation/tutorials for django-socialregistration. Too bad, because it seems like a nice enough app. Through some trial-and-error, I have managed to get it mostly running on my site.
My question, using django-socialregistration how do I request permission for the facebook user's full name, current city and date of birth and store it in my UserProfile table (which is my AUTH_PROFILE_MODULE for django-profiles) in Django upon registration? Also, how do I post to the user's wall from Django once the connection is made?
Currently, when I click the "Connect with Facebook" button the facebook connection is made, a new Django user is created and the user is logged in with that Django account. However, no UserProfile is created and no facebook profile data is saved.
Any facebook connect gurus out there want to help the Django pony fly to Facebookland?
Setup:
- Django 1.2.1
- Python 2.5.2
- django-socialregistration 0.4.2
- django-registration 0.7
- django-profiles 0.2
"Kind sir, can you please help me find the magical Facebookland?"
In facebook_js.html you need to adjust the following line, by uncommenting items that you need to get from FB:
FB.login(handleResponse/*,{perms:'publish_stream,sms,offline_access,email,read_stream,status_update,etc'}*/);
Then, in FacebookMiddleware you can extract that data from fb_user, like this:
facebook.GraphAPI(fb_user['access_token']).get_object('me')
FWIW, I just found this moderately helpful nugget from the app author buried in the "Issues" section on github:
question from "tolano":
I have a profile model associated with the users, and everytime the user is created the profile should be created also. Should we create a new custom setup view for this purpose?
I'm finding several problems because the documentation is poor. Thank you very much.
answer from "flashingpumpkin":
Yes. Ideally you'll overwrite the setup view with your own. An easier method to adjust what is done on user creation is to pass a custom form into the setup view. You'll do that by overriding the standard url.
Here's another relevant nugget (source: http://github.com/flashingpumpkin/django-socialregistration/issues/closed#issue/7) Enough of these and this page will become the de facto django-socialregistration documentation ;)
question from "girasquid":
Maybe I'm just missing something, but I'm stuck here - is there a way to 'connect' accounts on other sites to an already-existing user?
For example, I've already signed up on Really Awesome Website, so I don't need to sign up again - but I'd like to connect my Facebook and Twitter accounts so that I can sign in with those as well.
Is there a way to do this already? If there isn't...how would I do it?
answer from "flashingpumpkin":
Yes there is. Just use the same template tags for Facebook Connect as you would for registration. Depending on if the user is already logged in or not it will create just the FacebookProfile object and link it to the existing user - or create both, the User object and the FacebookProfile object.
Have a look here:
http://github.com/flashingpumpkin/django-socialregistration/blob/master/socialregistration/templates/socialregistration/facebook_button.html
and
http://github.com/flashingpumpkin/django-socialregistration/blob/master/socialregistration/templatetags/facebook_tags.py