Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from rest_framework import serializers
from crash.models import Symbols, Crash
from crash.utils import parse_debug_meta_info
__all__ = ['SymbolsSerializer']
class SymbolsSerializer(serializers.HyperlinkedModelSerializer):
file = serializers.FileField(required=True)
debug_id = serializers.CharField(default='', required=False, allow_blank=True)
debug_file = serializers.CharField(default='', required=False, allow_blank=True)
class Meta:
model = Symbols
fields = ('id', 'file', 'file_size', 'debug_id', 'debug_file',
'created', 'modified')
read_only_fields = ('created', 'modified')
validators = [
serializers.UniqueTogetherValidator(
queryset=Symbols.objects.all(),
fields=('debug_id', 'debug_file')
)
]
def create(self, validated_data):
if not validated_data.get('debug_id') or \
not validated_data.get('debug_file'):
file = validated_data['file']
try:
head = file.readline().rstrip()
def get_prefix(model_name):
model_path_prefix = {
Crash: ('minidump', 'minidump_archive'),
Feedback: ('blackbox', 'system_logs', 'feedback_attach', 'screenshot'),
Symbols: ('symbols',),
Version: ('build',),
SparkleVersion: ('sparkle',)
}
return model_path_prefix[model_name]
@bulk_delete.register(Symbols)
def _(cls, qs):
if settings.DEFAULT_FILE_STORAGE == 'storages.backends.s3boto.S3BotoStorage':
qs = s3_bulk_delete(qs, file_fields=['file'], s3_fields=['symbols'])
result = dict()
result['count'] = qs.count()
result['size'] = qs.get_size()
elements = list(qs.values_list('id', 'created'))
result['elements'] = map(lambda x: dict(id=x[0], element_created=x[1].strftime("%d. %B %Y %I:%M%p")), elements)
qs.delete()
return result
def regenerate_stacktrace(self, request, queryset):
for i in queryset:
signature("tasks.processing_crash_dump", args=(i.pk,)).apply_async(queue='default')
regenerate_stacktrace.short_description = 'Regenerate stacktrace'
def get_form(self, request, obj=None, **kwargs):
if CRASH_TRACKER != 'Sentry':
try:
self.readonly_fields.remove('sentry_link_field')
except ValueError:
pass
return super(CrashAdmin, self).get_form(request, obj, **kwargs)
@admin.register(Symbols)
class SymbolsAdmin(admin.ModelAdmin):
readonly_fields = ('created', 'modified', )
list_display = ('created', 'modified', 'debug_file', 'debug_id',)
list_display_links = ('created', 'modified', 'debug_file', 'debug_id',)
form = SymbolsAdminForm