示例#1
0
    def _value_rows_from_queryset(cls, query_set, template, with_header=True,**kwargs):
        from spreadsheets.models import Spreadsheet
        rows = []

        template_instance = Spreadsheet.spreadsheet_template_instance_class(template.template_type)(query_set[0].account)
        if with_header:
            rows.append([f[1].name for f in template_instance.fields.iteritems()])
        
        for r in query_set:
            try:
                row = []
                template_instance.get_primary_target(r.account, r.pk, force_refresh=True)
                target_objects,created = template_instance.get_target_objects()

                for k,f in template.fields.iteritems():
                    col_val = None
                    if target_objects[f.model_key]:
                        # try:
                        if f.field in target_objects[f.model_key].__dict__:
                            col_val = target_objects[f.model_key].__dict__[f.field]
                        else:
                            col_val = eval("target_objects[f.model_key].%s" % f.field)
                        # except:
                        #     row.append("")    
                    if not col_val:
                        col_val = ""
                    row.append(col_val)
                rows.append(row)
            except Exception, e:
                print "Error exporting row %s %s %s\n %s" % (r, r.pk, template_instance, e)
                from qi_toolkit.helpers import print_exception
                print_exception()
                pass
示例#2
0
def setup_crontab():
    try:
        from crontab import CronTab
        tab = CronTab()
        daily_command = "%(backup_dir)s/%(daily_backup_script_name)s > /dev/null 2>&1" % env
        weekly_command = "%(backup_dir)s/%(weekly_backup_script_name)s > /dev/null 2>&1" % env
        monthly_command = "%(backup_dir)s/%(monthly_backup_script_name)s > /dev/null 2>&1" % env
        changed = False
        if len(tab.find_command(daily_command)) == 0:
            daily_tab = tab.new(command=daily_command)
            daily_tab.hour().on(1)
            daily_tab.minute().on(0)
            changed = True
        if len(tab.find_command(weekly_command)) == 0:
            weekly_tab = tab.new(command=weekly_command)
            weekly_tab.dow().on(1)
            weekly_tab.hour().on(2)
            weekly_tab.minute().on(0)
            changed = True
        if len(tab.find_command(monthly_command)) == 0:
            monthly_tab = tab.new(command=monthly_command)
            monthly_tab.dom().on(1)
            monthly_tab.hour().on(3)
            monthly_tab.minute().on(0)
            changed = True
        if changed:
            tab.write()
    except:
        print_exception()
        pass
def pretty_timesince(this_date):
    if not hasattr(this_date,"hour"):
        this_date = datetime.datetime.combine(this_date,datetime.time())
    try:
        if datetime.datetime.now() - this_date < datetime.timedelta(minutes=1):
            return _("a few seconds ago")
        if this_date > datetime.datetime.now() - datetime.timedelta(days=14):
            return shorttime(timesince(this_date)) + _(" ago")
        else:
            return date(this_date)
    except:
        from qi_toolkit.helpers import print_exception
        print_exception()
        return date(this_date)
示例#4
0
def smoke_test(url_name, *args, **kwargs):
    __test__ = True
    try:
        config = Config()
        config.__dict__.update(DEFAULT_SMOKE_TEST_OPTIONS)
        config.__dict__.update(**kwargs)

        if config.verbose:
            print "Smoke Test: %s  " % (url_name),

        reverse_url = None
        fail_error = None
        try:
            reverse_url = reverse(url_name, args=config.reverse_args, kwargs=config.reverse_kwargs)
        except:
            pass
        if not reverse_url:
            fail_error = "URL Reversing for '%s' failed." % (url_name)
        assert_true(reverse_url)

        if reverse_url:
            if config.method=="POST":
                response = config.client.post(reverse_url, config.data)
            else:
                response = config.client.get(reverse_url, config.data)
            if config.verbose:
                print "%s" % (response.status_code)

            if not response.status_code == config.status_code:
                fail_error = "Status code fail. Expected %s.  Got %s" %(config.status_code, response.status_code)
            assert_true(response.status_code == config.status_code)
        
        if config.check_title:
            fail_error = "Page is missing a title. %s" % (reverse_url)
            assert title_re.search(response.content) != None
        
        transaction.rollback()

    except:
        print fail_error
        from qi_toolkit.helpers import print_exception
        print_exception()
        transaction.rollback()
        assert 1==0
示例#5
0
def deploy_media():
    try:
        local("%(work_on)s cd %(project_name)s; git checkout %(release_tag)s; %(python)s manage.py syncmedia --settings=%(settings_file)s;git checkout %(pull_branch)s" % env)
    except:
        print_exception()