Skip to content

Commit

Permalink
Merge branch 'main' of github.com:sepid-org/Manage-Content-Service in…
Browse files Browse the repository at this point in the history
…to email-service
  • Loading branch information
AmooHashem committed Jun 16, 2024
2 parents 308f336 + f1e16a7 commit d5430d8
Show file tree
Hide file tree
Showing 74 changed files with 775 additions and 745 deletions.
35 changes: 22 additions & 13 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
# pull official base image
# Pull official base image
FROM python:3.11

# set work directory
# Set work directory
WORKDIR /usr/src/app

# Upgrade pip
RUN pip install --upgrade pip

# copy requirements
# Copy requirements file
COPY requirements.txt /usr/src/requirements.txt

# Install dependencies
RUN pip install -r /usr/src/requirements.txt

# copy entrypoint-prod.sh
# Copy entrypoint script
COPY ./entrypoint.prod.sh /usr/src/app/entrypoint.prod.sh

# copy project
# Copy project files
COPY . /usr/src/app/

RUN adduser kamva
# Create a non-root user and set permissions
RUN adduser --disabled-password --gecos "" sepid && \
chown -R sepid:sepid /usr/src/app

RUN mkdir -p /usr/src/app/logging && chown -R kamva /usr/src/app/logging \
&& mkdir -p /usr/src/app/staticfiles && chown -R kamva /usr/src/app/staticfiles \
&& mkdir -p /usr/src/app/media && chown -R kamva /usr/src/app/media
# Create necessary directories and set permissions
RUN mkdir -p /usr/src/app/logging /usr/src/app/staticfiles /usr/src/app/media && \
chown -R sepid:sepid /usr/src/app/logging /usr/src/app/staticfiles /usr/src/app/media

RUN chown -R kamva /usr/src/app/
# Make the entrypoint script executable
RUN chmod +x /usr/src/app/entrypoint.prod.sh

USER kamva
# Switch to non-root user
USER sepid

# run entrypoint.prod.sh
ENTRYPOINT ["/usr/src/app/entrypoint.prod.sh"]
# Set entrypoint
ENTRYPOINT ["/usr/src/app/entrypoint.prod.sh"]

# Expose port 8000
EXPOSE 8000
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Instalation

- `git clone git@github.com:Kamva-Academy/Kamva-Backend.git`
- `git clone git@github.com:sepid-org/Manage-Content-Service.git`
- `virtualenv venv`
- `source venv/bin/activate`
- `pip install -r requirements.txt`
Expand All @@ -14,7 +14,7 @@ To see apis check http://127.0.0.1:8000/api after running the project locally

## Deployment

After being logged in to server and Kamva-Backend folder, run:
After being logged in to server and Manage-Content-Service folder, run:
- `git pull`
- `docker-compose up -d --build`
- `docker-compose restart nginx`
Expand All @@ -25,7 +25,7 @@ In case you need to get shell, do:

## Contribution

1. Select an issue from [here](https://github.com/Kamva-Academy/Kamva-Backend/issues) that you want to work on.
1. Select an issue from [here](https://github.com/sepid-org/Manage-Content-Service/issues) that you want to work on.
2. Create a new branch from `master` and fix selected issue on new branch.
* creating new branch from `master`: `git checkout -b <new-branch-name> master`
3. After fixing selected issue, create a pull request (PR) to `master` and waits until reviewr review your code.
Expand Down
32 changes: 23 additions & 9 deletions apps/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
from django.contrib import admin, messages
from django.contrib.contenttypes.models import ContentType
from django.http import HttpResponseRedirect
from .models import Purchase, DiscountCode, User, VerificationCode, \
from .models import Purchase, DiscountCode, User, UserWebsite, VerificationCode, \
University, EducationalInstitute, School, SchoolStudentship, AcademicStudentship, Merchandise, Voucher

logger = logging.getLogger(__name__)


@admin.register(UserWebsite)
class UserWebsiteAdmin(admin.ModelAdmin):
model = UserWebsite
list_display = ['user', 'website']
list_filter = ['website']


class CustomUserAdmin(admin.ModelAdmin):
def verify_school_documents(self, request, queryset):
# documents = queryset.exclude(
Expand All @@ -18,16 +25,19 @@ def verify_school_documents(self, request, queryset):

documents = queryset.values_list('school_studentship', flat=True)

updated = SchoolStudentship.objects.filter(pk__in=documents).update(is_document_verified=True)
self.message_user(request, f'{updated} document verified.', messages.SUCCESS)
updated = SchoolStudentship.objects.filter(
pk__in=documents).update(is_document_verified=True)
self.message_user(
request, f'{updated} document verified.', messages.SUCCESS)

def school(self, obj):
return obj.school_studentship.school

model = User
list_display = ['id', 'username', 'phone_number', 'national_code', 'first_name', 'last_name', 'gender', 'province',
'city', 'school']
search_fields = ['id', 'username', 'phone_number', 'national_code', 'first_name', 'last_name']
search_fields = ['id', 'username', 'phone_number',
'national_code', 'first_name', 'last_name']
actions = [verify_school_documents]
ordering = ['-date_joined']

Expand All @@ -48,10 +58,12 @@ def merge_schools(self, request, queryset):
studentship.save()
school.delete()

self.message_user(request, f'{schools} schools merged.', messages.SUCCESS)
self.message_user(
request, f'{schools} schools merged.', messages.SUCCESS)

model = School
list_display = ['id', 'name', 'province', 'city', 'school_type', 'postal_code', 'address']
list_display = ['id', 'name', 'province', 'city',
'school_type', 'postal_code', 'address']
actions = [merge_schools]
ordering = ['id']

Expand All @@ -65,13 +77,15 @@ def export_selected_objects(model_admin, request, queryset):

class CustomPurchaseAdmin(admin.ModelAdmin):
model = Purchase
list_display = ['id', 'ref_id', 'amount', 'status', 'created_at', 'user', 'merchandise']
list_display = ['id', 'ref_id', 'amount',
'status', 'created_at', 'user', 'merchandise']
search_fields = ['user__username']


class UniversityCustomAdmin(admin.ModelAdmin):
model = University
list_display = ['id', 'name', 'province', 'city', 'school_type', 'postal_code', 'address']
list_display = ['id', 'name', 'province', 'city',
'school_type', 'postal_code', 'address']
search_fields = ['name', 'city']


Expand All @@ -86,4 +100,4 @@ class UniversityCustomAdmin(admin.ModelAdmin):
admin.site.register(AcademicStudentship)
admin.site.register(Merchandise)
# admin.site.register(University)
admin.site.register(Voucher)
admin.site.register(Voucher)
20 changes: 20 additions & 0 deletions apps/accounts/management/commands/create_user_websites.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.core.management import BaseCommand

from apps.accounts.models import User, UserWebsite
from apps.fsm.models import RegistrationReceipt


class Command(BaseCommand):

def handle(self, *args, **options):
for registration_receipt in RegistrationReceipt.objects.all():
website = registration_receipt.answer_sheet_of.program.website
user = registration_receipt.user
try:
UserWebsite.objects.create(
user=user,
website=website,
password=user.password,
)
except:
pass
82 changes: 0 additions & 82 deletions apps/accounts/management/commands/create_users_from_team.py

This file was deleted.

26 changes: 0 additions & 26 deletions apps/accounts/management/commands/fix_player_workshop_history.py

This file was deleted.

40 changes: 0 additions & 40 deletions apps/accounts/management/commands/fix_scores.py

This file was deleted.

39 changes: 0 additions & 39 deletions apps/accounts/management/commands/fix_users.py

This file was deleted.

Loading

0 comments on commit d5430d8

Please sign in to comment.