<s> from __future__ import unicode_literals <EOL> from builtins import str <EOL> from builtins import object <EOL> from datetime import date <EOL> from django . contrib import admin <EOL> from django . contrib . admin import SimpleListFilter <EOL> from django . core . exceptions import ValidationError <EOL> from django . forms . models import BaseInlineFormSet <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from dynamic_scraper . models import * <EOL> class ScrapedObjAttrFormSet ( BaseInlineFormSet ) : <EOL> def clean ( self ) : <EOL> super ( ScrapedObjAttrFormSet , self ) . clean ( ) <EOL> cnt_type_b = <NUM_LIT:0> <EOL> cnt_type_u = <NUM_LIT:0> <EOL> cnt_type_i = <NUM_LIT:0> <EOL> cnt_id = <NUM_LIT:0> <EOL> cnt_wrong_id_type = <NUM_LIT:0> <EOL> for form in self . forms : <EOL> if not hasattr ( form , '<STR_LIT>' ) : <EOL> continue <EOL> data = form . cleaned_data <EOL> if '<STR_LIT>' in data and data [ '<STR_LIT>' ] : <EOL> continue <EOL> if not '<STR_LIT>' in data or not '<STR_LIT>' in data : <EOL> continue <EOL> at = data [ '<STR_LIT>' ] <EOL> if at == '<STR_LIT:B>' : <EOL> cnt_type_b += <NUM_LIT:1> <EOL> if at == '<STR_LIT>' : <EOL> cnt_type_u += <NUM_LIT:1> <EOL> if at == '<STR_LIT:I>' : <EOL> cnt_type_i += <NUM_LIT:1> <EOL> id_field = data [ '<STR_LIT>' ] <EOL> if id_field : <EOL> cnt_id += <NUM_LIT:1> <EOL> if ( at != '<STR_LIT:S>' and at != '<STR_LIT>' ) : <EOL> cnt_wrong_id_type += <NUM_LIT:1> <EOL> if cnt_type_b == <NUM_LIT:0> : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> if cnt_type_b > <NUM_LIT:1> : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> if cnt_type_u > <NUM_LIT> : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> if cnt_type_i > <NUM_LIT:1> : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> if cnt_wrong_id_type > <NUM_LIT:0> : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> class ScrapedObjAttrInline ( admin . TabularInline ) : <EOL> model = ScrapedObjAttr <EOL> formset = ScrapedObjAttrFormSet <EOL> extra = <NUM_LIT:3> <EOL> class ScrapedObjClassAdmin ( admin . ModelAdmin ) : <EOL> inlines = [ <EOL> ScrapedObjAttrInline <EOL> ] <EOL> class RequestPageTypeFormSet ( BaseInlineFormSet ) : <EOL> def clean ( self ) : <EOL> super ( RequestPageTypeFormSet , self ) . clean ( ) <EOL> cnt_rpts = <NUM_LIT:0> <EOL> cnt_rpts_mp = <NUM_LIT:0> <EOL> cnt_rpts_dp = <NUM_LIT:0> <EOL> for form in self . forms : <EOL> if not hasattr ( form , '<STR_LIT>' ) : <EOL> continue <EOL> data = form . cleaned_data <EOL> if '<STR_LIT>' in data and data [ '<STR_LIT>' ] : <EOL> continue <EOL> if not '<STR_LIT>' in data : <EOL> continue <EOL> cnt_rpts += <NUM_LIT:1> <EOL> pt = data [ '<STR_LIT>' ] <EOL> if pt == '<STR_LIT>' : <EOL> cnt_rpts_mp += <NUM_LIT:1> <EOL> else : <EOL> cnt_rpts_dp += <NUM_LIT:1> <EOL> if cnt_rpts_mp == <NUM_LIT:0> : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> if cnt_rpts_mp > <NUM_LIT:1> : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> class RequestPageTypeInline ( admin . StackedInline ) : <EOL> model = RequestPageType <EOL> formset = RequestPageTypeFormSet <EOL> extra = <NUM_LIT:0> <EOL> class CheckerInline ( admin . StackedInline ) : <EOL> model = Checker <EOL> extra = <NUM_LIT:0> <EOL> class ScraperElemInline ( admin . TabularInline ) : <EOL> model = ScraperElem <EOL> extra = <NUM_LIT:3> <EOL> class ScraperAdmin ( admin . ModelAdmin ) : <EOL> class Media ( object ) : <EOL> js = ( "<STR_LIT>" , ) <EOL> list_display = ( '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT:status>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> list_display_links = ( '<STR_LIT:name>' , ) <EOL> list_editable = ( '<STR_LIT:status>' , ) <EOL> list_filter = ( '<STR_LIT>' , '<STR_LIT:status>' , '<STR_LIT>' , ) <EOL> search_fields = [ '<STR_LIT:name>' ] <EOL> inlines = [ <EOL> RequestPageTypeInline , <EOL> CheckerInline , <EOL> ScraperElemInline <EOL> ] <EOL> fieldsets = ( <EOL> ( None , { <EOL> '<STR_LIT>' : ( '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT:status>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> } ) , <EOL> ( None , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) <EOL> } ) , <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> } ) , <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , ) <EOL> } ) , <EOL> ( None , { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , ) <EOL> } ) , <EOL> ) <EOL> def rpts ( self , obj ) : <EOL> return str ( obj . requestpagetype_set . count ( ) ) <EOL> def checkers ( self , obj ) : <EOL> cnt = obj . checker_set . count ( ) <EOL> if cnt > <NUM_LIT:0> : <EOL> return str ( cnt ) <EOL> else : <EOL> return "<STR_LIT>" <EOL> def last_scraper_save_ ( self , obj ) : <EOL> html_str = '<STR_LIT>' <EOL> if obj . last_scraper_save : <EOL> html_str = obj . last_scraper_save . strftime ( '<STR_LIT>' ) <EOL> if obj . last_scraper_save_alert_period != '<STR_LIT>' : <EOL> td = obj . get_last_scraper_save_alert_period_timedelta ( ) <EOL> if td : <EOL> html_str = html_str + '<STR_LIT>' + obj . last_scraper_save_alert_period + '<STR_LIT:)>' <EOL> if not obj . last_scraper_save or obj . last_scraper_save < datetime . datetime . now ( ) - td : <EOL> html_str = '<STR_LIT>' + html_str + '<STR_LIT>' <EOL> return html_str <EOL> last_scraper_save_ . allow_tags = True <EOL> def last_checker_delete_ ( self , obj ) : <EOL> html_str = '<STR_LIT>' <EOL> if obj . last_checker_delete : <EOL> html_str = obj . last_checker_delete . strftime ( '<STR_LIT>' ) <EOL> if obj . last_checker_delete_alert_period != '<STR_LIT>' : <EOL> td = obj . get_last_checker_delete_alert_period_timedelta ( ) <EOL> if td : <EOL> html_str = html_str + '<STR_LIT>' + obj . last_checker_delete_alert_period + '<STR_LIT:)>' <EOL> if not obj . last_checker_delete or obj . last_checker_delete < datetime . datetime . now ( ) - td : <EOL> html_str = '<STR_LIT>' + html_str + '<STR_LIT>' <EOL> return html_str <EOL> last_checker_delete_ . allow_tags = True <EOL> actions = [ '<STR_LIT>' , ] <EOL> def clone_scrapers ( self , request , queryset ) : <EOL> for scraper in queryset : <EOL> scraper_elems = scraper . scraperelem_set . all ( ) <EOL> rpts = scraper . requestpagetype_set . all ( ) <EOL> checkers = scraper . checker_set . all ( ) <EOL> scraper . pk = None <EOL> scraper . name = scraper . name + "<STR_LIT>" <EOL> scraper . status = '<STR_LIT:P>' <EOL> scraper . save ( ) <EOL> for se in scraper_elems : <EOL> se . pk = None <EOL> se . scraper = scraper <EOL> se . save ( ) <EOL> for rpt in rpts : <EOL> rpt . pk = None <EOL> rpt . scraper = scraper <EOL> rpt . save ( ) <EOL> for checker in checkers : <EOL> checker . pk = None <EOL> checker . scraper = scraper <EOL> checker . save ( ) <EOL> rows_updated = queryset . count ( ) <EOL> if rows_updated == <NUM_LIT:1> : <EOL> message_bit = "<STR_LIT>" <EOL> else : <EOL> message_bit = "<STR_LIT>" . format ( num = rows_updated ) <EOL> self . message_user ( request , "<STR_LIT>" . format ( mb = message_bit ) ) <EOL> clone_scrapers . short_description = "<STR_LIT>" <EOL> class SchedulerRuntimeAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> list_filter = ( '<STR_LIT>' , ) <EOL> search_fields = [ '<STR_LIT:id>' ] <EOL> class LogMarkerAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> list_filter = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> search_fields = ( '<STR_LIT>' , ) <EOL> class LogDateFilter ( SimpleListFilter ) : <EOL> title = _ ( '<STR_LIT:date>' ) <EOL> parameter_name = '<STR_LIT:date>' <EOL> def lookups ( self , request , model_admin ) : <EOL> return ( <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ) <EOL> def queryset ( self , request , queryset ) : <EOL> if self . value ( ) == '<STR_LIT>' : <EOL> comp_date = datetime . datetime . today ( ) <EOL> return queryset . filter ( <EOL> date__year = comp_date . year , <EOL> date__month = comp_date . month , <EOL> date__day = comp_date . day , <EOL> ) <EOL> if self . value ( ) == '<STR_LIT>' : <EOL> comp_date = datetime . datetime . today ( ) - datetime . timedelta ( <NUM_LIT:1> ) <EOL> return queryset . filter ( <EOL> date__year = comp_date . year , <EOL> date__month = comp_date . month , <EOL> date__day = comp_date . day , <EOL> ) <EOL> if self . value ( ) == '<STR_LIT>' : <EOL> comp_date = datetime . datetime . now ( ) - datetime . timedelta ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> return queryset . filter ( <EOL> date__gt = comp_date <EOL> ) <EOL> if self . value ( ) == '<STR_LIT>' : <EOL> comp_date = datetime . datetime . now ( ) - datetime . timedelta ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:6> ) <EOL> return queryset . filter ( <EOL> date__gt = comp_date <EOL> ) <EOL> if self . value ( ) == '<STR_LIT>' : <EOL> comp_date = datetime . datetime . now ( ) - datetime . timedelta ( <NUM_LIT:1> ) <EOL> return queryset . filter ( <EOL> date__gt = comp_date <EOL> ) <EOL> if self . value ( ) == '<STR_LIT>' : <EOL> comp_date = datetime . datetime . now ( ) - datetime . timedelta ( <NUM_LIT:7> ) <EOL> return queryset . filter ( <EOL> date__gt = comp_date <EOL> ) <EOL> class LogAdmin ( admin . ModelAdmin ) : <EOL> list_display = ( '<STR_LIT:message>' , '<STR_LIT>' , '<STR_LIT:type>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> list_filter = ( LogDateFilter , '<STR_LIT:type>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , ) <EOL> search_fields = [ '<STR_LIT>' , ] <EOL> def scraper_ ( self , instance ) : <EOL> return instance . scraper . name <EOL> def date_ ( self , instance ) : <EOL> return instance . date . strftime ( '<STR_LIT>' ) <EOL> admin . site . register ( ScrapedObjClass , ScrapedObjClassAdmin ) <EOL> admin . site . register ( Scraper , ScraperAdmin ) <EOL> admin . site . register ( SchedulerRuntime , SchedulerRuntimeAdmin ) <EOL> admin . site . register ( LogMarker , LogMarkerAdmin ) <EOL> admin . site . register ( Log , LogAdmin ) </s>
