def install_cover(press, request): """ Installs the default cover for the press (stored in Files/press/cover.png) :param press: the press object :param request: the current request or None :return: None """ if request: owner = request.user if request.user is not None and not request.user.is_anonymous else core_models.Account( id=1) else: owner = core_models.Account(id=1) thumbnail_file = core_models.File(mime_type="image/png", original_filename="cover.png", uuid_filename="cover.png", label="Press logo", description="Logo for the press", owner=owner) core_models.File.add_root(instance=thumbnail_file) press.thumbnail_image = thumbnail_file press.save()
def install_cover(journal, request): """ Installs the default cover for the journal (stored in Files/journal/<id>/cover.png) :param journal: the journal object :param request: the current request or None :return: None """ owner = request.user if request.user is not None else core_models.Account( id=1) thumbnail_file = core_models.File(mime_type="image/png", original_filename="cover.png", uuid_filename="cover.png", label="Journal logo", description="Logo for the journal", owner=owner) thumbnail_file.save() journal.thumbnail_image = thumbnail_file journal.save()
def import_accounts(create_users=True): with open('import_scripts/accounts.csv', newline='', encoding='utf-8', errors='ignore') as csvfile: reader = csv.reader(csvfile, delimiter='\t') for index, row in enumerate(reader): if not row[0] == '': original_id = int(row[0]) name = row[2] if row[4] == '': active = True else: active = False a = models.Account(name=name, original_id=original_id, active=active) a.save() comment = row[7] if not row[3] == '': rate = int(row[3]) if row[5]: start_date = datetime.datetime.strptime( row[5], '%d.%m.%y' ) # must begin at first day of the month! if start_date.day == 1: orig_start_date = "" else: orig_start_date = "Urspr. Eintrittsdatum: " + start_date.strftime( '%d.%m.%y; ') if start_date.month == 12: start_date = start_date.replace( day=1, month=1, year=start_date.year + 1) else: start_date = start_date.replace( day=1, month=start_date.month + 1) else: start_date = None orig_start_date = "" if row[6]: end_date = datetime.datetime.strptime( row[6], '%d.%m.%y' ) # must end at last day of the month, unless the date is on the 1st, then on the last day of the previous month orig_end_date = end_date if end_date.day == 1: end_date.replace(month=end_date.month - 1) end_date = last_day_of_month(end_date) if orig_end_date == end_date: orig_end_date = "" else: orig_end_date = "Urspr. Austrittsdatum: " + orig_end_date.strftime( '%d.%m.%y; ') else: end_date = None orig_end_date = "" ap = models.MembershipFee(account=a, start=start_date, end=end_date, rate=rate, comment=orig_start_date + orig_end_date + comment) ap.save() elif not row[5] == '': a.comment = "Eintritt am " + str( row[5]) + ", nicht zahlend; " + comment if create_users == True: if original_id == 1 or original_id == 52: # specifically for our database with Spontankäufer and Spendenkonto u = models.VirtualUser(name=name, active=active, comment=comment) u.save() else: u = models.Person(name=name, active=active, comment=comment) u.save() n = re.search( '(.+ ?.+) (.+)', name ) # improve regex code: if there is only one word, group 2 shall be empty (first name only) if n: u.first_name = n.group(1) u.last_name = n.group(2) u.accounts.add(a) u.save() a.users.add(u) a.save()