@@ -346,7 +346,7 @@ def clean_niche_urls(self):
346346 raise forms .ValidationError (
347347 _ ("'%(url)s' is an invalid URL." ), params = {"url" : url }
348348 )
349- return data
349+ return " \n " . join ( niche_urls )
350350
351351 def save (self , commit = True ):
352352 if not self .instance .targeting_parameters :
@@ -1371,11 +1371,20 @@ def get_ads(self):
13711371class AdvertisementCopyForm (forms .Form ):
13721372 """Used by advertisers to re-use their ads."""
13731373
1374+ MAXIMUM_ADS = 100
1375+ DEFAULT_ORDER = "-modified"
1376+
13741377 advertisements = AdvertisementMultipleChoiceField (
13751378 queryset = Advertisement .objects .none (),
13761379 required = False ,
13771380 help_text = _ ("Copy the following advertisements" ),
13781381 )
1382+ live_after_copy = forms .BooleanField (
1383+ required = False ,
1384+ initial = False ,
1385+ label = _ ("Make copied ads live" ),
1386+ help_text = _ ("If checked, the copied ads will be live immediately" ),
1387+ )
13791388
13801389 def __init__ (self , * args , ** kwargs ):
13811390 """Add the form helper and customize the look of the form."""
@@ -1384,14 +1393,24 @@ def __init__(self, *args, **kwargs):
13841393 else :
13851394 raise RuntimeError ("'flight' is required for the ad form" )
13861395
1396+ if "order" in kwargs :
1397+ order = kwargs .pop ("order" )
1398+ else :
1399+ order = self .DEFAULT_ORDER
1400+
13871401 super ().__init__ (* args , ** kwargs )
13881402
1403+ # Use the passed order to sort the ads on the form
13891404 self .fields ["advertisements" ].queryset = (
13901405 Advertisement .objects .filter (flight__campaign = self .flight .campaign )
1391- .order_by ("-flight__start_date" , "slug" )
1406+ .order_by (order , "slug" )
13921407 .select_related ()
13931408 .prefetch_related ("ad_types" )
13941409 )
1410+ # Limit the choices so the form isn't *too* long
1411+ self .fields ["advertisements" ].choices = self .fields ["advertisements" ].choices [
1412+ : self .MAXIMUM_ADS
1413+ ]
13951414
13961415 self .helper = FormHelper ()
13971416 self .helper .attrs = {"id" : "advertisements-copy" }
@@ -1403,6 +1422,10 @@ def __init__(self, *args, **kwargs):
14031422 "advertisements" ,
14041423 template = "adserver/includes/widgets/advertisement-form-option.html" ,
14051424 ),
1425+ Fieldset (
1426+ _ ("Options" ),
1427+ Field ("live_after_copy" ),
1428+ ),
14061429 css_class = "my-3" ,
14071430 ),
14081431 Submit ("submit" , _ ("Copy existing ads" )),
@@ -1413,6 +1436,8 @@ def save(self):
14131436 for ad in self .cleaned_data ["advertisements" ]:
14141437 new_ad = ad .__copy__ ()
14151438 new_ad .flight = self .flight
1439+ if self .cleaned_data ["live_after_copy" ]:
1440+ new_ad .live = True
14161441 new_ad .save ()
14171442
14181443 return len (self .cleaned_data ["advertisements" ])
0 commit comments