Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
items = []
for obj in self.object_list:
items.append(dict(title=obj.title,
body=obj.body,
tags=obj.tags))
return items
class Author(SmartListView):
fields = ('title', 'tags', 'created_on', 'created_by')
default_order = ('created_by__username', 'order')
class Update(SmartUpdateView):
success_message = "Your blog post has been updated."
class Create(SmartCreateView):
submit_button_name = "Create New Post"
class Exclude(SmartUpdateView):
exclude = ('tags',)
class Exclude2(SmartUpdateView):
form_class = ExcludeForm
exclude = ('tags',)
class Readonly(SmartUpdateView):
readonly = ('tags',)
class Readonly2(SmartUpdateView):
form_class = ExcludeForm
readonly = ('tags',)
model = Category
fields = ('name',)
# just tests that our reverse and permissions are based on the view.py app, not
# the model app, the template should also be /blog/user_list.html for the List view
class UserCRUDL(SmartCRUDL):
model = User
permissions = False
actions = ('list',)
class CategoryCRUDL(SmartCRUDL):
model = Category
class Create(SmartCreateView):
form_class = CategoryForm
class PostCRUDL(SmartCRUDL):
model = Post
actions = (
'create', 'read', 'update', 'delete', 'list', 'author', 'exclude', 'exclude2', 'readonly', 'readonly2',
'messages', 'csv_import', 'by_uuid', 'refresh', 'no_refresh', 'list_no_pagination'
)
class Read(SmartReadView):
permission = None
class List(SmartListView):
fields = ('title', 'tags', 'created_on', 'created_by')
search_fields = ('title__icontains', 'body__icontains')
return {"label": label, "text": text, "language": language}
class FaqCRUDL(SmartCRUDL):
model = FAQ
actions = ("list", "create", "read", "update", "delete", "search", "import", "languages")
class List(OrgPermsMixin, SmartListView):
fields = ("question", "answer", "language", "parent")
default_order = ("-parent", "question")
def derive_queryset(self, **kwargs):
return FAQ.get_all(self.request.org)
class Create(OrgPermsMixin, SmartCreateView):
form_class = FaqForm
def get_form_kwargs(self):
kwargs = super(FaqCRUDL.Create, self).get_form_kwargs()
# Get the data for post requests that didn't come through a form
if self.request.method == "POST" and not self.request.POST and hasattr(self.request, "json"):
kwargs["data"] = self.request.json
kwargs["org"] = self.request.org
return kwargs
def save(self, obj):
data = self.form.cleaned_data
org = self.request.org
question = data["question"]
answer = data["answer"]
language = data["language"]
# trigger task
result = faq_csv_import.delay(org.id, self.id)
self.task_id = result.task_id
self.save(update_fields=("task_id",))
ImportTask.start = override_start
class LabelCRUDL(SmartCRUDL):
actions = ("create", "update", "read", "delete", "list", "watch", "unwatch")
model = Label
class Create(RuleFormMixin, OrgPermsMixin, SmartCreateView):
form_class = LabelForm
def get_form_kwargs(self):
kwargs = super(LabelCRUDL.Create, self).get_form_kwargs()
kwargs["org"] = self.request.org
kwargs["is_create"] = True
return kwargs
def derive_initial(self):
# label created manually in casepro aren't synced by default
initial = super(LabelCRUDL.Create, self).derive_initial()
initial["is_synced"] = False
return initial
def save(self, obj):
data = self.form.cleaned_data
def get_queryset(self, **kwargs):
queryset = super(UserCRUDL.List, self).get_queryset(**kwargs)
group_id = self.request.POST.get('group_id', self.request.GET.get('group_id', 0))
group_id = int(group_id)
# filter by the group
if group_id:
queryset = queryset.filter(groups=group_id)
# ignore superusers and staff users
return queryset.exclude(is_staff=True).exclude(is_superuser=True).exclude(password=None)
def get_name(self, obj):
return obj.get_full_name()
class Create(SmartCreateView):
form_class = UserForm
fields = ('username', 'new_password', 'first_name', 'last_name', 'email', 'groups')
success_message = _("New user created successfully.")
field_config = {
'groups': dict(label=_("Groups"),
help=_("Users will only get those permissions that are allowed for their group.")),
'new_password': dict(label=_("Password"), help=_("Set the user's initial password here.")),
}
def post_save(self, obj):
"""
Make sure our groups are up to date
"""
if 'groups' in self.form.cleaned_data:
for group in self.form.cleaned_data['groups']:
# set new password if provided
password = data["new_password"]
if password:
obj.set_password(password)
obj.save()
update_session_auth_hash(self.request, obj)
return obj
class UserCRUDL(SmartCRUDL):
model = User
actions = ("create", "create_in", "update", "read", "self", "delete", "list")
class Create(OrgPermsMixin, OrgFormMixin, SmartCreateView):
"""
Form used by org admins to create any kind of user, and used by superusers to create unattached users
"""
permission = "profiles.profile_user_create"
success_url = "@profiles.user_list"
def get_form_class(self):
return OrgUserForm if self.request.org else UserForm
def derive_fields(self):
if self.request.org:
return (
"name",
"role",
"partner",
role = self.form.cleaned_data["role"]
partner = self.form.cleaned_data["partner"]
if partner:
self.object = Profile.create_partner_user(
org, partner, role, name, email, password, change_password, must_use_faq
)
else:
self.object = Profile.create_org_user(org, name, email, password, change_password, must_use_faq)
else:
self.object = Profile.create_user(name, email, password, change_password, must_use_faq)
def get_success_url(self):
return reverse("profiles.user_read", args=[self.object.pk])
class CreateIn(PartnerPermsMixin, OrgFormMixin, SmartCreateView):
"""
Form for creating partner-level users in a specific partner
"""
permission = "profiles.profile_user_create_in"
form_class = PartnerUserForm
fields = ("name", "role", "email", "password", "confirm_password", "change_password", "must_use_faq")
@classmethod
def derive_url_pattern(cls, path, action):
return r"^user/create_in/(?P\d+)/$"
def get_partner(self):
return Partner.get_all(self.request.org).get(pk=self.kwargs["partner_id"])
def save(self, obj):