Exemplo n.º 1
0
def create_copy(request, pk):
    """ Copy a report including related fields """
    report = get_object_or_404(Report, pk=pk)
    new_report = duplicate(report, changes=(
        ('name', '{0} (copy)'.format(report.name)),
        ('user_created', request.user),
        ('user_modified', request.user),
    ))
    # duplicate does not get related
    for display in report.displayfield_set.all():
        new_display = copy.copy(display)
        new_display.pk = None
        new_display.report = new_report
        new_display.save()
    for report_filter in report.filterfield_set.all():
        new_filter = copy.copy(report_filter)
        new_filter.pk = None
        new_filter.report = new_report
        new_filter.save()
    return redirect(new_report)
Exemplo n.º 2
0
 def create(self, validated_data):
     report = validated_data.pop('id')
     nombre = validated_data.pop('name')
     usuario = self.context['request'].user
     new_report = duplicate(report,
                            changes=(
                                ('name', nombre),
                                ('user_created', usuario),
                                ('user_modified', usuario),
                            ))
     # duplicate does not get related
     for display in report.displayfield_set.all():
         new_display = copy.copy(display)
         new_display.pk = None
         new_display.report = new_report
         new_display.save()
     for report_filter in report.filterfield_set.all():
         new_filter = copy.copy(report_filter)
         new_filter.pk = None
         new_filter.report = new_report
         new_filter.save()
     return report