Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_form_kwargs(self):
views = View.objects.filter_current_site().filter_catalog(self.object.catalog).filter_group(self.request.user)
form_kwargs = super().get_form_kwargs()
form_kwargs.update({
'views': views
})
return form_kwargs
def get_context_data(self, **kwargs):
context = super(ProjectViewView, self).get_context_data(**kwargs)
try:
context['current_snapshot'] = context['project'].snapshots.get(pk=self.kwargs.get('snapshot_id'))
except Snapshot.DoesNotExist:
context['current_snapshot'] = None
try:
context['view'] = context['project'].views.get(pk=self.kwargs.get('view_id'))
except View.DoesNotExist:
raise Http404
try:
context['rendered_view'] = context['view'].render(context['project'], context['current_snapshot'])
except TemplateSyntaxError:
context['rendered_view'] = None
context.update({
'snapshots': list(context['project'].snapshots.values('id', 'title')),
'export_formats': settings.EXPORT_FORMATS
})
return context
def save(self, *args, **kwargs):
self.uri = self.build_uri()
super(View, self).save(*args, **kwargs)
def import_view(element):
try:
view = View.objects.get(uri=element['uri'])
except View.DoesNotExist:
log.info('View not in db. Created with uri %s.', element['uri'])
view = View()
view.uri_prefix = element['uri_prefix'] or ''
view.key = element['key'] or ''
view.comment = element['comment'] or ''
view.template = element['template'] or ''
for lang_code, lang_string, lang_field in get_languages():
set_lang_field(view, 'title', element, lang_code, lang_field)
set_lang_field(view, 'help', element, lang_code, lang_field)
try:
ViewUniqueKeyValidator(view).validate()
except ValidationError as e:
tasks_node = root.find('tasks')
if tasks_node is not None:
for task_node in tasks_node.findall('task'):
try:
task_uri = get_uri(task_node, ns_map)
project.tasks.add(Task.objects.get(uri=task_uri))
except Task.DoesNotExist:
pass
views_node = root.find('views')
if views_node is not None:
for view_node in views_node.findall('view'):
try:
view_uri = get_uri(view_node, ns_map)
project.views.add(View.objects.get(uri=view_uri))
except View.DoesNotExist:
pass
snapshots_node = root.find('snapshots')
if snapshots_node is not None:
for snapshot_node in snapshots_node.findall('snapshot'):
if snapshot_node is not None:
snapshot = Snapshot()
snapshot.project = project
snapshot.title = snapshot_node.find('title').text or ''
snapshot.description = snapshot_node.find('description').text or ''
snapshot.created = snapshot_node.find('created').text
snapshot.save()
snapshot_values_node = snapshot_node.find('values')
if snapshot_values_node is not None:
for snapshot_value_node in snapshot_values_node.findall('value'):
from rest_framework.viewsets import ModelViewSet
from rest_framework.decorators import action
from rest_framework.response import Response
from django_filters.rest_framework import DjangoFilterBackend
from rdmo.core.permissions import HasModelPermission
from .models import View
from .serializers.v1 import ViewSerializer, ViewIndexSerializer
class ViewViewSet(ModelViewSet):
permission_classes = (HasModelPermission, )
queryset = View.objects.all()
serializer_class = ViewSerializer
filter_backends = (DjangoFilterBackend,)
filter_fields = (
'uri',
'key'
)
@action(detail=False)
def index(self, request):
serializer = ViewIndexSerializer(self.get_queryset(), many=True)
return Response(serializer.data)
tasks_node = root.find('tasks')
if tasks_node is not None:
for task_node in tasks_node.findall('task'):
try:
task_uri = get_uri(task_node, ns_map)
project.tasks.add(Task.objects.get(uri=task_uri))
except Task.DoesNotExist:
pass
views_node = root.find('views')
if views_node is not None:
for view_node in views_node.findall('view'):
try:
view_uri = get_uri(view_node, ns_map)
project.views.add(View.objects.get(uri=view_uri))
except View.DoesNotExist:
pass
snapshots_node = root.find('snapshots')
if snapshots_node is not None:
for snapshot_node in snapshots_node.findall('snapshot'):
if snapshot_node is not None:
snapshot = Snapshot()
snapshot.project = project
snapshot.title = snapshot_node.find('title').text or ''
snapshot.description = snapshot_node.find('description').text or ''
snapshot.created = snapshot_node.find('created').text
snapshot.save()
snapshot_values_node = snapshot_node.find('values')
if snapshot_values_node is not None:
def import_view(element):
try:
view = View.objects.get(uri=element['uri'])
except View.DoesNotExist:
log.info('View not in db. Created with uri %s.', element['uri'])
view = View()
view.uri_prefix = element['uri_prefix'] or ''
view.key = element['key'] or ''
view.comment = element['comment'] or ''
view.template = element['template'] or ''
for lang_code, lang_string, lang_field in get_languages():
set_lang_field(view, 'title', element, lang_code, lang_field)
set_lang_field(view, 'help', element, lang_code, lang_field)
try:
ViewUniqueKeyValidator(view).validate()
blank=True,
verbose_name=_('Description'),
help_text=_('A description for this project (optional).')
)
catalog = models.ForeignKey(
Catalog, related_name='+', on_delete=models.SET_NULL, null=True,
verbose_name=_('Catalog'),
help_text=_('The catalog which will be used for this project.')
)
tasks = models.ManyToManyField(
Task, blank=True,
verbose_name=_('Tasks'),
help_text=_('The tasks that will be used for this project.')
)
views = models.ManyToManyField(
View, blank=True,
verbose_name=_('Views'),
help_text=_('The views that will be used for this project.')
)
class Meta:
ordering = ('title', )
verbose_name = _('Project')
verbose_name_plural = _('Projects')
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('project', kwargs={'pk': self.pk})
@cached_property
for obj in Catalog.objects.all():
self._set_uri_prefix(obj, options['uri_prefix'])
for obj in Section.objects.all():
self._set_uri_prefix(obj, options['uri_prefix'])
for obj in Subsection.objects.all():
self._set_uri_prefix(obj, options['uri_prefix'])
for obj in QuestionEntity.objects.all():
self._set_uri_prefix(obj, options['uri_prefix'])
for obj in Task.objects.all():
self._set_uri_prefix(obj, options['uri_prefix'])
for obj in View.objects.all():
self._set_uri_prefix(obj, options['uri_prefix'])