93
93
'obj': next_bit_for(bits, 'get_attachments_for'),
94
94
'var_name': next_bit_for(bits, 'as', '"attachments"'),
96
return AttachmentsForObjectNode(**args)
b'\\ No newline at end of file'
96
return AttachmentsForObjectNode(**args)
98
class AttachmentsSizeForObjectNode(Node):
99
def __init__(self, obj, var_name):
101
self.var_name = var_name
103
def resolve(self, var, context):
104
"""Resolves a variable out of context if it's not in quotes"""
105
if var[0] in ('"', "'") and var[-1] == var[0]:
108
return Variable(var).resolve(context)
110
def render(self, context):
112
obj = self.resolve(self.obj, context)
113
var_name = self.resolve(self.var_name, context)
114
context[var_name] = Attachment.objects.attachments_size_for_object(obj) / MEGABYTE
119
def get_attachments_size_for(parser, token):
120
def next_bit_for(bits, key, if_none=None):
122
return bits[bits.index(key)+1]
126
bits = token.contents.split()
128
'obj': next_bit_for(bits, 'get_attachments_size_for'),
129
'var_name': next_bit_for(bits, 'as', '"attachments_size"'),
131
return AttachmentsSizeForObjectNode(**args)