Publish and "Save Drafts" feature in Django - reactjs

I am working on a Django Rest Framework B2B application with a React Frontend. The data is fed from a csv and then Analytics dashboards are rendered in React. Each Account ("User") is a company - and within a company, the app is used by the entire marketing team (say). Each company account has data unique to that co. and dashboard preferences unique to that company. An administrator is a human user who is some Manager / employee of a company (let's say, for example, Boeing, Nike etc) who has edit / administrator rights on behalf of the company. That "admin" makes some changes to the dashboard preferences and wants to "Publish" the changes so that rest of the employees (the rest of the Marketing team) of the company Account can view the updated dashboard. But maybe not yet, hence a "Save Drafts" feature.
I'm not sure how to get these two features in the most industry-standard way in Django (DRF) - When I hit "Publish", the entire marketing team should be able to see the changes. (It's a B2B app). But when I save drafts, I should be able to view the changes (as admin) but not the rest of the marketing team. I'd be grateful for any help. Thank you!

You can use a choices field to manage the status of a a model (Dashboard in your case)
Example code follow
models.py
class Dasboard(models.Model):
STATUS_CHOICES = (('draft', 'Save Draft'), ('published', 'Published'))
status = models.Charfield(max_length=20, choices=STATUS_CHOICES)
# Others models fields
views.py
def dashboard(request):
objects = None
if request.user.is_admin:
# The admin users can see draft and saved (all Dashboard objects)
objects = Dashboard.objects.all()
else:
# Others users are seeing only published
objects = Dashboard.objects.filter(status='published')
return render(request, 'app_name/dashboard.html', {'objects': objects})
NB : Here i used only Django filter features to retrives some data according to the type of users.
But you can also use Django permissions too for more advanced handling.

Related

Wagtail admin page for different clients

We are in the process of making a UberEat like app and will be using Django for the backend. I discovered wagtail not so long ago and was wondering if it would be possible to use it for our vendors, with each vendor having the possibility to log into Wagtail admin and having access to his/her own products, category, prices, etc. Rephrased, is there a possibility to have different admins in Wagtail that would have access to their own model instances ?
Thanks to you all
With Wagtail’s page permissions you could solve that via a "parent" page in combination with a custom "group" for each vendor. A clumsy workaround to be honest, it would require 3 steps, which could be automated. But this way you could use the full-featured Wagtail CMS in a way, in which each vendor could only see their "own" pages.
You could manage images and documents in the same way by assigning collections to vendors as well. But let’s start with the pages here.
The slug would look something like ubereatlike.app/vendorxyz/... with vendorxyz/ representing this "parent" page.
Groups can be added via the SETTINGS in the sidebar. Groups are a native part of the Django framework, see documentation. To add a new vendor, you would have to do three steps. (1) Create a parent page for this vendor. (2) Create a group for this vendor via SETTINGS --> GROUPS. Here you should check "Can access admin" and create a "native" new page permisson for the vendor’s page with all necessary permissions, like "Add", "Edit" and "Publish", for example. (3) Lastly you would have to add a new User for the vendor and choose its group as role.
To automate this I would create a custom user model, see documentation. With a post_signal for this custom user model, I would create both the parent page and the group and its permissions. This way you would add the User only and the page and the group would be generated programmatically.
# startapp vendors with models.py
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import Group, Permission
from django.dispatch import receiver
from wagtail.models import Page
from home.models import HomePage
class VendorPage(Page):
parent_page_types = ['home.HomePage']
...
class Vendor(AbstractUser):
company_name = models.CharField(max_length=255)
# ...other fields
#receiver(models.signals.post_save, sender=Vendor)
def vendor_created(sender, instance, created, **kwargs):
if created:
# create vendor page as child of home page
home_page = HomePage.objects.first()
vendor_page = VendorPage(title=instance.company_name)
home_page.add_child(instance=vendor_page)
vendor_page.save_revision().publish() # recommended
# create group with permissions
vendor_group = Group.objects.create(...)
permission = Permisson.objects.get(...) # please look into Wagtail’s page permissons, this is just a rough draft
vendor_group.permissions.add(permission)

Normal user (not admin) registration and publishing in Wagtail

I understand Wagtail is a CMS. Per my test so far, only the admin has permission to publish an article/content. I checked out "puput" and a few others as listed here. I wonder is there a way to allow normal user registration, login, publishing? Something similar to Medium, where the normal user, or say the community, can contribute to the content generation.
I thought there might be a toggle or switch to enable this. But I didn't find it. I'm looking for a way that is either a package or a plugin or similar. Not coding from scratch. Ideally within Wagtail CMS, but other frameworks based on Django should also be fine.
Thanks.
Wagtail provides two user groups:
Editors: user within this group can create page and submit it to moderation
Moderators: user within this group can publish pages that have been submitted to moderation.
To update groups for a given user, go the the django admin interface with admin credentails, usually the url is your-domain/admin
Then go to Users under Authentication and Authorization category
Then get into the user you want to allow posting pages,
Scroll down until Permissions category and moove groups Editors and Moderators from Available groups to Chosen groups as follow:
Then save new settings.

How to activate company accounts through email after creating the company. RAILS

so this is my first question here in stackoverflow, i always find the answer by looking here... so.
I have this issue, I have a Model named Company, which can have many users, which would be the "best approach" to create and activate a user account within this newly created Company.
Here is the process i am following:
Platform Admin creates a company, the company serves as a grouping account in which i will have a number of users, but i need to send an Email after company creation to the Company admin in order to have him create his account so that he can manage the other company users, this email needs to have a hash so that it has some kind of reference to the company (avoiding the company selection in the form).
Im using Rails 4.2.6 and Angular 1.5
so im stuck after the company creation form.
In an email send the angular route url which got the company hash that just created. When admin user clicks on that link your angular route gets called and then before it render the view , i mean use resolve in angularjs route, get the list of all the user and company that just got created where admin user can select user that he or she want to activate.

How to make payment to store business account byu paypal?

I am developing an mobile app where I present products (items) from different stores just like ebay.com. User can select product, can add to cart and then finally can make payment via paypal.
I have created an Paypal business account on sandbox. Currently all payment made by users are coming to this business account I mentioned in my code. But my requirement is different. I want that payment should go to store's (product owner's) account.
So I made changes so that whenever i make call to paypal I chnaged business account email to store owner email address and payment done successfully. :) Payment posted to store owner business.
I made changes only in paypal.recipient email address but still paypal object is created by my paypal application ID. This is what I am worried about. Does it will work on production mode? I really doubt that.
Please help me guys!!!
What API or service are you using to do this? Are you just using Website Payments Standard, Exprses Checkout, or one of the other API? You mentiioned application id, are you using Adaptive Payments? You could use Adative Payments to do what you are wanting to, if you are not already doing this. This would allow you to process payments and split it between different accounts. In your business model, it would allow you to split the payments between different store owners if the buyers checkout contained items from different merchants/stores.

Not logged-in user in a customer portal site

How do I get the list of users who have not logged into a customer portal site at all?
The User object has a field called LastLoginDate, you could report on this for users where IsPortalEnabled is true which indicates that they are a customer portal user if you're doing the reporting through code.
Of course, Salesforce's reporting engine can also be used to generate a report, you'll want something similar to this:
Unless you need the list in code for some reason (for instance, for integration with another system) then you should use the reporting engine and then you can schedule it for email delivery etc.

Resources