def create(pif): os.environ['PYTHON_EGG_CACHE'] = '/var/tmp' n = pif.form.get_str('n') p = pif.form.get_str('p') p2 = pif.form.get_str('p2') e = pif.form.get_str('e') if not n or not p or p != p2 or not e: pif.render.print_html() return pif.render.format_template('signup.html', dest=pif.form.get_str('dest')) vkey = useful.generate_token(10) id = pif.dbh.create_user(n, p, e, vkey) if id: gen_email(n, e, vkey) expire = (15 * 12 * 60 * 60) if ('a' in privs) else (60 * 365 * 24 * 60 * 60) pif.render.set_cookie( pif.render.secure.make_cookie(id, '', expires=expire)) useful.warn( "Your account has been created. Please check your email for the verification." ) raise useful.Redirect("/cgi-bin/login.cgi") pif.render.print_html() return pif.render.format_template('signup.html', dest=pif.form.get_str('dest'))
def recover_main(pif): pif.render.print_html() hide_vkey = recovering = False user_id = None if pif.form.has('user_id'): if pif.form.has('vkey'): user = pif.dbh.fetch_user(user_id=pif.form.get_alnum('user_id'), vkey=pif.form.get_alnum('vkey')) if user: if pif.form.has('p1') and pif.form.get_str('p1') == pif.form.get_str('p2'): pif.dbh.update_password(user.id, pif.form.get_str('p2')) pif.dbh.update_user(rec_id=user.id, flags=user.flags & ~config.FLAG_USER_PASSWORD_RECOVERY) pif.render.set_cookie(pif.render.secure.clear_cookie(['id'])) useful.warn("Your password has been changed.") raise useful.Redirect('/cgi-bin/login.cgi', delay=5) else: user_id = user.user_id recovering = hide_vkey = True else: user = pif.dbh.fetch_user(email=pif.form.get_str('user_id')) if not user: user = pif.dbh.fetch_user(user_id=pif.form.get_alnum('user_id')) if user: pif.dbh.update_user(rec_id=user.id, flags=user.flags | config.FLAG_USER_PASSWORD_RECOVERY) generate_recovery_email(pif, user) recovering = True user_id = user.user_id return pif.render.format_template('recover.html', recovering=recovering, user_id=user_id, show_vkey=not hide_vkey)
def create(pif): os.environ['PYTHON_EGG_CACHE'] = '/var/tmp' user_id = pif.form.get_str('user_id') p1 = pif.form.get_str('p') p2 = pif.form.get_str('p2') email = pif.form.get_str('email') if not user_id or (set(user_id) - set(string.ascii_letters + string.digits + '._')): raise useful.SimpleError('That is not a legal user ID.') if pif.dbh.fetch_user(user_id=user_id): raise useful.SimpleError('That ID is already in use.') if not email: raise useful.SimpleError('Please specify an email address.') if not p1 or p1 != p2: raise useful.SimpleError('Please specify the same password in both password boxes.') vkey = useful.generate_token(10) rec_id = pif.dbh.create_user(passwd=p1, vkey=vkey, privs='b', **pif.form.form) if rec_id: user = pif.dbh.fetch_user(id=rec_id) generate_signup_email(pif, user) # expire = (15 * 12 * 60 * 60) if ('a' in privs) else (60 * 365 * 24 * 60 * 60) # pif.render.set_cookie(pif.render.secure.make_cookie(rec_id, '', expires=expire)) useful.warn("Your account has been created. Please check your email for the verification.") raise useful.Redirect("/cgi-bin/validate.cgi") return pif.render.format_template('signup.html', dest=pif.form.get_str('dest'))
def change_password_main(pif): pif.render.title = 'Change Password' pif.render.hide_title = False pif.render.print_html() if not pif.user_id: raise useful.SimpleError("It doesn't look like you're logged in!") if pif.form.has('id') and pif.is_allowed('a') and pif.form.get_int('id') != pif.user_id: user = pif.dbh.fetch_user(pif.form.get_int('id')) else: user = pif.user if not user: raise useful.SimpleError('That user record ({}) was not found.'.format(pif.user_id)) if pif.is_allowed('a') and 'p1' in pif.form: user_id = pif.form.get_int('id') if pif.form.get_str('p1') != pif.form.get_str('p2'): useful.warn("The new passwords don't match!") else: pif.dbh.update_password(user_id, pif.form.get_str('p2')) useful.warn("This password has been changed.") elif 'op' in pif.form: newuser = pif.dbh.fetch_user(user_id=pif.user_id, passwd=pif.form.get_str('op')) if not newuser: useful.warn("That password isn't correct!") elif pif.form.get_str('p1') != pif.form.get_str('p2'): useful.warn("The new passwords don't match!") else: pif.dbh.update_password(pif.user_id, pif.form.get_str('p2')) pif.dbh.update_user(pif.user_id, ckey=uuid.uuid4()) pif.create_cookie() useful.warn("Your password has been changed.") entries = [ {'title': 'Old password:'******'value': '<input type="password" name="op">'}, {'title': 'New password:'******'value': '<input type="password" name="p1">'}, {'title': 'Retry new password:'******'value': '<input type="password" name="p2">'}, ] lsection = { 'columns': ['title', 'value'], 'range': [{'entry': entries}], 'note': '', 'noheaders': True, 'header': pif.render.format_form_start(method='post', token=pif.dbh.create_token()), 'footer': pif.render.format_hidden_input({'id': user['id']}) + pif.render.format_button_input() + "</form>", } return pif.render.format_template( 'simplelistix.html', header='''<br>You have requested to change your password.<br>''', llineup={'section': [lsection]}, nofooter=True)
def change_password_main(pif): pif.render.title = 'Change Password' pif.render.hide_title = False pif.render.print_html() if not pif.user_id: raise useful.SimpleError("It doesn't look like you're logged in!") table_info = pif.dbh.table_info['user'] if pif.form.has('id') and pif.is_allowed('a') and pif.form.get_int('id') != pif.user_id: user = pif.dbh.fetch_user(pif.form.get_int('id')) else: user = pif.user if not user: raise useful.SimpleError('That user record (%s) was not found.' % pif.user_id) if pif.is_allowed('a') and 'p1' in pif.form: user_id = pif.form.get_int('id') if pif.form.get_str('p1') != pif.form.get_str('p2'): useful.warn("The new passwords don't match!") else: pif.dbh.update_password(user_id, pif.form.get_str('p2')) useful.warn("This password has been changed.") elif 'op' in pif.form: newuser = pif.dbh.fetch_user(user_id=pif.user_id, passwd=pif.form.get_str('op')) if not newuser: useful.warn("That password isn't correct!") elif pif.form.get_str('p1') != pif.form.get_str('p2'): useful.warn("The new passwords don't match!") else: pif.dbh.update_password(pif.user_id, pif.form.get_str('p2')) expire = (15 * 12 * 60 * 60) if ('a' in pif.user.privs) else (60 * 365 * 24 * 60 * 60) pif.render.set_cookie(pif.render.secure.make_cookie(id, pif.user.privs, expires=expire)) useful.warn("Your password has been changed.") entries = [ {'title': 'Old password:'******'value': '<input type="password" name="op">'}, {'title': 'New password:'******'value': '<input type="password" name="p1">'}, {'title': 'Retry new password:'******'value': '<input type="password" name="p2">'}, ] lsection = { 'columns': ['title', 'value'], 'range': [{'entry': entries}], 'note': '', 'noheaders': True, 'header': pif.render.format_form_start(method='post', token=pif.dbh.create_token()), 'footer': pif.render.format_hidden_input({'id': user['id']}) + pif.render.format_button_input() + "</form>", } return pif.render.format_template('simplelistix.html', header='''<br>You have requested to change your password.<br>''', llineup={'section': [lsection]}, nofooter=True)
def verify(pif, name, vkey): userrec = pif.dbh.fetch_user(vkey=vkey, name=name) if userrec: userrec = userrec[0] id = userrec['user.id'] pif.dbh.update_user(id, state=1) useful.warn( "Your account has been verified! Now please log in.<br><hr>") raise useful.Redirect("/cgi-bin/login.cgi") useful.warn( "You have not verified your account. Please contact [email protected] for help." ) raise useful.Redirect("/")
def login_main(pif): if pif.form.has('user_id') and pif.form.has('p'): user = pif.dbh.fetch_user(user_id=pif.form.get_str('user_id'), passwd=pif.form.get_str('p')) if user: pif.dbh.update_user_last_login(user.id) pif.create_cookie(user) if not user.flags & config.FLAG_USER_VERIFIED: raise useful.Redirect('/cgi-bin/validate.cgi') raise useful.Redirect(pif.form.get_str('dest', '/index.php')) useful.warn("Login Failed!") pif.render.print_html() return pif.render.format_template('login.html', dest=pif.form.get_str('dest', '/index.php'), register='signup.cgi?dest=' + pif.form.get_str('dest', '/index.php'), forgot='recover.cgi')
def login_main(pif): if pif.form.has('n'): id, privs = pif.dbh.login(pif.form.get_str('n'), pif.form.get_str('p')) if id: expire = (15 * 12 * 60 * 60) if ('a' in privs) else (60 * 365 * 24 * 60 * 60) pif.render.set_cookie( pif.render.secure.make_cookie(id, privs, expires=expire)) raise useful.Redirect(pif.form.get_str('dest', '/index.php')) useful.warn("Login Failed!") pif.render.print_html() return pif.render.format_template( 'login.html', dest=pif.form.get_str('dest', '/index.php'), register='signup.cgi?dest=' + pif.form.get_str('dest', '/index.php'))
def login_main(pif): if pif.form.has('user_id'): user = pif.dbh.fetch_user(user_id=pif.form.get_str('user_id'), passwd=pif.form.get_str('p')) if user: pif.dbh.update_user_last_login(user.id) expire = (15 * 12 * 60 * 60) if ('a' in user.privs) else (60 * 365 * 24 * 60 * 60) pif.render.set_cookie(pif.render.secure.make_cookie(user.id, user.privs, expires=expire)) if not user.flags & config.FLAG_USER_VERIFIED: raise useful.Redirect('/cgi-bin/validate.cgi') raise useful.Redirect(pif.form.get_str('dest', '/index.php')) useful.warn("Login Failed!") pif.render.print_html() return pif.render.format_template('login.html', dest=pif.form.get_str('dest', '/index.php'), register='signup.cgi?dest=' + pif.form.get_str('dest', '/index.php'), forgot='recover.cgi')
def editor_start(pif): if pif.form.get_bool('clear'): pif.dbh.clear_health() errs = pif.dbh.fetch_counters("health!=0") if errs: useful.warn('<hr>', "<b>Errors found:<br><ul>", '\n'.join(["<li>" + err['counter.id'] for err in errs]), "</ul></b>", pif.render.format_button('clear', '?clear=1')) context = { 'table_info': pif.dbh.table_info, 'asks': sorted([t for t in pif.dbh.table_info if 'ask' in pif.dbh.table_info[t]]), 'masses': [x[0] for x in masses.mass_mains_list], } return pif.render.format_template('editorask.html', **context)
def profile_main(pif): pif.render.title = 'User Profile' pif.render.hide_title = False pif.render.print_html() if not pif.user_id: raise useful.SimpleError("It doesn't look like you're logged in!") table_info = pif.dbh.table_info['user'] user = pif.user if not user: raise useful.SimpleError('That user record ({}) was not found.'.format(pif.user_id)) if 'user_id' in pif.form: newuser = pif.dbh.fetch_user(user_id=pif.form.get_str('user_id')) if newuser and newuser.id != pif.form.get_int('id'): raise useful.SimpleError('Sorry, but that user ID is already in use.') if pif.dbh.update_profile(user, **pif.form.form): useful.warn('Your profile has been updated.') else: useful.warn('Updating your profile failed.') # if email changed, clear verified header = pif.render.format_form_start(method='post', token=pif.dbh.create_token()) rows = table_info['editable'] desc = pif.dbh.describe_dict('user') def prof_row(row): return {'title': table_info['title'][row], 'value': pif.render.format_text_input( row, desc[row]['length'], 80, value=user[row]) + ( '<br>If you change your email address, you will have to verify the new one.' if row == 'email' else '')} entries = [prof_row(row) for row in rows] if user['flags'] & config.FLAG_USER_BAMCA_MEMBER: entries[0]['value'] += ' ' + pif.render.fmt_art('bamca_member') footer = pif.render.format_hidden_input({'id': user['id']}) footer += pif.render.format_button_input() + "</form>" footer += pif.render.format_button('change password', '/cgi-bin/chpass.cgi') if user['photographer_id']: footer += pif.render.format_button( 'your pictures', '/cgi-bin/photogs.cgi?id={}'.format(user['photographer_id'])) lsection = dict(columns=['title', 'value'], range=[{'entry': entries}], note='', noheaders=True, header=header, footer=footer) return pif.render.format_template( 'simplelistix.html', header=('''<br>Currently this information is only available to administrators of this website. We're ''' '''looking at possibly doing more in the future though.<br><br>'''), llineup=dict(section=[lsection]), nofooter=True)
def profile_main(pif): pif.render.title = 'User Profile' pif.render.hide_title = False pif.render.print_html() if not pif.user_id: raise useful.SimpleError("It doesn't look like you're logged in!") table_info = pif.dbh.table_info['user'] user = pif.user if not user: raise useful.SimpleError('That user record (%s) was not found.' % pif.user_id) if 'user_id' in pif.form: newuser = pif.dbh.fetch_user(user_id=pif.form.get_str('user_id')) if newuser and newuser.id != pif.form.get_int('id'): raise useful.SimpleError('Sorry, but that user ID is already in use.') if pif.dbh.update_profile(user, **pif.form.form): useful.warn('Your profile has been updated.') else: useful.warn('Updating your profile failed.') # if email changed, clear verified header = pif.render.format_form_start(method='post', token=pif.dbh.create_token()) rows = table_info['editable'] desc = pif.dbh.describe_dict('user') def prof_row(row): return {'title': table_info['title'][row], 'value': pif.render.format_text_input(row, desc[row]['length'], 80, value=user[row]) + ('<br>If you change your email address, you will have to verify the new one.' if row == 'email' else '')} entries = [prof_row(row) for row in rows] if user['flags'] & config.FLAG_USER_BAMCA_MEMBER: entries[0]['value'] += ' ' + pif.render.fmt_art('bamca_member') footer = pif.render.format_hidden_input({'id': user['id']}) footer += pif.render.format_button_input() + "</form>" footer += pif.render.format_button('change password', '/cgi-bin/chpass.cgi') if user['photographer_id']: footer += pif.render.format_button('your pictures', '/cgi-bin/photogs.cgi?id=%s' % user['photographer_id']) lsection = dict(columns=['title', 'value'], range=[{'entry': entries}], note='', noheaders=True, header=header, footer=footer) return pif.render.format_template('simplelistix.html', header='''<br>Currently this information is only available to administrators of this website. We're looking at possibly doing more in the future though.<br><br>''', llineup=dict(section=[lsection]), nofooter=True)
def create(pif): # os.environ['PYTHON_EGG_CACHE'] = '/var/tmp' user_id = pif.form.get_str('user_id') p1 = pif.form.get_str('p') p2 = pif.form.get_str('p2') email = pif.form.get_str('email') if not user_id or (set(user_id) - set(string.ascii_letters + string.digits + '._')): raise useful.SimpleError('That is not a legal user ID.') if pif.dbh.fetch_user(user_id=user_id): raise useful.SimpleError('That ID is already in use.') if not email: raise useful.SimpleError('Please specify an email address.') if not p1 or p1 != p2: raise useful.SimpleError('Please specify the same password in both password boxes.') vkey = useful.generate_token(10) rec_id = pif.dbh.create_user(passwd=p1, vkey=vkey, privs='b', **pif.form.form) if rec_id: user = pif.dbh.fetch_user(id=rec_id) generate_signup_email(pif, user) useful.warn("Your account has been created. Please check your email for the verification.") raise useful.Redirect("/cgi-bin/validate.cgi") return pif.render.format_template('signup.html', dest=pif.form.get_str('dest'))
def validate_main(pif): pif.render.print_html() if not pif.user_id: raise useful.Redirect("/cgi-bin/login.cgi") user = pif.user if 'vkey' in pif.form: if user and user.vkey == pif.form.get_str('vkey'): rec_id = user.id pif.dbh.verify_user(rec_id) useful.warn("Your account has been verified!") raise useful.Redirect("/", delay=5) else: useful.warn("That code is not correct. Please try again.") if 'resend' in pif.form: generate_signup_email(pif, pif.user) useful.warn("The code has been resent.") return pif.render.format_template('validate.html', user_id=pif.user.user_id, dest=pif.form.get_str('dest'))
def action(self, pif, tdir=None, fn=None): log_action = False if not fn: fn = self.fn if not tdir: tdir = self.tdir ret = {'fn': fn, 'dir': tdir, 'act': True} from_path = os.path.join(tdir, fn) to_dir = to_name = '' if self.delete: useful.file_delete(from_path) elif self.trash: useful.file_mover(from_path, os.path.join( '.' + config.TRASH_DIR, from_path[from_path.rfind('/') + 1:]), mv=True, inc=True, trash=False) elif self.archive: useful.file_mover(from_path, os.path.join(tdir, 'archive', fn), mv=True) ret['fn'] = '' elif self.spam: path = '../spam' if os.path.exists(os.path.join( tdir, '..', 'spam')) else 'spam' useful.file_mover(from_path, os.path.join(tdir, path, fn), mv=True) ret['fn'] = '' elif self.fixed: useful.file_mover(from_path, os.path.join(tdir, 'fixed', fn), mv=True) ret['fn'] = '' elif self.rename: if not self.nname: useful.warn('What? (rename, no name)') else: to_dir = tdir to_name = self.nname elif self.lib: if not self.man: useful.warn('What? (lib, no man)') elif not os.path.exists( useful.relpath('.' + config.LIB_MAN_DIR, self.man)): # man2 = pif.dbh.fetch_alias(self.man) # if not man2: useful.warn('bad destination') # else: # useful.file_mover(from_path, os.path.join('.' + config.LIB_MAN_DIR, man2['ref_id'].lower(), fn), # mv=self.mv, ov=self.ov) else: to_dir = useful.relpath('.' + config.LIB_MAN_DIR, self.man) to_name = self.nname elif self.mvbin: if not os.path.exists(os.path.join('lib', self.cat)): useful.warn('bad destination') else: to_dir = os.path.join('lib', self.cat) to_name = self.nname elif self.selcat: if not (self.man or self.nname) or not self.dest: useful.warn('What? (selcat, no name or dest)') else: ddir = self.dest dnam = self.man if self.man else self.nname if self.pref: dnam = self.pref + '_' + dnam if self.ptype == 't': ddir = '.' + config.IMG_DIR_ADD if self.suff: dnam += '-' + self.suff if dnam: to_name = dnam.lower() + '.jpg' to_dir = ddir log_action = True elif self.select: # inc = self.inc if not self.man: # self.man = tdir[tdir.rfind('/') + 1:] useful.warn('Huh? (select, no man)') else: ddir = '.' + config.IMG_DIR_MAN dnam = self.man if self.var: ddir = '.' + config.IMG_DIR_VAR dnam = dnam + '-' + self.var if self.pref: dnam = self.pref + '_' + dnam elif self.pref: if self.pref != 'n': dnam = self.pref + '_' + dnam if self.ptype == 't': ddir = '.' + config.IMG_DIR_ADD if self.suff: dnam += '-' + self.suff self.inc = True else: useful.warn("What? (select, no var or pref)") dnam = '' if dnam: to_name = dnam.lower() + '.jpg' to_dir = ddir log_action = True else: ret['act'] = False if to_dir: cred = pif.form.get_str('credit') if cred: photog = pif.dbh.fetch_photographer(cred) if not photog or not photog.flags & config.FLAG_PHOTOGRAPHER_PRIVATE: cred = '' useful.file_mover(from_path, os.path.join(to_dir, to_name), mv=self.mv, ov=self.ov, inc=self.inc) ret['fn'] = to_name ret['dir'] = to_dir if log_action and self.tumblr: title = pif.form.get_str('title', to_name) url = pif.secure_prod + os.path.join(to_dir, to_name) link = pif.secure_prod + self.link title = to_name if cred: title += ' credited to ' + photog.name pif.render.message( 'Post to Tumblr: ', tumblr.Tumblr(pif).create_photo(caption=title, source=url, link=link)) pif.render.message( 'Credit added: ', pif.dbh.write_photo_credit(cred, to_dir, to_name)) return ret
def action(self, pif, tdir=None, fn=None): log_action = False if not fn: fn = self.fn if not tdir: tdir = self.tdir ret = {'fn': fn, 'dir': tdir, 'act': True} from_path = os.path.join(tdir, fn) to_dir = to_name = '' if self.delete: useful.file_delete(from_path) elif self.archive: useful.file_mover(from_path, os.path.join(tdir, 'archive', fn), mv=True) ret['fn'] = '' elif self.fixed: useful.file_mover(from_path, os.path.join(tdir, 'fixed', fn), mv=True) ret['fn'] = '' elif self.rename: if not self.nname: useful.warn('What? (rename, no name)') else: to_dir = tdir to_name = self.nname elif self.lib: if not self.man: useful.warn('What? (lib, no man)') elif not os.path.exists( useful.relpath('.' + config.LIB_MAN_DIR, self.man)): # man2 = pif.dbh.fetch_alias(self.man) # if not man2: useful.warn('bad destination') # else: # useful.file_mover(from_path, os.path.join('.' + config.LIB_MAN_DIR, man2['ref_id'].lower(), fn), mv=self.mv, ov=self.ov) else: to_dir = useful.relpath('.' + config.LIB_MAN_DIR, self.man) to_name = self.nname elif self.mvbin: if not os.path.exists(os.path.join('lib', self.cat)): useful.warn('bad destination') else: to_dir = os.path.join('lib', self.cat) to_name = self.nname elif self.selcat: if not (self.man or self.nname) or not self.dest: useful.warn('What? (selcat, no name or dest)') else: ddir = self.dest dnam = self.man if self.man else self.nname if self.pref: dnam = self.pref + '_' + dnam if self.ptype == 't': ddir = '.' + config.IMG_DIR_ADD if self.suff: dnam += '-' + self.suff if dnam: to_name = dnam.lower() + '.jpg' to_dir = ddir log_action = True elif self.select: inc = self.inc if not self.man: #self.man = tdir[tdir.rfind('/') + 1:] useful.warn('Huh? (select, no man)') else: ddir = '.' + config.IMG_DIR_MAN dnam = self.man if self.var: ddir = '.' + config.IMG_DIR_VAR dnam = dnam + '-' + self.var if self.pref: dnam = self.pref + '_' + dnam elif self.pref: if self.pref != 'n': dnam = self.pref + '_' + dnam if self.ptype == 't': ddir = '.' + config.IMG_DIR_ADD if self.suff: dnam += '-' + self.suff self.inc = True else: useful.warn("What? (select, no var or pref)") dnam = '' if dnam: to_name = dnam.lower() + '.jpg' to_dir = ddir log_action = True else: ret['act'] = False if to_dir: useful.file_mover(from_path, os.path.join(to_dir, to_name), mv=self.mv, ov=self.ov, inc=self.inc) ret['fn'] = to_name ret['dir'] = to_dir if log_action: title = pif.form.get_str('title', to_name) url = 'http://www.bamca.org/' + os.path.join(to_dir, to_name) link = 'http://www.bamca.org/' + self.link useful.write_message( 'Post to Tumblr: ', tumblr.tumblr(pif).create_photo(caption=to_name, source=url, link=link)) pif.dbh.write_photo_credit(pif.form.get_str('credit'), to_dir, to_name) return ret
def action(self, pif, tdir=None, fn=None): log_action = False if not fn: fn = self.fn if not tdir: tdir = self.tdir ret = {'fn': fn, 'dir': tdir, 'act': True} from_path = os.path.join(tdir, fn) to_dir = to_name = '' if self.delete: useful.file_delete(from_path) elif self.trash: useful.file_mover(from_path, os.path.join('.' + config.TRASH_DIR, from_path[from_path.rfind('/') + 1:]), mv=True, inc=True, trash=False) elif self.archive: useful.file_mover(from_path, os.path.join(tdir, 'archive', fn), mv=True) ret['fn'] = '' elif self.spam: path = '../spam' if os.path.exists(os.path.join(tdir, '..', 'spam')) else 'spam' useful.file_mover(from_path, os.path.join(tdir, path, fn), mv=True) ret['fn'] = '' elif self.fixed: useful.file_mover(from_path, os.path.join(tdir, 'fixed', fn), mv=True) ret['fn'] = '' elif self.rename: if not self.nname: useful.warn('What? (rename, no name)') else: to_dir = tdir to_name = self.nname elif self.lib: if not self.man: useful.warn('What? (lib, no man)') elif not os.path.exists(useful.relpath('.' + config.LIB_MAN_DIR, self.man)): # man2 = pif.dbh.fetch_alias(self.man) # if not man2: useful.warn('bad destination') # else: # useful.file_mover(from_path, os.path.join('.' + config.LIB_MAN_DIR, man2['ref_id'].lower(), fn), mv=self.mv, ov=self.ov) else: to_dir = useful.relpath('.' + config.LIB_MAN_DIR, self.man) to_name = self.nname elif self.mvbin: if not os.path.exists(os.path.join('lib', self.cat)): useful.warn('bad destination') else: to_dir = os.path.join('lib', self.cat) to_name = self.nname elif self.selcat: if not (self.man or self.nname) or not self.dest: useful.warn('What? (selcat, no name or dest)') else: ddir = self.dest dnam = self.man if self.man else self.nname if self.pref: dnam = self.pref + '_' + dnam if self.ptype == 't': ddir = '.' + config.IMG_DIR_ADD if self.suff: dnam += '-' + self.suff if dnam: to_name = dnam.lower() + '.jpg' to_dir = ddir log_action = True elif self.select: inc = self.inc if not self.man: #self.man = tdir[tdir.rfind('/') + 1:] useful.warn('Huh? (select, no man)') else: ddir = '.' + config.IMG_DIR_MAN dnam = self.man if self.var: ddir = '.' + config.IMG_DIR_VAR dnam = dnam + '-' + self.var if self.pref: dnam = self.pref + '_' + dnam elif self.pref: if self.pref != 'n': dnam = self.pref + '_' + dnam if self.ptype == 't': ddir = '.' + config.IMG_DIR_ADD if self.suff: dnam += '-' + self.suff self.inc = True else: useful.warn("What? (select, no var or pref)") dnam = '' if dnam: to_name = dnam.lower() + '.jpg' to_dir = ddir log_action = True else: ret['act'] = False if to_dir: cred = pif.form.get_str('credit') if cred: photog = pif.dbh.fetch_photographer(cred) if not photog or not photog.flags & config.FLAG_PHOTOGRAPHER_PRIVATE: cred = '' useful.file_mover(from_path, os.path.join(to_dir, to_name), mv=self.mv, ov=self.ov, inc=self.inc) ret['fn'] = to_name ret['dir'] = to_dir if log_action and self.tumblr: title = pif.form.get_str('title', to_name) url = pif.secure_prod + os.path.join(to_dir, to_name) link = pif.secure_prod + self.link title = to_name if cred: title += ' credited to ' + photog.name pif.render.message('Post to Tumblr: ', tumblr.tumblr(pif).create_photo(caption=title, source=url, link=link)) pif.render.message('Credit added: ', pif.dbh.write_photo_credit(cred, to_dir, to_name)) return ret